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

set schema name for EnumTypes #4727

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sam0r040
Copy link
Contributor

@sam0r040 sam0r040 commented Aug 30, 2024

At Springwolf we use the parsed schemas to generate Examples. Thereby we use the field Schema.getName() for all schemas including enums.

When enumAsRef is used, the name of the enum is missing in its class schema. Also, when serialized, the name of a schema is ignored because of the @JsonIgnore annotation.

This PR adds the schema name for enums. We found the following comment:

// Store off the ref and add the enum as a top-level model

And therefore believe that all enum classes should appear as models, resulting in the adaption of the tests.

Relates to #4722

@micryc micryc self-assigned this Sep 11, 2024
@micryc
Copy link
Contributor

micryc commented Sep 16, 2024

Hi @sam0r040 could you share some details on how you used enumAsRef annotation ? I think it should work as intended

@sam0r040
Copy link
Contributor Author

sam0r040 commented Oct 4, 2024

Hi @micryc,
sorry for the delay.

At Springwolf, we create AsyncAPI documentation for events, similar to OpenAPI/Swagger. @pdalfarr uses enumAsRef as shown in the following code example:

@io.swagger.v3.oas.annotations.media.Schema(enumAsRef = true)
    public enum MyEnumObject {
        VALUE1,
        VALUE2
    }

public record MyRootObject(MyEnumObject myEnumObjectField) {}

Our expectation of enumAsRef is that the enum schema is not embedded into the MyRootObject directly, but instead a ref to new MyEnumObject for the enum is created - including name, values etc. So, instead of inline, a ref is used.

We debugged the swagger-code and found the following two schemas when enumAsRef is used:
Using: final Map<String, Schema> models = converters.readAll(MyRootObject.class);

First, MyRootObject

Schema
- name=MyRootObject
- type=object
- properties:
  - myEnumObjectField
    - Schema(name=myEnumObjectField)
      - ref=#/components/schemas/MyEnumObject

Second, MyEnumObject

Schema
- name=null <-- missing name, expected: name="MyEnumObject"
- type=string
- _enum=VALUE1,VALUE2

Original issue at Springwolf: springwolf/springwolf-core#829 (comment)

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 this pull request may close these issues.

2 participants