另一个文件中的 Swagger 模式引用

Swagger schema reference in another file

我在设计 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

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

Errors Resolver error at components.schemas.Request.properties.technicalData.$ref Could not resolve reference because of: Not Acceptable

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

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

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

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

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