Description
Description
When referencing a parameter defined in another file, the swagger-editor successfully validates the YAML and creates the API documentation, but code generation fails with a NullPointer exception and no further details. If the same parameter is defined in the parameters section of the single file, then everything is ok.
Any code generation fails. I specifically tried server-JAX-RS and client-HTML.
Swagger-codegen version
swagger-editor 2.10.3
swagger-codegen 2.2.2
Swagger declaration file content or url
-- main yaml file ---------------------------
swagger: "2.0"
info:
title: Test Case for Code Gen Issue - Fails
description: |
Test case to demonstrate the problem with generating code when external parameter references are used.
This is the failure test case.
version: 0.0.1
produces:
- application/json
paths:
/test/fails:
get:
parameters:
- $ref: 'fails_param.yaml#/parameters/TheParam'
responses:
"200":
$ref: '#/responses/TheResponse'
parameters: {} # are in fails_param.yaml
responses:
TheResponse:
description: The response.
schema:
$ref: '#/definitions/TheResponseSchema'
definitions:
TheResponseSchema:
description: The response schema.
type: object
properties:
prop1:
type: integer
prop2:
type: string
# end
-- included file (params) ------------------
# parameters used in fails_main.yaml
swagger: "2.0"
info:
title: Parameters for Test Case for Code Gen Issue - Fails
description: |
Parameters for the test case to demonstrate the problem with generating
code when external parameter references are used.
This is the failure test case.
version: 0.0.1
parameters:
TheParam:
name: param
in: query
type: string
description: The parameter.
# end
-- end YAML files --------------------------------
Command line used for generation
Initially done from swagger-editor (local)
java -jar C:\Utils\swagger-tools\swagger-codegen-cli.jar generate -l jaxrs -i fails_main.yaml
Steps to reproduce
Use above swagger-codegen-cli command in a directory with both the above YAML files.
Exception reported by swagger-codegen-cli
Exception in thread "main" java.lang.NullPointerException
at io.swagger.codegen.DefaultGenerator.generateParameterId(DefaultGenerator.java:834)
at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:758)
at io.swagger.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:727)
at io.swagger.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:356)
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:666)
at io.swagger.codegen.cmd.Generate.run(Generate.java:234)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:41)
The problem seems to be that the $ref in the parameters section is not properly parsed. In the verbose mode, it shows a null parameter list.
"paths" : {
"/test/fails" : {
"get" : {
"parameters" : [ null ],
"responses" : {
"200" : {
"description" : "The response.",
"schema" : {
"$ref" : "#/definitions/TheResponseSchema"
}
}
}
}
}
},