2017-08-30 15 views
1

例えばボディ部分にあるもののようなものです。構造体1と構造体の間で選択できるようにすることができます。これは私の構造体と構造体です。セレクタのようなものがあるか、 POSTやPUTをすべての構造に適用できますか?もしかすると別の方法がありますか?リクエストボディ用差分ボディを作成し、操作中にどちらを選択することができますか?

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: [email protected] 
    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 
+0

私はoneOfについて聞いたことがありますが、それほど気にしませんでした.2.0はそれをサポートしていません – Dima

+0

代替として使用したいボディの例を追加できますか? – Helen

+0

答えをありがとう。私はそれを追加しました。 – Dima

答えて

1

代替スキーマはoneOfを使用して定義することができますが、それだけOpenAPIを3.0にしていないOpenAPIを/ SWAGGER 2.0でサポートされています。 OpenAPIを/闊歩2.0では

、ほとんどあなたが行うことができますが、任意のプロパティを可能にする自由形式のオブジェクトボディ使用である:OpenAPIを3.0に

- in: body 
    name: body 
    description: Add what do you wnat to add 
    required: true 
    schema: 
    type: object 

を、あなたはこのようなoneOfを使用することができます。

paths: 
    /something: 
    post: 
     requestBody: 
     required: true 
     content: 
      application/json: 
      schema: 
       oneOf: 
       - $ref: '#/components/schemas/Structure' 
       - $ref: '#/components/schemas/Structure1' 
     responses: 
     ... 

# "definitions" were replaced with "components.schemas" 
components: 
    schemas: 
    Structure: 
     ... 
    Structure1: 
     ... 
+1

はい、正確には私は2.0のようなものにしたいと思いましたが、それは不可能です.3.0を使い始めるでしょう。ありがとう – Dima

+0

私はそれをしましたが、動作しませんでした。あなたはそれを見てくださいできますか?そしてそれは間違いを与えません – Dima

関連する問題