question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

using enum in schema leads to unexpected results

See original GitHub issue

Hi

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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dod38frcommented, Oct 7, 2019

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

0reactions
cdimasciocommented, Oct 7, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found