swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

Avoid generating uncompilable response body in Spring's API template

Open smasset opened this issue 7 years ago • 22 comments

PR checklist

  • [x] Read the contribution guidelines.
  • [x] Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • [x] Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • [x] Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

If definitions start to get complicated, example response bodies can exceed Java compiler's limit for constant strings.

This PR addresses this issue by introducing and using two new lambdas to remove any unnecessary whitespace and (if still needed) to split the constant string into smaller compilable parts using a StringBuilder to merge them back again.

Fixes #9055

smasset avatar Sep 10 '18 23:09 smasset

Rebased against current master. Should fix #9055

Not sure why continuous-integration/appveyor/branch check is not running automatically

smasset avatar Apr 17 '19 04:04 smasset

Rebased against current master

smasset avatar Apr 20 '19 03:04 smasset

I can confirm this fixes #9055.

With provided example, only removing duplicate white space in generated example string made the class compilable.

Duplicating the billingAccounts property in CustomerAccount definition to a total of 10 instances illustrates the use of StringBuilder.

smasset avatar Apr 20 '19 05:04 smasset

Attaching ZIP archive with API interfaces generated by version 2.3.1 of swagger-codegen and by a snapshot with my proposed fix (with vanilla sample provided in #9055 and with extra array properties to demonstrate the use of StringBuilder)

CustomerAccountsApi.zip

smasset avatar Apr 20 '19 05:04 smasset

@frantuma, rebased this against latest master, is there anything missing in this PR ?

@drej1, can you confirm this fixes #9055 ?

smasset avatar Apr 29 '19 21:04 smasset

Hi @smasset , I appologize, I missed the notification. We checked your solution out and it's working... is it possible to merge it into the upcoming version? Thanks

drej1 avatar Jan 15 '21 12:01 drej1

Hey @drej1. I've just rebased against latest master and didn't get any conflict. Let's hope all checks pass and if so feel free to merge it for the next release.

smasset avatar Jan 18 '21 09:01 smasset

All checks passed. @frantuma can you include this PR in the next release ?

smasset avatar Jan 18 '21 09:01 smasset

@smasset thank you very much! @frantuma any idea when this will be released? thanks :)

drej1 avatar Jan 18 '21 12:01 drej1

Hi @diyfr, can you or somebody from the team check this PR and include it into the next release of 2.x (and also 3.x)? Thanks

drej1 avatar Feb 18 '21 07:02 drej1

Hi @diyfr, can you or somebody from the team check this PR and include it into the next release of 2.x (and also 3.x)? Thanks -> @cbornet @wing328

diyfr avatar Feb 18 '21 07:02 diyfr

@cbornet @wing328 any updates on this???

drej1 avatar Jul 16 '21 07:07 drej1

@cbornet @wing328 @diyfr or anybody... this is a pull request from 4 years ago...

drej1 avatar Feb 02 '22 07:02 drej1

@cbornet @wing328 @diyfr Will this ever be available? Been 5 years already..

Xerocry avatar Feb 16 '23 08:02 Xerocry

@cbornet @wing328 @diyfr @frantuma @smasset Guys, at least give some comment, please..

Xerocry avatar Apr 28 '23 05:04 Xerocry

@Xerocry This pull request 2903 doesn't solved this issue ?
Included in V4.2.2

Difference between Swagger Codegen and OpenAPI Generator

diyfr avatar Apr 28 '23 06:04 diyfr

@diyfr Maybe I misunderstood something but that is a fix for OpenApi generator, not swagger codegen, no? Sadly I can't switch cause of complex structure openapi plugin is running out of space and it would be great to have fix in swagger-codegen too :)

Xerocry avatar Apr 28 '23 08:04 Xerocry

@diyfr Maybe I misunderstood something but that is a fix for OpenApi generator, not swagger codegen, no? Sadly I can't switch cause of complex structure openapi plugin is running out of space and it would be great to have fix in swagger-codegen too :)

Check, it's present on master branch

diyfr avatar Apr 28 '23 09:04 diyfr

@wing328 @frantuma you can close this pull request

diyfr avatar Apr 28 '23 09:04 diyfr

Check, it's present on master branch

Correct me if I'm wrong but there are only lambdaEscapeDoubleQuote and lambdaRemoveLineBreak in master, no lambdaTrimWhitespace*lambdaSplitString*

Xerocry avatar Apr 28 '23 09:04 Xerocry

@Xerocry I suggest you propose a new PR. this one is based on an obsolete branch

diyfr avatar Apr 28 '23 10:04 diyfr

@diyfr I've just created a new PR #12136 cherry-picking all commits from this one without any conflict. Can you approve the workflows there ? I can also rebase this PR's branch against latest master if you prefer. Let me know what is more convenient for you

smasset avatar May 02 '23 09:05 smasset