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

[BUG] [JAVA] OAS3 incorrect data type when providing a default value #11367

Open
5 of 6 tasks
kevinparaport opened this issue Jan 21, 2022 · 8 comments
Open
5 of 6 tasks

Comments

@kevinparaport
Copy link

kevinparaport commented Jan 21, 2022

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When providing a default value, UI is saying the value is a string when it's an integer. Example JSON shows the variable as the correct data type though.

openapi-generator version

5.3.1

OpenAPI declaration file content or url
        - name: page
          in: query
          description: Zero-based page index of results to return
          required: false
          schema:
            type: integer
            format: int32
            default: 100
Generation Details

Using OAS3 = true

Related issues/PRs

#9775

Suggest a fix/enhancement

My guess is that the OAS3 changes for Java just aren't setting the type correctly in the mustache templates.

incorrectdatatype
correctdatatype

@kevinparaport
Copy link
Author

@cachescrubber it seems like you've been working on the OAS3 issues quite a bit. Let me know if there's anything I can do to help.

@cachescrubber
Copy link
Contributor

@kevinparaport You might want to review / test #11258. This PR should complete the OAS story.

@cachescrubber
Copy link
Contributor

@kevinparaport Is the OpenApi spec generated by SpringDoc?

@kevinparaport
Copy link
Author

@cachescrubber I upgraded to 5.4.0 and this is still an issue.

Here are the properties I'm using:
"oas3" to "true",
"useSpringController" to "true",
"useSpringfox" to "false",
"documentationProvider" to "springdoc",
"springDocDocumentationProvider" to "true",

@cachescrubber
Copy link
Contributor

Yep, I see the issue here. The @Schema() annotation hides the default SpringDoc could otherwise deduct from the @RequestParam annotation.

@Parameter(name = "page", description = "Zero-based page index of results to return", schema = @Schema(type = "foo", description = "", defaultValue = "100")) @Valid @RequestParam(value = "page", required = false, defaultValue = "100") Integer page

Simply remove the @Schema from @Parameter would fix things.

@welshm what Do you think? I would currently opt to remove @Schema.

@cachescrubber
Copy link
Contributor

@kevinparaport

"documentationProvider" to "springdoc"

Would be enough. You should remove oas3 and useSpringfox. springDocDocumentationProvider will be set automatically.

@welshm
Copy link
Contributor

welshm commented Feb 4, 2022

An issue with removing @Schema is that it enforces enum types (with allowableValues) - if the defaultVlaue field is removed from @Schema does SpringDoc behave as expected?

Could also try setting type field as aprt of @Schema - https://docs.swagger.io/swagger-core/v2.1.0/apidocs/io/swagger/v3/oas/annotations/media/Schema.html - although not sure if SpringDoc is respecting this field either

@cachescrubber
Copy link
Contributor

I filed #11526. @kevinparaport, please give it a try if you can.

@welshm I came to the conclusion that in it's current incarnation the @Schema annotation inside @Parameter does more harm then good - hence I removed it.

If you have a valid use-case for it it let's discuss it here. Probably a new feature PR would be appropriate?

wing328 pushed a commit that referenced this issue Feb 5, 2022
* Content mediatype is hardcoded in api.mustache #11511

* Generate Samples

* OAS3 incorrect data type when providing a default value #11367

* Generate Samples

* Fix JsonTypeName annotation handling in Java and JavaSpring

* Generate Samples

* getIsClassnameSanitized: use null safe equals
wing328 added a commit that referenced this issue Mar 16, 2022
…11650)

* Fix #5381
added x-is-one-of-interface extension for oneOf interface in mustache
template

* Fix #5381
fixed name of model from UNKNOWN_BASE_TYPE to right one in api: operationId + OneOf

Fix #5381
parcelableModel is not required

* Fix #5381
removed not needed methods

* Fix #5381
catch NPE cases in preprocessOpenAPI
updated samples

* Fix #5381
fixed generation of oneOf Models

* Fix #5381
addOneOfInterfaceModel only for cases when useOneOfInterfaces is true and for spring

* Fix #5381
NPE fix

* Fix #5381
spring: fixed use of oneOf Models in API

* Fix #5381
implementing oneOf for spring lib overriding methods with different behavior from default

* Fix #5381
added x-is-one-of-interface extension for oneOf interface in mustache
template

* Fix #5381
fixed name of model from UNKNOWN_BASE_TYPE to right one in api: operationId + OneOf

Fix #5381
removed not needed methods

Fix #5381
fixed generation of oneOf Models

Fix #5381
addOneOfInterfaceModel only for cases when useOneOfInterfaces is true and for spring

Fix #5381
NPE fix for tests

* Fix #5381
fixed handing of composed schema with array

* Fix #5381
fixed NPE in addOneOfInterfaceModel

* Fix #5381
fixed generation of oneOf models with descriminator

* Initial merge of 5.0

* Aligned with master formatting

* Corrected spacing for class names to align with samples.

* Merged master

* Updated samples

* Consolidate methods from JavaClient and SpringCodegen (mov up to AbstractJavaCodegen)

* set useLegacyDiscriminator to false, format templates

* Suport JsonTypeName, fq class name for spring.io.Resource

* Generate Samples

* Test full qualified usage of the spring Resource interface.

* Add java-camel to samples.circleci.spring profile

* Add more complex example combining inheritance and oneof-interface

* Remove x-implements Serializable from JavaClientCodegen (moved to AbstractJavaCodegen)

* Fix spacing before opening brace after extends/implements

* Generate Samples

* Add more complex example combining inheritance and oneof-interface

* Generate Samples

* Fix JsonTypeName annotation handling in Java and JavaSpring

* Content mediatype is hardcoded in api.mustache #11511

* Generate Samples

* OAS3 incorrect data type when providing a default value #11367

* Generate Samples

* Fix JsonTypeName annotation handling in Java and JavaSpring

* Generate Samples

* getIsClassnameSanitized: use null safe equals

* Fix JsonTypeName annotation handling in Java and JavaSpring (merge)

* Generate Samples

* Generate Samples

* Add oneof sample

* Generate Samples

* Giv example oas spec a meaningful name, demo usage of oneOf in Model

* Generate Samples

* Remove unnecessary JsonTypeName include, add example for JsonTypeName (Bar_Create)

* Generate Samples

* Generate Samples

Co-authored-by: Alexej <[email protected]>
Co-authored-by: JBurgess <[email protected]>
Co-authored-by: William Cheng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants