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

Wrong class generated for enum #28

Closed
lburgazzoli opened this issue Mar 24, 2022 · 7 comments · Fixed by #31
Closed

Wrong class generated for enum #28

lburgazzoli opened this issue Mar 24, 2022 · 7 comments · Fixed by #31
Assignees
Labels
bug Something isn't working

Comments

@lburgazzoli
Copy link

lburgazzoli commented Mar 24, 2022

Ginevn the follwogin OpenApi scheme:

   ConnectorNamespaceState:
      type: string
      enum:
        - disconnected
        - ready
        - deleting

the extension generates an invalid class:

@JsonIgnoreProperties(ignoreUnknown = true)
public enum ConnectorNamespaceState {
    private String value;

    ConnectorNamespaceState(String value){
        this.value = value;
    }

    @Override
    @JsonValue
    public String toString() {
        return String.valueOf(value);
    }

    @JsonCreator
    public static ConnectorNamespaceState fromValue(String text) {
        for (ConnectorNamespaceState b : ConnectorNamespaceState.values()) {
            if (String.valueOf(b.value).equals(text)) {
                return b;
            }
        }
        throw new IllegalArgumentException("Unexpected value '" + text + "'");
    }
}

Which is wrong as it does not include the listed enum values.

As an additional note, ConnectorNamespaceState.values() should probably be cached as each call to values() creates a copy of the enum values for each invocation

@ricardozanini ricardozanini self-assigned this Mar 28, 2022
@ricardozanini
Copy link
Member

@lburgazzoli, can you share your openapi file?

@lburgazzoli
Copy link
Author

Here you have https://github.com/lburgazzoli/bf2-cos-fleetshard/tree/opeanpi-get-quarus/cos-fleet-manager-api/src/main/openapi

@ricardozanini
Copy link
Member

Thank you! I'll take a look at it.

@ricardozanini ricardozanini added the bug Something isn't working label Mar 28, 2022
ricardozanini added a commit that referenced this issue Mar 28, 2022
Signed-off-by: Ricardo Zanini <zanini@redhat.com>
@ricardozanini ricardozanini linked a pull request Mar 28, 2022 that will close this issue
@ricardozanini
Copy link
Member

@lburgazzoli, the fix is in #31 if you want to take a look. As soon as we merge it, I'll release a new patch version.

ricardozanini added a commit that referenced this issue Mar 29, 2022
Fix #28 - Add Enum Outer Class template and values cache
@ricardozanini
Copy link
Member

@lburgazzoli, can you try the latest 0.3.1 version? Maven repo took a while to update the latest release. :(

@lburgazzoli
Copy link
Author

@lburgazzoli, can you try the latest 0.3.1 version? Maven repo took a while to update the latest release. :(

On my TODO list for tomorrow

@lburgazzoli
Copy link
Author

@ricardozanini much better, filled another issue: #38 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants