-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[kotlin-spring][server] Fix: treat "nullable: false, required: false" attributes with "default" fallback value as non-nullable in DTOs #22258
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
Open
Picazsoo
wants to merge
12
commits into
OpenAPITools:master
Choose a base branch
from
Picazsoo:feat/fix-required-false-with-default
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,196
−833
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
574db8c
attempts to make non required with default non-nullable
Picazsoo 299cc80
add more complex cases to the open api definition
Picazsoo 421b438
add java unit test
Picazsoo 5d00c83
fix dataClass attribute formatting
Picazsoo e837d3e
add updated files
Picazsoo 00f079c
add some default strings and fix test
Picazsoo 6159bca
add some default strings and fix test
Picazsoo 611eb87
fix open api definition to side-step issues with local enum schema de…
Picazsoo 1019573
add a case with nullable attribute with non-null default. That breaks…
Picazsoo 6428dde
fix behavior for nullable with null and non-null default
Picazsoo c9f57fc
regenerate code
Picazsoo 4993124
revert unrelated formatting changes in test
Picazsoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 24 additions & 6 deletions
30
modules/openapi-generator/src/main/resources/kotlin-spring/dataClassOptVar.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,24 @@ | ||
| {{#useBeanValidation}}{{>beanValidation}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}} | ||
| @Schema({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{.}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}", {{/example}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}} | ||
| @ApiModelProperty({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{.}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}", {{/example}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}{{#deprecated}} | ||
| @Deprecated(message = ""){{/deprecated}}{{#vendorExtensions.x-field-extra-annotation}} | ||
| {{{.}}}{{/vendorExtensions.x-field-extra-annotation}} | ||
| @get:JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isArray}}{{baseType}}<{{/isArray}}{{classname}}.{{{nameInPascalCase}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{^defaultValue}}null{{/defaultValue}}{{#defaultValue}}{{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}} | ||
| {{! comments are used to break long lines into multiple lines for better readability }} | ||
| {{#useBeanValidation}}{{>beanValidation}}{{>beanValidationModel}}{{/useBeanValidation}}{{! | ||
| }}{{#swagger2AnnotationLibrary}} | ||
| @Schema({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{.}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}", {{/example}}required = false, {{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{! | ||
| }}{{/swagger2AnnotationLibrary}}{{! | ||
| }}{{#swagger1AnnotationLibrary}} | ||
| @ApiModelProperty({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{.}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}", {{/example}}required = false, {{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{! | ||
| }}{{/swagger1AnnotationLibrary}}{{! | ||
| }}{{#deprecated}} | ||
| @Deprecated(message = ""){{! | ||
| }}{{/deprecated}}{{! | ||
| }}{{#vendorExtensions.x-field-extra-annotation}} | ||
| {{{.}}}{{! | ||
| }}{{/vendorExtensions.x-field-extra-annotation}} | ||
| @get:JsonProperty("{{{baseName}}}", required = false) | ||
| {{#isInherited}}{{! | ||
| }}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{! | ||
| }}{{#isEnum}}{{#isArray}}{{baseType}}<{{/isArray}}{{classname}}.{{{nameInPascalCase}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{! | ||
| }}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{! | ||
| }}{{^defaultValue}}? = null{{/defaultValue}}{{! | ||
| }}{{#defaultValue}}{{#isNullable}}?{{/isNullable}} = {{! | ||
| }}{{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{! | ||
| }}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{! | ||
| }}{{/defaultValue}} | ||
26 changes: 21 additions & 5 deletions
26
modules/openapi-generator/src/main/resources/kotlin-spring/dataClassReqVar.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,21 @@ | ||
| {{#useBeanValidation}}{{>beanValidation}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}} | ||
| @Schema({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{.}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}", {{/example}}required = true, {{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}} | ||
| @ApiModelProperty({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{.}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}", {{/example}}required = true, {{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}{{#vendorExtensions.x-field-extra-annotation}} | ||
| {{{.}}}{{/vendorExtensions.x-field-extra-annotation}} | ||
| @get:JsonProperty("{{{baseName}}}", required = true){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isArray}}{{baseType}}<{{/isArray}}{{classname}}.{{{nameInPascalCase}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}?{{/isNullable}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}} | ||
| {{! comments are used to break long lines into multiple lines for better readability }} | ||
| {{#useBeanValidation}}{{>beanValidation}}{{>beanValidationModel}}{{/useBeanValidation}}{{! | ||
| }}{{#swagger2AnnotationLibrary}} | ||
| @Schema({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{.}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}", {{/example}}required = true, {{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{! | ||
| }}{{/swagger2AnnotationLibrary}}{{! | ||
| }}{{#swagger1AnnotationLibrary}} | ||
| @ApiModelProperty({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{.}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}", {{/example}}required = true, {{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{! | ||
| }}{{/swagger1AnnotationLibrary}}{{! | ||
| }}{{#vendorExtensions.x-field-extra-annotation}} | ||
| {{{.}}}{{! | ||
| }}{{/vendorExtensions.x-field-extra-annotation}} | ||
| @get:JsonProperty("{{{baseName}}}", required = true) | ||
| {{#isInherited}}{{! | ||
| }}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{! | ||
| }}{{#isEnum}}{{#isArray}}{{baseType}}<{{/isArray}}{{classname}}.{{{nameInPascalCase}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{! | ||
| }}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{! | ||
| }}{{#isNullable}}?{{/isNullable}}{{! | ||
| }}{{#defaultValue}} = {{! | ||
| }}{{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{! | ||
| }}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{! | ||
| }}{{/defaultValue}} |
25 changes: 21 additions & 4 deletions
25
modules/openapi-generator/src/main/resources/kotlin-spring/interfaceOptVar.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,22 @@ | ||
| {{! comments are used to break long lines into multiple lines for better readability }} | ||
| {{#swagger2AnnotationLibrary}} | ||
| @get:Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}requiredMode = Schema.RequiredMode.REQUIRED, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}} | ||
| @get:ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}{{#vendorExtensions.x-field-extra-annotation}} | ||
| {{{.}}}{{/vendorExtensions.x-field-extra-annotation}} | ||
| {{#isInherited}}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInPascalCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? {{^discriminator}}= {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}{{/discriminator}} | ||
| @get:Schema({{#example}}example = "{{{.}}}", {{/example}}{{! | ||
| }}{{#required}}requiredMode = Schema.RequiredMode.REQUIRED, {{/required}}{{! | ||
| }}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}{{! | ||
| }}description = "{{{description}}}"){{! | ||
| }}{{/swagger2AnnotationLibrary}}{{! | ||
| }}{{#swagger1AnnotationLibrary}} | ||
| @get:ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{! | ||
| }}{{#required}}required = {{required}}, {{/required}}{{! | ||
| }}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}{{! | ||
| }}value = "{{{description}}}"){{! | ||
| }}{{/swagger1AnnotationLibrary}}{{! | ||
| }}{{#vendorExtensions.x-field-extra-annotation}} | ||
| {{{.}}}{{! | ||
| }}{{/vendorExtensions.x-field-extra-annotation}} | ||
| {{#isInherited}}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{! | ||
| }}{{#isEnum}}{{classname}}.{{nameInPascalCase}}{{/isEnum}}{{! | ||
| }}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{! | ||
| }}{{#isNullable}}?{{/isNullable}}{{! | ||
| }}{{^isNullable}}{{^defaultValue}}?{{/defaultValue}}{{/isNullable}}{{! | ||
| }}{{^discriminator}} = {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}{{/discriminator}} |
22 changes: 18 additions & 4 deletions
22
modules/openapi-generator/src/main/resources/kotlin-spring/interfaceReqVar.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,19 @@ | ||
| {{! comments are used to break long lines into multiple lines for better readability }} | ||
| {{#swagger2AnnotationLibrary}} | ||
| @get:Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}requiredMode = Schema.RequiredMode.REQUIRED, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}} | ||
| @get:ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}{{#vendorExtensions.x-field-extra-annotation}} | ||
| {{{.}}}{{/vendorExtensions.x-field-extra-annotation}} | ||
| {{#isInherited}}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInPascalCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}} | ||
| @get:Schema({{#example}}example = "{{{.}}}", {{/example}}{{! | ||
| }}{{#required}}requiredMode = Schema.RequiredMode.REQUIRED, {{/required}}{{! | ||
| }}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}{{! | ||
| }}description = "{{{description}}}"){{! | ||
| }}{{/swagger2AnnotationLibrary}}{{! | ||
| }}{{#swagger1AnnotationLibrary}} | ||
| @get:ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{! | ||
| }}{{#required}}required = {{required}}, {{/required}}{{! | ||
| }}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}{{! | ||
| }}value = "{{{description}}}"){{! | ||
| }}{{/swagger1AnnotationLibrary}}{{! | ||
| }}{{#vendorExtensions.x-field-extra-annotation}} | ||
| {{{.}}}{{! | ||
| }}{{/vendorExtensions.x-field-extra-annotation}} | ||
| {{#isInherited}}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{! | ||
| }}{{#isEnum}}{{classname}}.{{nameInPascalCase}}{{/isEnum}}{{! | ||
| }}{{^isEnum}}{{{dataType}}}{{/isEnum}} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am using these dummy multi-line comments as a way to make the long lines more readable.