我可以向 YAML Swagger 对象添加版本吗? [英] Can I add versions to YAML Swagger objects?

查看:80
本文介绍了我可以向 YAML Swagger 对象添加版本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 API 定义,并且我想将我的规范模型拆分为不同的文档并使用 JSON 指针$ref"来重用它们.我需要找到一种在 YAML 文件中添加版本的方法.例如:

I am creating a API definition, and a I wanto to split my canonical model to different documents and use the JSON pointer '$ref' to reuse them. I need to find a way to add version in the YAML files. For instance:

***pj.yaml***
 pJType:
  verison: 1.0
  type: object
  properties:
    cnpj:
      type: integer

***afastamento.yaml***
oswagger: '2.0'
info:
  version: '1.0'
  title: AfastamentoService
consumes:
  - application/json
produces:
  - application/json
paths:
  '/{nis}':
    get:
      parameters:
        - in: path
          name: nis
          type: integer
          required: true

      responses:
        '200':
          description: OK
          schema:
            $ref: '#/definitions/pesquisarResponse'
definitions:
  pesquisarResponse:
    type: object
    properties:
      listaAfastamento:
        $ref: '#/definitions/listaAfastamentoType'
  ...
  empregadorType:
    type: object
    properties:
      personalidadeJuridica:
        type: string
      pessoaJuridica:
        $ref: pJ.yaml#/pessoaJuridicaType
...

推荐答案

您可以使用扩展属性(以 x- 为前缀)向规范添加任意数据:

You can use the extension properties (prefixed with x-) to add arbitrary data to the spec:

# pj.yaml
pJType:
  x-version: 1.0

  type: object
  properties:
    cnpj:
      type: integer

这篇关于我可以向 YAML Swagger 对象添加版本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆