swagger-codegen - 如何为生成的C#SDK方法提供正文?

时间:2017-02-14 15:04:20

标签: c# swagger swagger-codegen

我使用https://hub.docker.com/r/jimschubert/swagger-codegen-cli/中的(非官方)swagger-codegen-cli Docker容器,它在运行之前从主分支中提取swagger-codegen。我尝试从https://hub.docker.com/r/swaggerapi/swagger-codegen-cli/抓取最近记录的(官方)swagger-codegen-cli,但目前似乎无法使用。

与非官方cli一样,我从swagger文档生成了一个C#SDK,其中包含以下内容:

/api/customer/{zoneId}/files/cover/gallery: {
    get: {
        tags: [
            "FileUpload"
        ],
        summary: "Get all files in customer cover gallery",
        operationId: "FileUpload_GetCustomerCoverFiles",
        consumes: [ ],
        produces: [
            "application/json",
            "text/json"
        ],
        parameters: [
            {
                name: "zoneId",
                in: "path",
                description: "",
                required: true,
                type: "integer",
                format: "int32"
            }
        ],
        responses: {
            200: {
                description: "OK",
                schema: {
                    type: "array",
                    items: {
                        $ref: "#/definitions/FileUploadGalleryItemModel"
                    }
                }
            }
        }
    },
    post: {
        tags: [
            "FileUpload"
        ],
        summary: "Upload file to customer cover gallery",
        operationId: "FileUpload_CreateCustomerCoverGalleryItem",
        consumes: [
            "application/octet-stream"
        ],
        produces: [
            "application/json",
            "text/json"
        ],
        parameters: [
            {
                name: "zoneId",
                in: "path",
                description: "",
                required: true,
                type: "integer",
                format: "int32"
            },
            {
                name: "payload",
                in: "body",
                description: "",
                required: true,
                type: "byte[]",
                format: "binary"
            }
        ],
        responses: {
            200: {
                description: "OK",
                schema: {
                    type: "array",
                    items: {
                        $ref: "#/definitions/FileUploadGalleryItemModel"
                    }
                }
            }
        }
    }
},

&#39>有效负载&#39;在请求正文中提供,但是我没有看到任何方式为SDK中生成的方法提供正文,并带有以下签名:public List<FileUploadGalleryItemModel> FileUploadCreateCustomerCoverGalleryItem (int? zoneId)

关于我可能忽略或做错的任何建议?

1 个答案:

答案 0 :(得分:2)

您可以将payload记录为文件(表单参数),例如https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml#L269-L273,您将在自动生成的文档中找到示例代码(请查看自动生成的README.md作为起点)