swagger-api / swagger-api/swagger-codegen
Referenced model with array causes NullpointerException
Open
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the Swagger Codegen CLI command and the API YAML and external schema shown in the issue. Start at io.swagger.parser.processors.ExternalRefProcessor.java:63, then trace the call through ModelProcessor while handling the array definition. Done means this input no longer throws a NullPointerException during generation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100