【问题标题】:Swagger UI 3.x setting custom content type for body parameterSwagger UI 3.x 为 body 参数设置自定义内容类型
【发布时间】:2023-03-08 02:42:01
【问题描述】:

如何使用 Swagger (Open API) 2.0 YAML 定义文件在 Swagger UI 3.x 中为正文参数设置 application/json 以外的内容类型?

我的 YAML 文件如下,consumes 元素设置为application/json+fhirapplication/xml+fhir

swagger: '2.0'
info:
  title: Test
  version: '1.0'
host: 'server.com'
basePath: /fhir
schemes:
  - http
paths:
  /Patient/$getrecordsection:
    post:
      tags:
        - Get record section
      summary: Retrieve a care record section
      consumes:
        - application/json+fhir
        - application/xml+fhir
      produces:
        - application/json+fhir
        - application/xml+fhir
      parameters:
        - in: body
          name: body
          description: ''
          required: true
          schema:
            $ref: '#/definitions/GetRecordSection'
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
definitions:
  GetRecordSection:
    type: object
    properties:
      resourceType:
        type: string
        default: "Parameters"
      parameter:
        type: string
    example:
      resourceType: "Parameters"
      parameter: 
        - name: "patientIdentifier"
          valueIdentifier: 
            system: "http://fhir.provider.net/Id/patient-identifier"
            value: "9999999999"
        - name: "recordSection"
          valueCodeableConcept: 
            coding:
              - system: "http://fhir.provider.net/ValueSet/record-section"
                code: "ALL"
    xml:
      name: Parameters

但是,Swagger UI 仅将application/json 显示为正文参数内容类型:

我正在使用当前最新的 Swagger UI 版本 - 3.11.0。

这是 Swagger UI 的问题,而不是 Swagger 编辑器的问题(尽管我知道两者共享大量组件),因此根本原因可能是相同的。

【问题讨论】:

  • 这是最新版本的 Swagger 编辑器中引入的一个错误。请参阅链接的问答。 ^^
  • 这是 Swagger UI 而非 Swagger 编辑器的问题,尽管我知道两者共享大量组件,因此根本原因可能是相同的。

标签: swagger swagger-ui swagger-2.0 hl7-fhir


【解决方案1】:

这是 3.11.0 版本的 Swagger UI 中的一个错误,使用 Swagger/Open API 2.0:

https://github.com/swagger-api/swagger-ui/issues/4257

【讨论】:

  • 已在 Swagger UI 3.12.0(2018 年 3 月 4 日发布)中修复。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-24
  • 2018-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-06
相关资源
最近更新 更多