using enum in schema leads to unexpected results
See original GitHub issueHi
With the following schema:
EnumBody:
required: true
content:
application/json:
schema:
type: object
enum:
- foo
required:
- foo
properties:
foo:
type: string
A call with body set to {foo: 'bar', bogus: 'baz'}
is rejected (which is expected), but a call with body set to {foo: 'bar'}
is also rejected which is not expected.
Is this a bug or did I misunderstood OpenApi specification ?
If needed I can provide a patch so that express-openapi-validator’s tests show this behavior.
All the best
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
MySQL 8.0 Reference Manual :: 11.3.5 The ENUM Type
An ENUM is a string object with a value chosen from a list of permitted values ... To prevent unexpected results when using...
Read more >What you need to know about GraphQL enums
Learn how GraphQL enums can help you build more robust and discoverable APIs, create simple interfaces, maintain slim resolvers, and more.
Read more >Unexpected result when using Enum.Parse() - Stack Overflow
I suspect that both FirstValue and Two have an internal value of 1, so the system doesn't know which string to output. public...
Read more >Unsupported REST Enum Use Cases
Use cases currently unsupported when consuming REST services using "enums" and how to overcome some of these situations.
Read more >Looking up Enum types and values in Postgres - Sadique Ali
Postgres Enums are created using the CREATE TYPE statement. ... and using blank as the separator will lead to unexpected and wrong results....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes ! this resolves my problem.
On the other hand, you might want to check why specifying
enum
with properties leads to weird results. I would have expected a consistent behavior or an error.Feel free to leave this bug open to track this issue or to close it.
Thanks for the help ! 😃
All the best
Woop! Excellent news! I’m glad it worked out.
The validator is properly handling the enum cases. There are examples of them working in the tests. I’m fairly certain that the specification you provided above is not behaviorally valid, despite it passing validation. Enums describe values and not keys. The OpenAPI spec allows one to define an enum property as a type object, however, the value should also be an object.
I’ll keep this open while I validate this is indeed the case.