openmicroservices.org icon indicating copy to clipboard operation
openmicroservices.org copied to clipboard

Should we use `enum` as a basic type key word?

Open jiusanzhou opened this issue 6 years ago • 3 comments

From OpenAPI Specification, define enum like below:

type: string
enum:
- a
- b

We declare the type of enum's item.

Should OMG change to that style?

jiusanzhou avatar Jul 30 '19 09:07 jiusanzhou

While there's the infamous YAML variable reference trick (e.g. https://github.com/microservices/microservice.guide/issues/85), it doesn't help as there's still no way to specify the underlying type. So yeah I think this would be a pretty useful change :+1: Range even works the same today as well:

        type: int
        range:  # default is no bounds for min and max
          min: 10
          max: 20

(from: https://microservice.guide/schema/actions/#arguments)

There's of course the question what should happen when the user defines sth. like:

type: int
enum:
- a
- b

But imho it would be reasonable to only allow a few common mappings (e.g. no float) and in the case above start with 0.


A bit off-topic:

It should be possible to specify such enums on the top level. This can be combined with objects (https://github.com/microservices/microservice.guide/issues/60) to a custom types section as proposed in https://github.com/microservices/microservice.guide/issues/50 with nested "structs" and objects.

wilzbach avatar Jul 30 '19 16:07 wilzbach

@wilzbach Please give this comment a thumbs up if we consider this resolved.

matthewhudson avatar Oct 10 '19 19:10 matthewhudson

@matthewhudson: no it's not resolved. The user is asking for enum to behave like range (i.e. allowing a custom type).

wilzbach avatar Oct 10 '19 19:10 wilzbach