【问题标题】:Swagger schema reference in another file另一个文件中的 Swagger 架构引用
【发布时间】:2021-06-01 14:30:05
【问题描述】:

我在设计我的 swagger API 服务模型并强调文本时正在处理巨大的 yaml 架构我想将 model 部分保存在另一个文件中,以便具有更大的灵活性和易读性。

按照this 文档,我使用了这部分代码:

components:
  schemas:
    Request:
      title: Request
      type: object
      properties:
        technicalData:
          $ref: '../../schemas/foo.yaml/components/schemas/TechnicalData'

在我的foo.yaml 文件中,我有这样的东西:

components:
  schemas:
    TechnicalData:
      type: object
      properties:
        application:
          type: string
        applicationCode:
          type: string
        userId:
          type: string

它在本地主机上工作,但我在企业部署服务器上运行我的文件时遇到以下问题:

错误 解析器错误 components.schemas.Request.properties.technicalData.$ref 不能 解决参考,因为:不可接受

我已成功通过本地浏览器浏览我的文件。

上网查了一下,我发现了一些与我的主题相关的问题,但不幸的是不是很有用: https://github.com/swagger-api/swagger-editor/issues/1561

https://github.com/RepreZen/KaiZen-OpenAPI-Editor/issues/438

【问题讨论】:

    标签: yaml swagger


    【解决方案1】:

    在文件名和/components/...之间添加#

    $ref: '../../schemas/foo.yaml#/components/schemas/TechnicalData'
                                 ^
    

    【讨论】:

    • 就是这么简单。我保持问题开放等待部署,以验证它在服务器上工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-24
    • 2013-03-15
    • 2017-06-27
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    相关资源
    最近更新 更多