Swagger 是否可以创建不同的主体,并在操作过程中选择我想要的主体?

Swagger 是否可以创建不同的主体,并在操作过程中选择我想要的主体?,swagger,swagger-ui,swagger-2.0,swagger-editor,Swagger,Swagger Ui,Swagger 2.0,Swagger Editor,例如,在主体部分,我可以做一些事情,让我在结构1或枚举中的结构之间进行选择。这也是我的结构和结构1。我们是否有类似选择器的东西,或者每次我都应该为每个结构创建新的帖子或放置内容?是否有其他方法处理if?是否有if大摇大摆 openapi: 3.0.0 servers: - url: 'http://petstore.swagger.io/v2' x-origin: - url: 'http://petstore.swagger.io/v2/swagger.json' form

例如,在主体部分,我可以做一些事情,让我在结构1或枚举中的结构之间进行选择。这也是我的结构和结构1。我们是否有类似选择器的东西,或者每次我都应该为每个结构创建新的帖子或放置内容?是否有其他方法处理if?是否有if大摇大摆

  openapi: 3.0.0
servers:
  - url: 'http://petstore.swagger.io/v2'
x-origin:
  - url: 'http://petstore.swagger.io/v2/swagger.json'
    format: swagger
    version: '2.0'
    converter:
      url: 'https://github.com/mermade/swagger2openapi'
      version: 2.2.0
info:
  description: 'This is a sample server Petstore server.  You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).  For this sample, you can use the api key `special-key` to test the authorization filters.'
  version: 1.0.0
  title: Swagger Petstore
  termsOfService: 'http://swagger.io/terms/'
  contact:
    email: apiteam@swagger.io
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
  - name: pet
    description: Everything about your Pets
    externalDocs:
      description: Find out more
      url: 'http://swagger.io'
  - name: store
    description: Access to Petstore orders
  - name: user
    description: Operations about user
    externalDocs:
      description: Find out more about our store
      url: 'http://swagger.io'
paths:
  /something:
     post:
        requestBody:
         required: true
         content:
           application/json:
             schema:
               oneOf:
                 - $ref: '#/components/schemas/Dog'
                 - $ref: '#/components/schemas/Cat'
        responses:
          '200':
            description: Updated         
components:
  schemas:
    Dog:
      type: object
      properties:
        bark:
          type: boolean
        breed:
          type: string
          enum: [Dingo, Husky, Retriever, Shepherd]
    Cat:
      type: object
      properties:
        hunts:
          type: boolean
        age:
          type: integer

可以使用中的一个定义请求主体的备用模式,但它仅在OpenAPI 3.0中受支持,而在OpenAPI/Swagger 2.0中不受支持

在OpenAPI/Swagger 2.0中,您最多只能使用允许任意属性的自由形式对象体:

-in:body
姓名:body
描述:添加要添加的内容
必填项:true
模式:
类型:对象
在OpenAPI 3.0中,您可以像这样使用
oneOf

路径:
/一些东西:
职位:
请求主体:
必填项:true
内容:
应用程序/json:
模式:
其中一项:
-$ref:“#/components/schemas/Structure”
-$ref:“#/components/schemas/Structure1”
响应:
...
#“定义”已替换为“组件.架构”
组件:
模式:
结构:
...
结构1:
...

我听说过其中一个,但在swagger 2.0中不支持它。你能添加你想用作替代品的身体示例吗?谢谢你的回答。我添加了它。结构内部是什么?答案取决于结构是否完全不同或有一些共同的属性。我编辑了它。你能看一下吗?是的,确切地说,我想在2.0中使用类似的东西,但这是不可能的,然后我将开始使用3.0。谢谢,我做到了,但它不起作用。当我写所有的东西时,它是工作的,但是有一个没有,你能看一下吗?它没有给出任何错误