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

Fixing @Schema's defaultValue generation and SwaggerDocumentationConfig #796

Merged
merged 3 commits into from Nov 18, 2020

Conversation

reta
Copy link
Contributor

@reta reta commented Nov 6, 2020

{{^useOas2}}
{{^springBootV2}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to change but there is an issue since springdoc-openapi-ui dependency is introduced but the version is conditional on {{springBootV2}}, fixing that as well.

@@ -53,7 +50,7 @@ public class SwaggerDocumentationConfig {
{{/useOptional}}
.apiInfo(apiInfo());
}
{{#useOas2}}

ApiInfo apiInfo() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like ApiInfo is needed even for OAS 3.x, adding that

{{#isQueryParam}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{#useOas2}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{defaultValue}}}"{{/defaultValue}}){{/useOas2}}{{^useOas2}}@Parameter(in = ParameterIn.QUERY, description = "{{{description}}}" {{#required}},required=true{{/required}},schema=@Schema({{#allowableValues}}{{> allowableValues }}{{/allowableValues}}{{#defaultValue}}{{#allowableValues}},{{/allowableValues}} defaultValue="{{{defaultValue}}}"{{/defaultValue}})){{/useOas2}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestParam(value = "{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{>optionalDataType}} {{paramName}}{{/isQueryParam}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now generates correctly:

@Parameter(in = ParameterIn.QUERY, description = "", schema = @Schema(defaultValue = "*"))
@Parameter(in = ParameterIn.HEADER, description = "status", 
    schema = @Schema(allowableValues = {"AVAILABLE", "PENDING"},  defaultValue = "AVAILABLE")                                          )

@SlavchoArsovski
Copy link

Hi @reta can i help you testing?

Deploy the snapshot version od 1.0.24-SNAPSHOT and i can test it.
I guess you need to merge first.

Best,
Slavcho

@reta
Copy link
Contributor Author

reta commented Nov 6, 2020

Hi @reta can i help you testing?

Deploy the snapshot version od 1.0.24-SNAPSHOT and i can test it.
I guess you need to merge first.

Best,
Slavcho

@SlavchoArsovski yeah, that would be much appreciated. I do not have merge permissions on the repository, so the way to test it is still simple:

Please let me know if you need any help, thanks!

@SlavchoArsovski
Copy link

SlavchoArsovski commented Nov 6, 2020

Hi @reta,

I have tested, i did tested by copying your templates from this PR.
There is no compilation issues.
However OAS3 and spring fox ui 3.0 bring a lot of possibilities.

For instance now inheritance and composition are not well described.

There are descriptions like:

@Schema(subTypes = {Cat.class, Dog.class}, discriminatorProperty = "petType", discriminatorMapping = {
@DiscriminatorMapping(value = "Cat", schema = Cat.class),
@DiscriminatorMapping(value = "Dog", schema = Dog.class)
})

@ApiResponse(responseCode = "200", description = "Get Payment Details", content = @content(schema = @Schema(oneOf = {
Cat.class, Dog.class}))) })

Which are not used.

In other words, generated code is fine. But Annotation description is missing in such cases. Now with this version my swagger ui documentation is not complete.

Best,
Slavcho

@reta
Copy link
Contributor Author

reta commented Nov 6, 2020

Hi @SlavchoArsovski ,

The OAS 3.x is very rich indeed, not all features are supported by generators yet however it could be certainly improved. It just takes more time unfortunately since the changes in how generator model is built might be needed. Do you use PetStore schema or crafted by yourself?

@SlavchoArsovski
Copy link

@reta, it is a big API from my project, i just tried to add example to see how inheritance and composition will play out with new swagger ui springfox 3.0.

@reta
Copy link
Contributor Author

reta commented Nov 6, 2020

Got it @SlavchoArsovski , would you mind please to submit an issue with examples of OAS 3.x API definitions and expected generation outcomes, so we could work it through, thank you.

@SlavchoArsovski
Copy link

SlavchoArsovski commented Nov 7, 2020

Got it @SlavchoArsovski , would you mind please to submit an issue with examples of OAS 3.x API definitions and expected generation outcomes, so we could work it through, thank you.

@reta sure, but i will need some time, but in my opinion this PR should be merged

@reta
Copy link
Contributor Author

reta commented Nov 17, 2020

@HugoMario , sorry, mind taking a look please?

@HugoMario
Copy link
Contributor

@reta
looking

@HugoMario HugoMario merged commit a0ade99 into swagger-api:master Nov 18, 2020
@HugoMario
Copy link
Contributor

thanks @reta !!

@reta
Copy link
Contributor Author

reta commented Nov 18, 2020

Thanks @HugoMario

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

Successfully merging this pull request may close these issues.

Migration from swagger codegen 3.0.21 to 3.0.23 fails due to compilation errors
3 participants