0

On running java -jar swagger-codegen-cli.jar generate -i ../tech-bucket/membership-card/apis/mini.swagger -l nodejs-server against the swagger spec below, I see two errors/warnings:

[main] ERROR io.swagger.codegen.DefaultCodegen - unexpected missing property for name actual_things
[main] WARN io.swagger.codegen.DefaultCodegen - skipping invalid property {
  "type" : "array"
}
[main] ERROR io.swagger.codegen.DefaultCodegen - unexpected missing property for name actual_things
[main] WARN io.swagger.codegen.DefaultCodegen - skipping invalid property {
  "type" : "array"
}

I don't understand what's invalid about specifying type: array. How else do I express that the API returns an array of objects? That is, the API returns something that looks like:

{
    formatted_input: "Here is the formatted input",
    actual_things: [
        {id: "10", thing_value: "the value for number 10"},
        {id: "12", thing_value: "the value for number 12"}
    ]
}

The swagger spec in error is:

swagger: '2.0'

info:
  version: "1"
  title: title here
  description: description here

paths:
  /endpoint:
    get:
      description: an endpoint
      parameters:
        -
          name: someparam
          in: query
          description: param desc here
          required: true
          type: string
      responses:
        200:
          description: List of things
          schema:
            title: thing_list
            type: object
            properties:
              formatted_input:
                type: string
                description: The passed input
              actual_things:
                type: array
                items:
                  -
                    type: object
                    properties:
                      thing_value:
                        type: string
                        description: The thing
                      id:
                        type: string
                        description: an ID

1 Answer 1

2

The issue is that items is a magic keyword which defines that all items in this collection use the following schema. We do not need to actually make it a YAML array item. So, working swagger spec looks like:

swagger: '2.0'

info:
  version: "1"
  title: title here
  description: description here

paths:
  /endpoint:
    get:
      description: an endpoint
      parameters:
        -
          name: someparam
          in: query
          description: param desc here
          required: true
          type: string
      responses:
        200:
          description: List of things
          schema:
            title: thing_list
            type: object
            properties:
              formatted_input:
                type: string
                description: The passed input
              actual_things:
                type: array
                items:
                  type: object
                  properties:
                    thing_value:
                      type: string
                      description: The thing
                    id:
                      type: string
                      description: an ID
Sign up to request clarification or add additional context in comments.

1 Comment

diff for those who are having a hard time spotting the difference between the broken and working code: diffchecker.com/rHgYlLyk

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.