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

[java jaxrs-jersey] default values are never generated in annotations #166

Open
tomzo opened this issue Sep 6, 2018 · 5 comments · May be fixed by #376
Open

[java jaxrs-jersey] default values are never generated in annotations #166

tomzo opened this issue Sep 6, 2018 · 5 comments · May be fixed by #376
Assignees
Milestone

Comments

@tomzo
Copy link

tomzo commented Sep 6, 2018

In all operations I have in my 3.0 spec, swagger-codegen never emits @DefaultValue annotation, although it exists on parameter definitions.

For parameter in operation like this:

    put:
      operationId: putExactResultZip
      tags:
        - results
      parameters:
        - name: failed
          in: query
          schema:
            type: boolean
            default: false

Emitted code for parameter is

,@Parameter(description = "") @QueryParam("failed") Boolean failed

While I would expect it to include the default value:

,@Parameter(description = "") @QueryParam("failed") @DefaultValue("false") Boolean failed

It does not matter what is the type of default, in a big project with many uses of default I see no @DefaultValue annotations in generated code.

Version info

Swagger-codegen (build from 3.0.0 release 713d52883cf320d46fb1a555c63e8ad99f78c16e), which is using 1.0.0 release of swagger-codegen-generators.

@HugoMario HugoMario added this to the v3.0.1 milestone Sep 6, 2018
@HugoMario HugoMario self-assigned this Sep 6, 2018
@jbeaven
Copy link

jbeaven commented Oct 16, 2018

I've observed the same issue :( adding the following to my generator code shows no sign at all of the defaults in my spec in the output:

    @Override
    public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Schema> schemas, OpenAPI openAPI) {

    	System.out.println("operation: " + operation.getOperationId());
    	System.out.println(operation);
    	System.out.println("schemas:");
    	System.out.println(schemas);
    	System.out.println("openAPI:");
    	System.out.println(openAPI);

        return super.fromOperation(path, httpMethod, operation, schemas, openAPI);
    }

Any hints on where I can change the code to fix this? Or is a fix on its way?

@tomzo
Copy link
Author

tomzo commented Oct 16, 2018

@jbeaven I haven't tried yet, but it could possibly work in the community fork of the generator https://github.com/OpenAPITools/openapi-generator

@douglasbgray
Copy link

I too had this problem. When I looked into it, the defaultValue for a parameter was not propagated from the schema to the CodegenParameter class. For my project, I am using a custom code generator so I added this method to my Config class and now defaults are showing in generated code.

  /**
   * Need to copy the default value for a Schema query/header parameter to the CodegenProperty.
   */
  @Override
  public CodegenParameter fromParameter(Parameter parameter, Set<String> imports) {
    CodegenParameter codegenParameter = super.fromParameter(parameter, imports);
    Object defaultValue = parameter.getSchema().getDefault();
    if (defaultValue != null) {
      codegenParameter.defaultValue = defaultValue.toString();
    }
    return codegenParameter;
  }

A long term fix would be to add the logic above in this method - https://github.com/swagger-api/swagger-codegen-generators/blob/master/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java#L2256

@HugoMario
Copy link
Contributor

thanks for updating @douglasbgray . i'll try to get this solve next week.

@mwiehl
Copy link

mwiehl commented May 3, 2019

+1. The default value should be transferred to the CodegenParameter object.

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

Successfully merging a pull request may close this issue.

5 participants