当前位置: 首页 > 知识库问答 >
问题:

Swager 2.0参考规范

松新
2023-03-14

我在尝试格式化这个OpenApI(Swagger) Json文件时遇到了挑战。当我试图与https://editor.swagger.io/,确认时,我得到了错误。

$ref值必须是符合 RFC3986 的百分比编码 URI

当我将文件中架构的$ref属性从$ ref:' #/definitions/GetResponse[List[currency model]]'更改为$ ref:%/definitions/GetResponse[List[currency model]]'时

错误消失了,但随后请求和响应都没有显示正确的模型,而是显示字符串。请参阅下面的屏幕截图。第一张图像带有 #,第二张图像带有 %

swagger: '2.0'
info:
  version: v1
  title: API
  contact:
    name: DEMO
paths:
  /api/Currency/GetCurrencies:
    get:
      tags:
        - Currency
      summary: Get List of Currencies
      description: ''
      operationId: GetAllCurrencies
      consumes: []
      produces:
        - text/plain
        - application/json
        - text/json
      parameters: []
      responses:
        '200':
          description: Returns list of Currencies
          schema:
            $ref: '#/definitions/GetResponse[List[CurrencyModel]]'
        '400':
          description: If an error occur
          schema:
            $ref: '#/definitions/GetResponse[ProducesResponseStub]'
        '404':
          description: If the list of Currencies is null
          schema:
            $ref: '#/definitions/GetResponse[ProducesResponseStub]'
definitions:
  GetResponse[List[CurrencyModel]]:
    type: object
    properties:
      status:
        type: boolean
      data:
        uniqueItems: false
        type: array
        items:
          $ref: '#/definitions/CurrencyModel'
      message:
        type: string
  CurrencyModel:
    type: object
    properties:
      id:
        format: int32
        type: integer
      name:
        type: string
      code:
        type: string
      currencyUTF32Code:
        format: int32
        type: integer
      currencySymbol:
        type: string
        readOnly: true
securityDefinitions:
  Bearer:
    name: Authorization
    in: header
    type: apiKey
    description: Please insert JWT with Bearer into field
security:
  - Bearer: []

共有1个答案

弘和同
2023-03-14

有两个问题:

> < li>

您的API定义缺少在某些refs中使用的< code > GetResponse[produce response stub]和< code > GetResponse[produce response stub]模式。您需要添加缺少的模式,或者删除相应的$refs。

如果某些架构名称包含特殊字符,则必须在$ref路径中对它们进行 URL 编码。将 [ 替换为 [ ] 替换为 ],例如

# Incorrect
$ref: '#/definitions/GetResponse[List[CurrencyModel]]'

# Correct
$ref: '#/definitions/GetResponse%5BList%5BCurrencyModel%5D%5D'

或者更好的是,不要在模式名称中使用特殊字符。

 类似资料:
  • fsid 描述: 文件系统 ID ,每集群一个。 类型: UUID 是否必需: No. 默认值: 无。通常由部署工具生成。 admin socket 描述: 在某个守护进程上执行管理命令的套接字,不管 Ceph 监视器团体是否已建立。 类型: String 是否必需: No 默认值: /var/run/ceph/$cluster-$name.asok pid file 描述: mon 、 osd

  • 本文内容用于详细说明Dism++规则的组成,不感兴趣的同学可以无视本文内容。 清理规则结构参考 很多朋友可能还是有疑问,Dism++的规则形式到底是怎么样的。本文将详细说明清理规则完整语法。清理规则有V1版跟V2版,这是由于历史原因导致的。Dism++同时支持二个版本,可以根据自己的需要选择。 清理规则结构体V1 V1版结构体会简洁很多 <!--V1版结构体--> <element name="I

  • Modules 参考了以下开源模块: adm-zip clean-css colors fs-extra glob howdo open uglify-js ydr-utils seajs fis webpack posthtml Articles 感谢以下文章: FED社区:coolie 介绍专辑 FED社区:跟我学 coolie 专辑 知乎:大公司里怎样开发和部署前端代码? InfoQ:前端工

  • http://openstack.redhat.com/Networking_in_too_much_detail http://web.archive.org/web/20150215214007/http://masimum.inf.um.es/fjrm/2013/12/26/the-journey-of-a-packet-within-an-openstack-cloud http://pa

  • ECMAScript 6 入门。 ESlint是一个javascript代码审查框架。 Testem A test runner that makes Javascript unit testing fun. 创建一个testem的测试目录,然后安装testem: $ cd /opt && mkdir testem && cd /opt/testem $ npm install testem -g

  • Hyperledger Composer参考资料包含许多主题,包括npm模块的参考信息、CLI命令、建模语言、API、连接配置文件和常用术语表。 Historian(历史记录) Hyperledger Composer Historian提供了一个库,其中包含历史交易的信息 Hyperledger Composer npm模块 Hyperledger Composer包含许多npm模块,提供使用H