-
Notifications
You must be signed in to change notification settings - Fork 11
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
False positive for missing maxLength for format: date #41
Comments
I can also note that it is the same with
For date-time, it is implicit that I can also note that when generating code using open-api generators, at least with Java, if maxLength is added to a date or a date-time format, the code generator adds a This is similar for the UUID format as well: minLength and maxLength should not be required for these known formats. |
Additionally, I almost feel warning rules should be shown instead if an API specifies minLength or maxLength on known format types with implicit sizes. However, pattern should perhaps be allowed, if say for example an API would like to always receive date-time values in Zulu time, this can be achieved with a regular expression. |
Seeing as format is by default merely an annotation it may not be used at all in the validaiton process. In order to keep things secure, if you're using OpenAPI-based validation, or if you just want to be clear about how that API is going to work, it's better to define the maxLength properties even when there is a format in place. It might feel weird, but tbh format is weird, and there's no nice answer to that other than a time machine and/or making it never exist.
https://json-schema.org/draft/2020-12/json-schema-validation#name-format-assertion-vocabulary |
When a property has
we get a false positive
Context
The
date
format must matchfull-date = date-fullyear "-" date-month "-" date-mday
as per RFC 3339 and ISO 8601, such as
2023-04-03
and thus there is an implicitminLength
andmaxLength
of 10 for this format, so there should be no error.Current Behavior
error diagnostic
Expected Behavior
no error
Possible Workaround/Solution
one can explicitly add
but that bloats the OpenAPI definition.
Note that the format may be defined via an
allOf
construct as well, so it may not be in the same JSON Schema objectas the
type: string
. This may be harder for Spectral to handle:Steps to Reproduce
Environment
The text was updated successfully, but these errors were encountered: