Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referenced model with array causes NullpointerException #1530

Open
samskiter opened this issue Nov 6, 2015 · 2 comments
Open

Referenced model with array causes NullpointerException #1530

samskiter opened this issue Nov 6, 2015 · 2 comments

Comments

@samskiter
Copy link

My api spec:

swagger: '2.0'
info:
  title: Test API
  description: This is my awesome documentation
  version: 1.0.0
host: test.com

schemes:
  - https
produces:
  - application/json

paths:
  /sites:
    get:
      description: |
        Get some sites
      responses:
        '200':
          description: Success
          schema:
            $ref: '#/definitions/sites'
definitions:
  sites:
    $ref: './schemas/sitesGETresponse.schema.json'

sitesGETresponse.schema.json:

{
    "id": "sitesGETresponse.schema.json#",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Site list",
    "description": "Response to site list request",
    "type": "array",
    "items": {
        "type": "string"
    }
}

Created an error:

> java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i ../path/to/my/swagger/api.yaml -o samples/client/test/android-java -l android -v
[main] INFO io.swagger.codegen.config.CodegenConfigurator -
VERBOSE MODE: ON. Additional debug options are injected
 - [debugSwagger] prints the swagger specification as interpreted by the codegen
 - [debugModels] prints models passed to the template engine
 - [debugOperations] prints operations passed to the template engine
 - [debugSupportingFiles] prints additional data passed to the template engine
reading from ../path/to/my/swagger/api.yaml
Exception in thread "main" java.lang.NullPointerException
    at io.swagger.parser.processors.ExternalRefProcessor.processRefToExternalDefinition(ExternalRefProcessor.java:63)
    at io.swagger.parser.processors.ModelProcessor.processRefModel(ModelProcessor.java:92)
    at io.swagger.parser.processors.ModelProcessor.processModel(ModelProcessor.java:33)
    at io.swagger.parser.processors.DefinitionsProcessor.processDefinitions(DefinitionsProcessor.java:40)
    at io.swagger.parser.SwaggerResolver.resolve(SwaggerResolver.java:42)
    at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:64)
    at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:317)
    at io.swagger.codegen.cmd.Generate.run(Generate.java:186)
    at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)

Running swagger codegen built from source, master checkout

@samskiter
Copy link
Author

More information:

I get the same error if I try to generate with objc

Note that the example works if I change sitesGETresponse.schema.json to:

{
    "id": "sitesGETresponse.schema.json#",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Site list",
    "description": "Response to site list request",
    "type": "object",
    "properties": {
        "title": {
            "type": "string"
        }
    }
}

And I get another failure (this might be a different issue) with:

{
    "$ref": "./schemas/site.schema.json"
}

OR

{
    "$ref": "./site.schema.json"
}

Where site.schema.json:

{
    "id": "sitesGETresponse.schema.json#",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Site",
    "description": "A site",
    "type": "object",
    "properties": {
        "title": {
            "type": "string"
        },
        "count": {
            "type": "integer"
        },
        "description": {
            "type": "string"
        }
    },
    "required": ["title"]
}

@samskiter
Copy link
Author

I've tracked the issue to the processRefToExternalDefinition method in ExternalRefProcessor in swagger-parser. There seem to be numerous ways this one line can fail, and I've managed to find them all...

See: swagger-api/swagger-parser#132

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant