OpenApi 生成器不允许内容中有多个架构

如何解决OpenApi 生成器不允许内容中有多个架构

我有一个这样的 OpenAPI 合同:

openapi: 3.0.1
info:
  title: Internal API
  version: ''
tags:
  - name: Calendar
    description: Api for Calendar resource
paths:
  '/api/v1/appointments/{id}':
    get:
      tags:
        - Calendar
      summary: Get the given appointment
      description: Get the given appointment
      operationId: findById
      parameters:
        - name: id
          in: path
          description: The appointment Id
          required: true
          schema:
            type: integer
            format: int64
      responses:
        '200':
          description: Successful operation
          content:
            application/vnd.widget+json:
              schema:
                $ref: '#/components/schemas/AppointmentWidgetDto'
            application/json:
              schema:
                $ref: '#/components/schemas/Appointment'
      
components:
  schemas:
    AppointmentWidgetDto:
      required:
        - contactEmail
        - contactName
        - contactPhone
        - endDate
        - startDate
        - store
        - title
      type: object
      properties:
        store:
          $ref: '#/components/schemas/Store'
        title:
          maxLength: 255
          minLength: 0
          type: string
        description:
          maxLength: 1024
          minLength: 0
          type: string
        type:
          maxLength: 50
          minLength: 0
          type: string
        icon:
          maxLength: 50
          minLength: 0
          type: string
        startDate:
          type: string
          format: date-time
        endDate:
          type: string
          format: date-time
        contact:
          $ref: '#/components/schemas/Contact'
        contactName:
          type: string
        contactEmail:
          type: string
        contactPhone:
          type: string
    AuditUser:
      type: object
      properties:
        sid:
          type: string
        fullName:
          type: string
    Contact:
      required:
        - billingCountry
        - personType
        - preset
        - publicAdministration
        - shippingCountry
        - status
        - type
      type: object
      properties:
        id:
          type: integer
          format: int64
        sid:
          type: string
        createdBy:
          $ref: '#/components/schemas/AuditUser'
        createdDate:
          type: string
          format: date-time
        lastModifiedDate:
          type: string
          format: date-time
        lastModifiedBy:
          $ref: '#/components/schemas/AuditUser'
        version:
          type: integer
          format: int64
        userInputTime:
          type: integer
          format: int64
        type:
          type: string
          enum:
            - CUSTOMER
            - SUPPLIER
            - CUSTOMER_SUPPLIER
            - SUBCONTRACTOR
        personType:
          type: string
          enum:
            - NATURAL_PERSON
            - LEGAL_PERSON
        extCode:
          maxLength: 50
          minLength: 0
          type: string
        lotteryCode:
          maxLength: 8
          minLength: 0
          type: string
        firstName:
          type: string
        lastName:
          type: string
        companyName:
          type: string
        fullName:
          type: string
          readOnly: true
        gender:
          type: string
          enum:
            - MALE
            - FEMALE
            - OTHER
        birthDate:
          type: string
          format: date
        birthCity:
          type: string
        job:
          maxLength: 100
          minLength: 0
          type: string
        billingAddress:
          type: string
        billingZipCode:
          type: string
        billingCity:
          type: string
        billingDistrict:
          type: string
        billingCountry:
          maxLength: 2
          minLength: 2
          type: string
        shippingAddress:
          type: string
        shippingZipCode:
          type: string
        shippingCity:
          type: string
        shippingDistrict:
          type: string
        shippingCountry:
          maxLength: 2
          minLength: 2
          type: string
        taxCode:
          type: string
        vatNumber:
          type: string
        landlinePhone:
          type: string
        mobilePhone:
          type: string
        fax:
          type: string
        email:
          type: string
        certifiedEmail:
          type: string
        workingDistance:
          type: string
          enum:
            - FAR_NEAR
            - INTERMEDIATE_NEAR
            - NEAR
            - FAR_INTERMEDIATE
        bankName:
          type: string
        iban:
          type: string
        swift:
          type: string
        publicAdministration:
          type: boolean
        sdiAccountId:
          type: string
        store:
          $ref: '#/components/schemas/Store'
        preset:
          type: boolean
        avatar:
          type: boolean
        status:
          type: string
          enum:
            - ACTIVE
            - DECEASED
        completenessScore:
          type: number
          readOnly: true
        tags:
          type: string
        age:
          type: integer
          format: int32
    Store:
      required:
        - address
        - city
        - code
        - country
        - district
        - name
        - whatsAppEnabled
        - zipCode
      type: object
      properties:
        id:
          type: integer
          format: int64
        sid:
          type: string
        createdBy:
          $ref: '#/components/schemas/AuditUser'
        createdDate:
          type: string
          format: date-time
        lastModifiedDate:
          type: string
          format: date-time
        lastModifiedBy:
          $ref: '#/components/schemas/AuditUser'
        version:
          type: integer
          format: int64
        userInputTime:
          type: integer
          format: int64
        name:
          type: string
        code:
          type: string
        extCode:
          maxLength: 50
          minLength: 0
          type: string
        address:
          type: string
        zipCode:
          type: string
        city:
          type: string
        district:
          type: string
        country:
          maxLength: 2
          minLength: 2
          type: string
        landlinePhone:
          type: string
        mobilePhone:
          type: string
        whatsAppEnabled:
          type: boolean
        fax:
          type: string
        email:
          type: string
        certifiedEmail:
          type: string
        openingHours:
          maxLength: 1024
          minLength: 0
          type: string
        contactMinScore:
          maximum: 10
          minimum: 0
          type: number
    Agent:
      required:
        - country
        - email
        - firstName
        - gender
        - language
        - lastName
        - user
        - verified
      type: object
      properties:
        id:
          type: integer
          format: int64
        sid:
          type: string
        createdBy:
          $ref: '#/components/schemas/AuditUser'
        createdDate:
          type: string
          format: date-time
        lastModifiedDate:
          type: string
          format: date-time
        lastModifiedBy:
          $ref: '#/components/schemas/AuditUser'
        version:
          type: integer
          format: int64
        userInputTime:
          type: integer
          format: int64
        user:
          $ref: '#/components/schemas/User'
        firstName:
          type: string
        lastName:
          type: string
        gender:
          type: string
          enum:
            - MALE
            - FEMALE
            - OTHER
        color:
          maxLength: 30
          minLength: 0
          type: string
        employeeId:
          type: string
        address:
          type: string
        zipCode:
          type: string
        city:
          type: string
        district:
          type: string
        country:
          maxLength: 2
          minLength: 2
          type: string
        birthDate:
          type: string
          format: date
        taxCode:
          type: string
        vatNumber:
          type: string
        landlinePhone:
          type: string
        mobilePhone:
          type: string
        email:
          type: string
        verified:
          type: boolean
          readOnly: true
        language:
          maxLength: 2
          minLength: 2
          type: string
        iban:
          type: string
        swift:
          type: string
        stores:
          uniqueItems: true
          type: array
          items:
            $ref: '#/components/schemas/Store'
        avatar:
          type: boolean
          readOnly: true
        tourCompleted:
          type: boolean
          readOnly: true
        enabled:
          type: boolean
          writeOnly: true
        password:
          type: string
          writeOnly: true
        lastPasswordUpdate:
          type: string
          format: date-time
        username:
          type: string
        roles:
          uniqueItems: true
          type: array
          items:
            type: string
            enum:
              - ROLE_ADMIN
        userSid:
          type: string
    Appointment:
      required:
        - allDay
        - endDate
        - startDate
        - status
        - store
        - title
      type: object
      properties:
        id:
          type: integer
          format: int64
        sid:
          type: string
        createdBy:
          $ref: '#/components/schemas/AuditUser'
        createdDate:
          type: string
          format: date-time
        lastModifiedDate:
          type: string
          format: date-time
        lastModifiedBy:
          $ref: '#/components/schemas/AuditUser'
        version:
          type: integer
          format: int64
        userInputTime:
          type: integer
          format: int64
        store:
          $ref: '#/components/schemas/Store'
        title:
          maxLength: 255
          minLength: 0
          type: string
        description:
          maxLength: 1024
          minLength: 0
          type: string
        color:
          maxLength: 30
          minLength: 0
          type: string
        type:
          maxLength: 50
          minLength: 0
          type: string
        icon:
          maxLength: 50
          minLength: 0
          type: string
        location:
          maxLength: 255
          minLength: 0
          type: string
        startDate:
          type: string
          format: date-time
        endDate:
          type: string
          format: date-time
        allDay:
          type: boolean
        contact:
          $ref: '#/components/schemas/Contact'
        contactName:
          type: string
        contactEmail:
          type: string
        contactPhone:
          type: string
        agent:
          $ref: '#/components/schemas/Agent'
        agentName:
          type: string
        status:
          type: string
          readOnly: true
          enum:
            - TO_APPROVE
            - VALID
            - CANCELED
            - DECLINED
    GrantedAuthority:
      type: object
      properties:
        authority:
          type: string
    User:
      required:
        - enabled
        - fullName
        - roles
        - username
      type: object
      properties:
        id:
          type: integer
          format: int64
        sid:
          type: string
        createdBy:
          $ref: '#/components/schemas/AuditUser'
        createdDate:
          type: string
          format: date-time
        lastModifiedDate:
          type: string
          format: date-time
        lastModifiedBy:
          $ref: '#/components/schemas/AuditUser'
        version:
          type: integer
          format: int64
        userInputTime:
          type: integer
          format: int64
        fullName:
          type: string
        username:
          maxLength: 255
          minLength: 3
          type: string
        enabled:
          type: boolean
          readOnly: true
        roles:
          maxItems: 2147483647
          minItems: 1
          uniqueItems: true
          type: array
          items:
            type: string
            enum:
              - ROLE_ADMIN
        accountNonExpired:
          type: boolean
        credentialsNonExpired:
          type: boolean
        authorities:
          type: array
          items:
            $ref: '#/components/schemas/GrantedAuthority'
        accountNonLocked:
          type: boolean

我希望我的端点 /api/v1/appointments/{id} 返回我的资源约会的 2 种不同表示:完整资源和轻量资源(数据较少)。 我认为使用内容的架构是正确的做法,这样客户就可以轻松决定它想要什么。

我尝试使用 Swagger editorOpenApi generator 从这个合约生成一些客户端,但我看到这些警告:

[WARNING] Multiple schemas found in the OAS 'content' section,returning only the first one (application/vnd.widget+json)

我的客户端,正如该消息所预期的那样,只有一种方法只返回资源的 1 种表示。

我发现了这个错误 https://github.com/OpenAPITools/openapi-generator/issues/144,但同时我认为这是 HTTP/REST 的一个非常基本的概念,我有点惊讶它不起作用。 事实上,我在质疑自己做错了什么。有没有办法描述单个端点返回相同资源(OpenApi 合同)的不同表示,生成客户端,同时使用两种方法来获取已经提到的资源的表示?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)> insert overwrite table dwd_trade_cart_add_inc > select data.id, > data.user_id, > data.course_id, > date_format(
错误1 hive (edu)> insert into huanhuan values(1,'haoge'); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive> show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 <configuration> <property> <name>yarn.nodemanager.res