You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 --------------------------------
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.
Update: When prefixing the referenced file with "./" codgen works when using the CLI. But it still fails from the editor (same way).
It should not be necessary to use the "./" prefix, and it works without the prefix for definitions.
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 ---------------------------
-- included file (params) ------------------
-- 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
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.
Related issues
Suggest a Fix
The text was updated successfully, but these errors were encountered: