另一个文件中的 Swagger 架构引用

Xav*_* W. 3 yaml swagger

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

根据文档,我使用了这部分代码:

components:
  schemas:
    Request:
      title: Request
      type: object
      properties:
        technicalData:
          $ref: '../../schemas/foo.yaml/components/schemas/TechnicalData'
Run Code Online (Sandbox Code Playgroud)

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

components:
  schemas:
    TechnicalData:
      type: object
      properties:
        application:
          type: string
        applicationCode:
          type: string
        userId:
          type: string
Run Code Online (Sandbox Code Playgroud)

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

Components.schemas.Request.properties.technicalData.$ref 处的错误解析器错误无法解析引用,因为:不可接受

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

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

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

Hel*_*len 9

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

$ref: '../../schemas/foo.yaml#/components/schemas/TechnicalData'
                             ^
Run Code Online (Sandbox Code Playgroud)