19

Swagger API ドキュメント内には、apis 配列の横にある json 内にモデル オブジェクト エントリがありますが、それに関するドキュメントはありません。この「モデル」部分をどのように使用できますか?

{
   apiVersion: "0.2",
   swaggerVersion: "1.1",
   basePath: "http://petstore.swagger.wordnik.com/api",
   resourcePath: "/pet.{format}"

   ...

   apis: [...]
   models: {...}
}
4

1 に答える 1

18

モデルは、変数とプロパティを持つJavaのPOJOクラスに他なりません。モデルセクションでは、独自のカスタムクラスを定義し、それをデータ型として参照できます。

以下をご覧ください

     {
        "path": "/pet.{format}",
        "description": "Operations about pets",
        "operations": [
            {
                "httpMethod": "POST",
                "summary": "Add a new pet to the store",
                "responseClass": "void",
                "nickname": "addPet",
                "parameters": [
                    {
                        "description": "Pet object that needs to be added to the store",
                        "paramType": "body",
                        "required": true,
                        "allowMultiple": false,
                        "dataType": "Pet"
                    }
                ],
                "errorResponses": [
                    {
                        "code": 405,
                        "reason": "Invalid input"
                    }
                ]
            }

ここのパラメーターセクションには、dataTypePetであるパラメーターが1つあり、petは以下のようにモデルで定義されています。

{
"models": {
    "Pet": {
        "id": "Pet",
        "properties": {
            "id": {
                "type": "long"
            },
            "status": {
                "allowableValues": {
                    "valueType": "LIST",
                    "values": [
                        "available",
                        "pending",
                        "sold"
                    ]
                },
                "description": "pet status in the store",
                "type": "string"
            },
            "name": {
                "type": "string"
            },
            "photoUrls": {
                "items": {
                    "type": "string"
                },
                "type": "Array"
            }
        }
    }
}}

ネストされたモデルを持つことができます。詳細については、SwaggerPetStoreの例を参照してください。

つまり、モデルはクラスのようなものに他なりません。

于 2013-03-04T10:03:34.970 に答える