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

@Schema maximum and minimum are Strings? #178

Closed
EricWittmann opened this issue Jan 17, 2018 · 4 comments
Closed

@Schema maximum and minimum are Strings? #178

EricWittmann opened this issue Jan 17, 2018 · 4 comments

Comments

@EricWittmann
Copy link
Contributor

EricWittmann commented Jan 17, 2018

For example, the @Schema annotation has this property:

https://github.com/eclipse/microprofile-open-api/blob/master/api/src/main/java/org/eclipse/microprofile/openapi/annotations/media/Schema.java#L113-L119

    /**
     * Sets the maximum numeric value for a property. 
     * Ignored if the value is an empty string.
     * 
     * @return the maximum value for this schema
     **/
    String maximum() default "";

The data model defines these properties as BigDecimal. Can I assume that this is done because java annotations don't support BigDecimal as a type for a property and that no other type would be sufficient?

@EricWittmann
Copy link
Contributor Author

Note that the Schema model also has the property multipleOf which required a BigDecimal, but the corresponding property of the annotation is double.

@msavy
Copy link

msavy commented Feb 23, 2018

Just a quick thought: could Hibernate's @Digits annotation serve as some inspiration? It has a variety of properties that allow you to constrain values in useful ways, such as @Digits(integer=10, fraction=2).

@EricWittmann
Copy link
Contributor Author

Assigning to myself. :)

@EricWittmann
Copy link
Contributor Author

OK so the reason that these properties are String instead of something more (seemingly) sensible (e.g. double) is that there is no default value that we could use to clearly indicate that the property was not included. In other words, if we made the property a double then there is no default value we could provide that is not also a valid value.

The way all these annotation properties work is that every one of them has a default value. When the annotation processor reads them, if the default value is found (for any given annotation property) then the processor is supposed to not include it in the final OAI document being generated. For String properties, the default value is typically empty string. So when the processor reads that property and sees empty string, it skips it.

For this particular property, switching to double would mean there is no sensible default that could indicate "skip it" to the processor.

We could do something like @Digits as @msavy suggests. I think that would allow us to use null as the "skip it" indicator. But it adds a fair bit of complexity for rather little value.

So for now I think we should update the javadoc to explain why the type is String and then close this issue.

Azquelt pushed a commit to Azquelt/microprofile-open-api that referenced this issue Mar 17, 2022
…lrye-smallrye-parent-12

Bump smallrye-parent from 10 to 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants