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.

Is there is a way to merge enums into one flat enum, or list?

See original GitHub issue

I am using the 2.0 spec and I have a field which I am using in a model as well as a path param where the value can be from one of three different enums. Using the syntax below is turning into an array with 3 enums. However, I would like it to be one flat enum. Is there any way to achieve this?

Thanks so much:

    properties:
      type:
        type: "string"
        enum: 
        - *unitTypes
        - *componentTypes
        - *snootTypes

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
hkosovacommented, Aug 15, 2017

YAML does not support this.

where the value can be from one of three different enums.

In OpenAPI 3.0 this can probably be handled using oneOf:

components:
  schemas:
    Colors1:
      type: string
      enum: [red, green, blue]
    Colors2:
      type: string
      enum: [black, white]
    
    Color:
      oneOf:
        - $ref: '#/components/schemas/Colors1'
        - $ref: '#/components/schemas/Colors2'
1reaction
hkosovacommented, Aug 16, 2017

can I also use this for my path param?

Yes. In 3.0, all parameters use a schema, so the syntax would be similar to models:

- in: path
  name: color
  required: true
  schema:
    oneOf:
      - $ref: '#/components/schemas/Colors1'
      - $ref: '#/components/schemas/Colors2'

I’m assuming there is no way to do this in OpenAPI 2.0?

Correct. oneOf is a new feature in 3.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java 8 how to merge multiple lists by enum type
You can use Collectors.toMap . Map by ResourcesStatus and merge two StatusSummary with count field in merge-function for the same ...
Read more >
Merge TypeScript Enums
There is no native support for merging 2 or more enums in typescript but its possible with a combination of type aliases and...
Read more >
11 Enumerations
Identifies one way enumerations, i. e., enumerations that can map only from the natural numbers to values that satisfy the enumeration's contract, but...
Read more >
Enum — Elixir v1.13.4
Returns a list of results of invoking fun on every nth element of enumerable , starting with the first element. map_intersperse(enumerable, separator, mapper)....
Read more >
Enum in TypeScript
Numeric enums can include members with computed numeric value. The value of an enum member can be either a constant or computed. The...
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