2017-03-21 6 views
1

swagger-editorでapiのパラメータとしてカスタムオブジェクトを表現したいと思います。スワッガーエディタでapiのパラメータとしてカスタムオブジェクトを表現する方法

class Info 
{ 
    private String id; 
    private String name; 
    private String desc; 
} 

どのようにこれはYAML文書として闊歩エディタで表すことができます?パラメータとして情報モデルクラスが含まれている、我々は法の上に/postInfo /データ

@RequestMapping(value = "/postInfo/data", method = RequestMethod.POST) 
public Info requestProcessing(@RequestBody Info info) 
{ 
    // Implementation 
} 

をAPIを呼び出していると言うことができますか闊歩2.0で

答えて

2

、オブジェクト・スキーマは、グローバルdefinitionsセクションで定義することができる:スペックの他の部分から

definitions: 
    Info: 
    type: object 
    properties: 
     id: 
     type: string 
     name: 
     type: string 
     desc: 
     type: string 

、次いで$ref「ED。

オブジェクトに操作の入力が使用されている場合、操作では、そのオブジェクトのスキーマに対応するschemaの本体パラメーターを定義する必要があります。

paths: 
    /postInfo/data: 
    post: 
     consumes: 
     - application/json 
     parameters: 
     - in: body 
      name: body 
      required: true 
      schema: 
      $ref: '#/definitions/Info' 
     responses: 
     200: 
      description: OK 
関連する問題