Skip to content

Inconsistensies/(bug?) in Swagger Data Types specification for pattern keyword #10455

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
PaddySe opened this issue Sep 10, 2020 · 2 comments
Closed

Comments

@PaddySe
Copy link

PaddySe commented Sep 10, 2020

Hi,

The Swagger Data Types documentation for the pattern keyword (https://swagger.io/docs/specification/data-models/data-types/#pattern) specifies that the format used should follow the ECMA 262 format. This format is /pattern/flags. However, in the example a few lines below, you use a different format (pattern: '^\d{3}-\d{2}-\d{4}$').

This opens up for a lot of problems, people writing the yaml files according to your example, but the code generators require the ECMA 262 format (I have only checked with the csharp och python code generators, however the java generator seems to accept it), and if the format is wrong, the generators simply throws an exception about the wrong format being used.

There are a lot of (open) issues here about this problem.

The "fun" part is that while the csharp generator throws an exception if the wrong format is used, it doesn't generate any code that actually use the pattern...

Fixing the format to use /pattern/ in the yaml file stops the csharp generator from throwing an exception.

@hkosova
Copy link

hkosova commented Sep 10, 2020

As explained in OAI/OpenAPI-Specification#1985, pattern is supposed to contain a regular expression body such as ^[A-Za-z0-9]+$ or ^\d{3}-\d{2}-\d{4}$, rather than a regex literal such as /pattern/flags.

@PaddySe
Copy link
Author

PaddySe commented Sep 11, 2020

@hkosova, ahh, thanks for that! There were too many hits when I searched so couldn't really read through them all.

The problem I (and many others) have is that several of the code generators require the /pattern/flags format, since they throw exceptions if that format isn't used.

@PaddySe PaddySe closed this as completed Sep 11, 2020
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

No branches or pull requests

2 participants