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

OpenAPI Client Generator generates classes that can't build for models with required readonly fields and inheritance #1208

Closed
runenielsen opened this issue Sep 13, 2023 · 6 comments · Fixed by #1214

Comments

@runenielsen
Copy link

Expected Behavior

When the OpenAPI Client Generator generates classes for an OpenAPI definition with required readonly fields and inheritance, the generated classes should build.

Actual Behaviour

The super-class (BookInfo in my example below) is generated correctly, but the constructor in the sub-class (ExtendedBookInfo) is generated incorrectly and makes the class unable to build. The required readonly parameter requiredReadOnly is not part of the constructor signature (which is correct), but it still tries to include it in the call to the super class' constructor.

The problem only exists for generated client models and is related to the fix done in this issue.

Steps To Reproduce

  1. Clone the project https://github.com/runenielsen/readonlyconstructorbug.git.
  2. Try to build and see it fail.
  3. Inspect the constructor in the generated class ExtendedBookInfo and see, that it is incorrect.
  4. See the file readonlyconstructorbug.yml for the OpenAPI definitions.

Environment Information

OS: MacOS
JDK: Java 17

Example Application

https://github.com/runenielsen/readonlyconstructorbug.git

Version

4.1.0

@altro3
Copy link
Collaborator

altro3 commented Sep 17, 2023

@runenielsen Hi! Hm... I test your example app and can't reproduce the problem. with yor yaml file I have 2 classes and ExtendedBookInfo is correct:

...

/**
 * ExtendedBookInfo
 */
@Serdeable
@JsonPropertyOrder(ExtendedBookInfo.JSON_PROPERTY_ISBN)
@Introspected
public class ExtendedBookInfo extends BookInfo {

    public static final String JSON_PROPERTY_ISBN = "isbn";

    @NotNull
    @Pattern(regexp = "[0-9]{13}")
    @Schema(name = "isbn", requiredMode = Schema.RequiredMode.REQUIRED)
    @JsonProperty(JSON_PROPERTY_ISBN)
    private String isbn;

    public ExtendedBookInfo(String isbn, String name, String requiredReadOnly) {
        super(name, requiredReadOnly);
        this.isbn = isbn;
    }
...

@altro3
Copy link
Collaborator

altro3 commented Sep 17, 2023

@runenielsen Could you try to use latest micronaut-openapi version - 5.1.1 and also build from master ?

@altro3
Copy link
Collaborator

altro3 commented Sep 17, 2023

@runenielsen Sorry, I didn't read it carefully. Yes, indeed, the problem is only in the client generator....

@runenielsen
Copy link
Author

@altro3 : Thanks a lot 🙂

@runenielsen
Copy link
Author

@altro3 : Do you know when Micronaut OpenAPI will be released again? Last release was 2 months ago, and my project needs your fixes 🙂

@altro3
Copy link
Collaborator

altro3 commented Oct 31, 2023

@runenielsen I just can ask about it.

@graemerocher Could we release micronaut-openapi 5.2.0 or we need to wait micronaut-core 4.2.0 release?

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 a pull request may close this issue.

2 participants