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.

Re-usable enums in path/query parameters

See original GitHub issue

I’ve been told that it’s not possible to use schemas in path/query parameters, but I have a case where multiple paths use the same enum pattern for inputs.

For example, I have the following pattern that is duplicated over many paths:

parameters:
- in: "query"
  ...
  enum: 
  - id
  - sku
  - guid
  - stock
  ...

Is it possible to generalize this in some way, so that I don’t have to define them for each path, but can just reference them?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:22
  • Comments:27 (16 by maintainers)

github_iconTop GitHub Comments

6reactions
mohsen1commented, Mar 7, 2015

@chanthakim15 Here is a quick example

---
swagger: '2.0'
info:
  version: 1.0.0
  title: Pets Store
paths:
  /pets:
    get:
      responses:
        200:
          description: Returns all the pets
          schema:
            $ref: '#/definitions/List'
        201:
          description: Returns all the pets
          schema:
            $ref: '#/definitions/Set'

definitions:
  List:
    type: string
    enum: &my-list
      - one
      - two
      - three
  Set:
    type: string
    enum: *my-list

@BigstickCarpet’s example is correct. If any of swagger tools is not supporting it, it’s a bug. Please file a bug for it.

1reaction
rdreycommented, Aug 27, 2015
Unidentified alias "OperationType" at line 78, column 33: enum: *OperationType ^

Flip the order, all good

EDIT: Some more info: Using a local copy of the Swagger Editor. Did reproduce with http://editor.swagger.io/#/ as well, quickly

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger: Reusing an enum definition as query parameter
I'm defining the Swagger Enum in the definitions part of my Swagger 2.0 spec file. OperationType: type: string enum: - registration - renewal....
Read more >
Enums - Swagger
Reusable enums. In OpenAPI 3.0, both operation parameters and data models use a schema , making it easy to reuse the data types....
Read more >
Unsupported REST Enum Use Cases - OutSystems 11 ...
Use cases currently unsupported when consuming REST services using "enums" and how to overcome some of these situations.
Read more >
[MockMvc] [OpenAPI 3.0] Type of enum parameter not picked ...
Declare an endpoint with a (path or query) parameter that refers to an enum from components section. For example, take a look at...
Read more >
F.A.Q - Springdoc-openapi
@Bean public GroupedOpenApi storeOpenApi() { String paths[] = {"/store/**"}; return ... How can I add Reusable Enums ?
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