swagger-api / swagger-api/swagger-codegen
swagger-codegen 3.0.19 fail with NPE for jaxrs-jersey when use securitySchemes
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I upgraded from Swagger 2.0 to OpenApi 3.x and ran into issues around Security Schemes.
I defined securitySchemes bearer but it is failing with NPE when generating code around generators.DefaultCodegenConfig.fromSecurity .
I recreated the issue with a very simple YAML file.
It generates code fine from swagger UI hence something to do with code-gen used from CLI.
Swagger-codegen version
3.0.19 and 3.0.20 Worked fine
Swagger declaration file content or url
Command line used for generation
swagger-codegen generate -i provided_swagger.yaml -l jaxrs-jersey
Steps to reproduce
swagger-codegen generate -i provided_swagger.yaml -l jaxrs-jersey
Related issues/PRs
Suggest a fix/enhancement
Suspect schemeDefinition.getScheme() is returning Null instead of Bearer for some reason.
src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java
else if (SecurityScheme.Type.HTTP.equals(schemeDefinition.getType())) {
if ("bearer".equalsIgnoreCase(schemeDefinition.getScheme())) {
codegenSecurity.getVendorExtensions().put(CodegenConstants.IS_BEARER_EXT_NAME, Boolean.TRUE);
final Map<String, Object> extensions = schemeDefinition.getExtensions();
if (extensions != null && extensions.get("x-token-example") != null) {
final String tokenExample = extensions.get("x-token-example").toString();
if (StringUtils.isNotBlank(tokenExample)) {
codegenSecurity.getVendorExtensions().put("x-token-example", tokenExample);
}
}
}
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
Start by reproducing the failure with the provided openapi_security_issue.yaml.txt and the swagger-codegen generate command using jaxrs-jersey. Inspect generators/DefaultCodegenConfig.java around fromSecurity and schemeDefinition.getScheme(); done means the same OpenAPI 3 security scheme generates successfully without an NPE.
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
- 45/100