Swagger Codegen-名称响应意外的缺少属性

时间:2018-10-01 22:19:53

标签: node.js swagger-2.0 swagger-codegen

我正在尝试使用codegen生成node.js-server存根。我已经下载了swagger-codegen-cli-2.3.1.jar文件,并尝试使用cli命令生成代码。 但是,它失败并显示以下错误消息:

[main] ERROR io.swagger.codegen.DefaultCodegen - unexpected missing property for name response
[main] WARN io.swagger.codegen.DefaultCodegen - skipping invalid array property {
  "baseName" : "response",
  "getter" : "getResponse",
   ....
  "isReadOnly" : false,
  "vendorExtensions" : { },
  "hasValidation" : false,
  "isXmlAttribute" : false,
  "isXmlWrapped" : false
}
[main] ERROR io.swagger.codegen.DefaultCodegen - unexpected missing property for name response
Exception in thread "main" java.lang.RuntimeException: Could not process operation:
  Tag: Tag {
        name: messages
        description: Messages for blue instance
        externalDocs: null
        extensions:{}}
  Operation: listMessages
  Resource: get /instances/{instanceId}/messages
  Definitions: {message-common=io.swagger.models.ModelImpl@e68ed4e0, Error Response=io.swagger.models.ModelImpl@7bcf5e6c}
  Exception: null
        at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:932)
        at io.swagger.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:808)
        at io.swagger.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:431)
        at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:746)
        at io.swagger.codegen.cmd.Generate.run(Generate.java:285)
        at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Caused by: java.lang.NullPointerException
        ... 5 more

这是我昂首阔步的定义文件的摘录。 我确实添加/删除了x-swagger-router-controller属性,但这也没有帮助。

swagger: '2.0'
info:
  title: Messages API
  version: '1.0'
  description: |-
    Call used to get messages
host: 'localhost:8080'
paths:
  '/instances/{instanceId}/messages':
    get:
      summary: Get all messages
      operationId: listMessages
      responses:
        '200':
          description: 'Success Response'
          schema:
            type: array
            items:
              title: Message Output
              description: The properties that are included
              allOf:
                - type: object
                  properties:
                    id:
                      type: string
                - title: Message Common
                  description: The properties that are shared
                  type: object
                  properties:
                    message:
                      type: string
                      description: Operation the system must do
                    details:
                      type: string
                      description: 'Textual data'
                  required:
                    - message
                    - details
        '401':
          description: Unauthorized requests
          schema:
            type: object
            title:  Error Response
            description: Standard  error message.
            properties:
              errors:
                type: array
                items:
                  type: object
                  properties:
                    code:
                      type: string
                      description: Human readable category
                    message:
                      type: string
                      description: Detailed error message
                  required:
                    - code
                    - message
            required:
              - errors
        '500':
          description: Response for other issues
          schema:
            type: object
            title:  Error Response
            description: Standard  error message.
            properties:
              errors:
                type: array
                items:
                  type: object
                  properties:
                    code:
                      type: string
                      description: Human readable category
                    message:
                      type: string
                      description: Detailed error message
                  required:
                    - code
                    - message
            required:
              - errors
      description: 'Call used to get messages, notices, and/or instructions from E&E system for the product to take. '
      parameters:
        - name: Digest
          in: header
          type: string
          description: The digest for the body being passed
      tags:
        - messages
    parameters:
      - name: instanceId
        in: path
        type: string
        required: true
        description: The specific instance for which the message is relevant
basePath: /v1
schemes:
  - http
consumes:
  - application/json
produces:
  - application/json
tags:
  - name: messages
    description: Messages for instance

请帮助。不确定我在这里缺少什么。

1 个答案:

答案 0 :(得分:0)

该错误似乎是由responses中的内联模型引起的。虽然这完全正确,但可能是Swagger Codegen不支持此功能。您可以在Swagger Codegen repository中打开问题。

尝试将模型定义放在全局definitions部分中,以便您的responses部分如下所示:

      responses:
        '200':
          description: 'Success Response'
          schema:
            type: array
            items:
              $ref: '#/definitions/Message'
        '401':
          description: Unauthorized requests
          schema:
            $ref: '#/definitions/Error'
        '500':
          description: Response for other issues
          schema:
            $ref: '#/definitions/Error'