Skip to content

additionalProperties with Boolean value causes NPEs #1318

@ches

Description

@ches

I'll come back and provide a more minimal reproduction case, just wanted to file this while it's fresh (it seems fairly trivial to reproduce, and a quick grep shows a lot of code that seems to assume additionalProperties will be a map).

additionalProperties in JSON Schema can be an object or a Boolean. When I use a Boolean value, codegen blows up with an NPE (using rev 253c46a at time of this trace):

$ make gen
Running Swagger code generation
java -jar /Volumes/onner/onner-sdk-ios/vendor/swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
                --input-spec /Volumes/onner/onner-sdk-ios/../API/docs/swagger.json \
                --lang objc \
                --config /Volumes/onner/onner-sdk-ios/config.json \
                --output /Volumes/onner/onner-sdk-ios
reading from /Volumes/onner/onner-sdk-ios/../API/docs/swagger.json
[main] WARN io.swagger.util.PropertyDeserializer - no property from null, null, {ENUM=null, TITLE=null, DESCRIPTION=null, DEFAULT=null, PATTERN=null, DESCRIMINATOR=null, MIN_ITEMS=null, MAX_ITEMS=null, MIN_PROPERTIES=null, MAX_PROPERTIES=null, MIN_LENGTH=null, MAX_LENGTH=null, MINIMUM=null, MAXIMUM=null, EXCLUSIVE_MINIMUM=null, EXCLUSIVE_MAXIMUM=null, UNIQUE_ITEMS=null, EXAMPLE=null, TYPE=null, FORMAT=null, READ_ONLY=null, VENDOR_EXTENSIONS={}}
[main] WARN io.swagger.util.PropertyDeserializer - no property from null, null, {ENUM=null, TITLE=null, DESCRIPTION=null, DEFAULT=null, PATTERN=null, DESCRIMINATOR=null, MIN_ITEMS=null, MAX_ITEMS=null, MIN_PROPERTIES=null, MAX_PROPERTIES=null, MIN_LENGTH=null, MAX_LENGTH=null, MINIMUM=null, MAXIMUM=null, EXCLUSIVE_MINIMUM=null, EXCLUSIVE_MAXIMUM=null, UNIQUE_ITEMS=null, EXAMPLE=null, TYPE=null, FORMAT=null, READ_ONLY=null, VENDOR_EXTENSIONS={}}
(was java.lang.NullPointerException) (through reference chain: io.swagger.models.ModelImpl["additionalProperties"]) (through reference chain: io.swagger.models.Swagger["definitions"]->java.util.LinkedHashMap["JsonApi"])
reading from /Volumes/onner/onner-sdk-ios/../API/docs/swagger.json
[main] WARN io.swagger.util.PropertyDeserializer - no property from null, null, {ENUM=null, TITLE=null, DESCRIPTION=null, DEFAULT=null, PATTERN=null, DESCRIMINATOR=null, MIN_ITEMS=null, MAX_ITEMS=null, MIN_PROPERTIES=null, MAX_PROPERTIES=null, MIN_LENGTH=null, MAX_LENGTH=null, MINIMUM=null, MAXIMUM=null, EXCLUSIVE_MINIMUM=null, EXCLUSIVE_MAXIMUM=null, UNIQUE_ITEMS=null, EXAMPLE=null, TYPE=null, FORMAT=null, READ_ONLY=null, VENDOR_EXTENSIONS={}}
[main] WARN io.swagger.util.PropertyDeserializer - no property from null, null, {ENUM=null, TITLE=null, DESCRIPTION=null, DEFAULT=null, PATTERN=null, DESCRIMINATOR=null, MIN_ITEMS=null, MAX_ITEMS=null, MIN_PROPERTIES=null, MAX_PROPERTIES=null, MIN_LENGTH=null, MAX_LENGTH=null, MINIMUM=null, MAXIMUM=null, EXCLUSIVE_MINIMUM=null, EXCLUSIVE_MAXIMUM=null, UNIQUE_ITEMS=null, EXAMPLE=null, TYPE=null, FORMAT=null, READ_ONLY=null, VENDOR_EXTENSIONS={}}
(was java.lang.NullPointerException) (through reference chain: io.swagger.models.ModelImpl["additionalProperties"]) (through reference chain: io.swagger.models.Swagger["definitions"]->java.util.LinkedHashMap["JsonApi"])
Exception in thread "main" java.lang.RuntimeException: missing swagger input or config!
        at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:63)
        at io.swagger.codegen.cmd.Generate.run(Generate.java:188)
        at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
make: *** [gen] Error 1

The offending spec definition in this case is this one:

  # http://jsonapi.org/format/#document-jsonapi-object
  JsonApi:
    description: An object describing the server's implementation
    type: object
    properties:
      version:
        type: string
      meta:
        $ref: '#/definitions/Meta'
    additionalProperties: false

This API conforms to JSON API and derives definitions from the JSON Schema definition of JSON API, which declares additionalProperties: false here. The $ref here is inconsequential—commenting out the additionalProperties line (and others like it in the rest of the spec) avoids the codegen failure and succeeds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions