Coder Social home page Coder Social logo

Comments (4)

gunnarkessler avatar gunnarkessler commented on June 26, 2024 1

Thank you for the explanation and all the infos. I will look into the workaround.

from openapi-generator.

jpfinne avatar jpfinne commented on June 26, 2024

@gunnarkessler There is no such {{^lombok.NoArgsConstructor} in pojo.mustache in version 7.6.0. Do you use another version or do you have custom templates?

{{^lombok.NoArgsConstructor} was removed in favor of a more robust {{#vendorExtensions.x-java-no-args-constructor}} computed in java in SpringCodeGen.postProcessAllModels(Map<String, ModelsMap> objs)

To generate a no-arg-constructor, the spring generator needs to check the combination of

  • fields present
  • required fields present with generatedConstructorWithRequiredArgs=true
  • required fields present with generatedConstructorWithRequiredArgs=false (maybe not done in 7.6.0. I will check)
  • additionalProperties in the contract
  • generateConstructorWithAllArgs flag
  • generatedConstructorWithRequiredArgs
  • lombok dedicated handling introduced in templates #17622
  • additionalModelTypeAnnotations option with different combination of lombok annotations

This is nearly impossible to achieve in straight mustache conditions.

It seems your usage of lombok is to create a builder.
For that purpose you can use the new generateBuilders option and remove your additionalModelTypeAnnotations

from openapi-generator.

gunnarkessler avatar gunnarkessler commented on June 26, 2024

There is no such {{^lombok.NoArgsConstructor} in pojo.mustache in version 7.6.0. Do you use another version or do you have custom templates?

Sorry, if I put it ambiguously. I was trying to say, that the above section was still present in 7.5.0. and removed with 7.6.0

Thank you for the pointer to SpringCodeGen.postProcessAllModels(Map<String, ModelsMap> objs). I was only looking at the mustache-template.

I am currently performing a spring boot upgrade of an application consuming numerous extrenal REST-services and therefore also updating the generator used and a lot of external dependencies.

Our application stack expects objects to be deserialized to have a default constructor. Before upgrading the generator all generated pojos contained no default constructor but the aforementioned lombok annotation, after the upgrade pojos for contract objects with required fields hat explicit default constructors generated, and objects without required fields had none. I was looking for a way to generate the pojos with the same structure as before the update.

I had already stumbled upon vendorExtensions.x-java-no-args-constructor but I have not yet understood, how and where to use this option.

from openapi-generator.

jpfinne avatar jpfinne commented on June 26, 2024

@gunnarkessler The root cause of the bug is the parsing of ADDITIONAL_MODEL_TYPE_ANNOTATIONS and the subsequent parsing of lombok annotations
The parsing of ADDITIONAL_MODEL_TYPE_ANNOTATIONS is done with a split using this regex
"\\s*(;|\\r?\\n)\\s*"
This code exists for years, so I would not consider that as an issue.
You use space instead of semi column in your configuration. So the result is additionalModelTypeAnnotations with one row.

The lombok annotion parsing is done with this regex:
"@lombok.(\\w+\\.)*(?<ClassName>\\w+)(\\(.*?\\))?"
The result is that lombokAnnotations contains only one row: @lombok.Builder
This is an additional bug introduced by the lombok handling. See #17793 for similar issues.

So the handling in postProcessAllModels() does not know about NoArgsConstructor.

The fact that it worked in 7.5.0 and before is probably pure luck.

Workaround for you: use semicolon separated values:
@lombok.Builder;@lombok.NoArgsConstructor;@lombok.AllArgsConstructor

Can you rename your bug report to reflect the finding? Like "wrong parsing of space separated lombok annotations"

from openapi-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.