Skip to content

Specifying minimum/maximum for date/date-time #411

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

Closed
petrenyi-mark opened this issue Feb 20, 2020 · 6 comments
Closed

Specifying minimum/maximum for date/date-time #411

petrenyi-mark opened this issue Feb 20, 2020 · 6 comments
Labels

Comments

@petrenyi-mark
Copy link

We are using micoprofile openApi for generating an API description for our REST endpoints, and have a date type property on one of our request objects, which is required to be later than a specific date (2010-01-01 in our case), however if we set minimum to "2010-01-01" on @Schema we get a NumberFormatException.

We already realized that OpenApi specification itself is based on the JSON Schema draft which explicitly specifies minimum/maximum as number and does not have any other property for this (maybe there will be once with some vocabulary: json-schema-org/json-schema-spec#116).

(Note: our dto-s are defined and validated by xsd-s, in which we can specify minimum for date ie.:

<xsd:simpleType name="RestrictedDateType">
        <xsd:restriction base="xsd:date">
            <xsd:minInclusive value="2010-01-01"/>
        </xsd:restriction>
</xsd:simpleType>

Our goal is to include this restriction in the openAPI definition as well.)

Do you have any suggestions (or workaround) to imply the given property has a minimum/maximum date in the API specification?

@EricWittmann
Copy link
Contributor

Unfortunately I think the best you could do right now is to either add this as text in the description of the field (or in the bean) OR add an extension element. But I do not believe there is support for min/max of dates in OpenAPI or JSON Schema. You could try raising that as an issue in either or both of those communities. Because it's not something supported there, we cannot support it in microprofile-openapi.

Is your goal to have the payloads actually validated using the OpenAPI schema, or is the schema just used for generating documentation?

@petrenyi-mark
Copy link
Author

Thanks for the answer. I think we will add it to the description for now, since we're using the schema only for generating documentation.

@EricWittmann
Copy link
Contributor

EricWittmann commented Feb 21, 2020

If you wanted to get fancy, you could annotate a field with an extension using the @Extension annotation. And then implement your own custom filter to automatically update the description based on the value of the extension. Something like:

@Extension("x-minInclusive", "2010-01-01")
private Date myDateField;

Then your filter would look for the x-minInclusive property while filtering schemas. Might not be worth the effort, but it would be cool. :)

@petrenyi-mark
Copy link
Author

Thank you for the suggestion. Our objects are actually defined in xsd-s and we are using jaxb to generate the java objects. We have a plugin for jaxb which annotates the objects with @Schema based on the xsd definitions, so adding the restrictions to the description was simple.
However, using the @Extension annotation would be more elegant, unfortunately as we tried to achieve this, we found that the smallrye implementation processes the annotation only if placed on the Resource class, we raised an issue for this: smallrye/smallrye-open-api#267

@EricWittmann
Copy link
Contributor

OK - sorry for making a suggestion that didn't work! But at least we've identified a problem in SmallRye that we can fix!

image

@MikeEdgar
Copy link
Contributor

Closing, as there is no further action to take from a MicroProfile OpenAPI perspective.

Azquelt pushed a commit to Azquelt/microprofile-open-api that referenced this issue Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants