New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-usable enums in path/query parameters #300

Closed
marcus-maws opened this Issue Mar 5, 2015 · 26 comments

Comments

Projects
None yet
8 participants
@marcus-maws

marcus-maws commented Mar 5, 2015

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?

@webron

This comment has been minimized.

Show comment
Hide comment
@webron

webron Mar 5, 2015

Member

I think we've had a similar issue about it, or someone was talking about it in the mailing list. I think it's a fair request to avoid repetitions for 'primitive' definitions as well and it's something we should look into in the next version of the spec.

Member

webron commented Mar 5, 2015

I think we've had a similar issue about it, or someone was talking about it in the mailing list. I think it's a fair request to avoid repetitions for 'primitive' definitions as well and it's something we should look into in the next version of the spec.

@marcus-maws

This comment has been minimized.

Show comment
Hide comment
@marcus-maws

marcus-maws Mar 5, 2015

OK, thanks for the quick response.

marcus-maws commented Mar 5, 2015

OK, thanks for the quick response.

@marcus-maws marcus-maws closed this Mar 5, 2015

@webron

This comment has been minimized.

Show comment
Hide comment
@webron

webron Mar 5, 2015

Member

No, don't close it :) It's good to get feedback from others as well.

Member

webron commented Mar 5, 2015

No, don't close it :) It's good to get feedback from others as well.

@webron webron reopened this Mar 5, 2015

@marcus-maws

This comment has been minimized.

Show comment
Hide comment
@marcus-maws

marcus-maws commented Mar 5, 2015

OK. :-)

@marcus-maws

This comment has been minimized.

Show comment
Hide comment
@marcus-maws

marcus-maws Mar 5, 2015

On a separate issue (touched on in #290), I have a situation where multiple paths can take the same collection of parameters. It appears that again, I have to define all those parameters individually for each path. Being able to separate all those parameters would be useful as well.

marcus-maws commented Mar 5, 2015

On a separate issue (touched on in #290), I have a situation where multiple paths can take the same collection of parameters. It appears that again, I have to define all those parameters individually for each path. Being able to separate all those parameters would be useful as well.

@webron

This comment has been minimized.

Show comment
Hide comment
@webron

webron Mar 5, 2015

Member

That should be a separate issue though. However, you can define parameters in a single place and then refer to them from multiple paths.

Member

webron commented Mar 5, 2015

That should be a separate issue though. However, you can define parameters in a single place and then refer to them from multiple paths.

@mohsen1

This comment has been minimized.

Show comment
Hide comment
@mohsen1

mohsen1 Mar 5, 2015

Contributor

If you're writing you specs in YAML you can take advantage of YAML anchors to avoid reputations.

Contributor

mohsen1 commented Mar 5, 2015

If you're writing you specs in YAML you can take advantage of YAML anchors to avoid reputations.

@webron

This comment has been minimized.

Show comment
Hide comment
@webron

webron Mar 5, 2015

Member

But since there's a solution for that in the spec, it's better to utilize than than to utilize a solution that's can't be converted back and forth between JSON and YAML.

Member

webron commented Mar 5, 2015

But since there's a solution for that in the spec, it's better to utilize than than to utilize a solution that's can't be converted back and forth between JSON and YAML.

@webron

This comment has been minimized.

Show comment
Hide comment
@webron

webron Mar 5, 2015

Member

My bad, I thought @mohsen1 referred to repeating the parameters. His solution is most certainly valid for the original request though!

Member

webron commented Mar 5, 2015

My bad, I thought @mohsen1 referred to repeating the parameters. His solution is most certainly valid for the original request though!

@James-Messinger

This comment has been minimized.

Show comment
Hide comment
@James-Messinger
Contributor

James-Messinger commented Mar 6, 2015

@Ckim15

This comment has been minimized.

Show comment
Hide comment
@Ckim15

Ckim15 Mar 7, 2015

@mohsen1, Could you provide a working sample yaml spec where I can avoid repetition for enum?

I checked BigStickCarpet's url (https://github.com/BigstickCarpet/swagger-parser/blob/master/tests/files/non-object-refs.yaml#L40), It doesn't work.

Ckim15 commented Mar 7, 2015

@mohsen1, Could you provide a working sample yaml spec where I can avoid repetition for enum?

I checked BigStickCarpet's url (https://github.com/BigstickCarpet/swagger-parser/blob/master/tests/files/non-object-refs.yaml#L40), It doesn't work.

@mohsen1

This comment has been minimized.

Show comment
Hide comment
@mohsen1

mohsen1 Mar 7, 2015

Contributor

@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.

Contributor

mohsen1 commented 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.

@rdrey

This comment has been minimized.

Show comment
Hide comment

rdrey commented Aug 27, 2015

@webron

This comment has been minimized.

Show comment
Hide comment
@webron

webron Aug 27, 2015

Member

OMG, what a coincidence, I just answered on it there too! 😉

Member

webron commented Aug 27, 2015

OMG, what a coincidence, I just answered on it there too! 😉

@rdrey

This comment has been minimized.

Show comment
Hide comment
@rdrey

rdrey Aug 27, 2015

:P Thanks! Got the YAML reference trick to work, only issue I had is that the order in the file seems to be important. (Sorry, I'm a YAML noob.) So now I have definitions above paths.

rdrey commented Aug 27, 2015

:P Thanks! Got the YAML reference trick to work, only issue I had is that the order in the file seems to be important. (Sorry, I'm a YAML noob.) So now I have definitions above paths.

@webron

This comment has been minimized.

Show comment
Hide comment
@webron

webron Aug 27, 2015

Member

Actually, the order is meaningless.

Member

webron commented Aug 27, 2015

Actually, the order is meaningless.

@rdrey

This comment has been minimized.

Show comment
Hide comment
@rdrey

rdrey 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

rdrey commented 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

@webron

This comment has been minimized.

Show comment
Hide comment
@webron

webron Aug 27, 2015

Member

That sounds like a parsing bug.

Member

webron commented Aug 27, 2015

That sounds like a parsing bug.

@rdrey

This comment has been minimized.

Show comment
Hide comment
@rdrey

rdrey Aug 27, 2015

Would you like a minimal example to repro in here? Or should I open a new issue?

rdrey commented Aug 27, 2015

Would you like a minimal example to repro in here? Or should I open a new issue?

@webron

This comment has been minimized.

Show comment
Hide comment
@webron

webron Aug 27, 2015

Member

It's got nothing to do with swagger-spec. I'm not sure which project is giving you the error, but if you want to report it, you should report it on the right one.

Member

webron commented Aug 27, 2015

It's got nothing to do with swagger-spec. I'm not sure which project is giving you the error, but if you want to report it, you should report it on the right one.

@rdrey

This comment has been minimized.

Show comment
Hide comment
@rdrey

rdrey Aug 27, 2015

Makes sense, sorry. Will report to Swagger Editor, but not sure which parser they use internally.

rdrey commented Aug 27, 2015

Makes sense, sorry. Will report to Swagger Editor, but not sure which parser they use internally.

@webron

This comment has been minimized.

Show comment
Hide comment
@webron

webron Aug 27, 2015

Member

Doesn't matter. @mohsen1 definitely knows more about it than me, so I could be mistaken, but better keep that information in swagger-editor. Thanks!

Member

webron commented Aug 27, 2015

Doesn't matter. @mohsen1 definitely knows more about it than me, so I could be mistaken, but better keep that information in swagger-editor. Thanks!

@gersongoulart

This comment has been minimized.

Show comment
Hide comment
@gersongoulart

gersongoulart Feb 16, 2016

+1 for this feature baked in Swagger. I think the "YAML reference" serves as good inspiration to how the Swagger schema could handle this... e.g.:

// (...)
"parameters": {
    "marketIds": {
        "name": "marketIds",
        "$ref": "#/definitions/idsParam"
    },
    "clientIds": {
        "name": "clientIds",
        "$ref": "#/definitions/idsParam"
    },
},
// (...)
"definitions": {
    "idsParam": {
        "in": "query",
        "required": false,
        "description": "One or more id integers as a comma delimited array",
        "type": "array",
        "items": {
              "type": "integer"
        }
},

gersongoulart commented Feb 16, 2016

+1 for this feature baked in Swagger. I think the "YAML reference" serves as good inspiration to how the Swagger schema could handle this... e.g.:

// (...)
"parameters": {
    "marketIds": {
        "name": "marketIds",
        "$ref": "#/definitions/idsParam"
    },
    "clientIds": {
        "name": "clientIds",
        "$ref": "#/definitions/idsParam"
    },
},
// (...)
"definitions": {
    "idsParam": {
        "in": "query",
        "required": false,
        "description": "One or more id integers as a comma delimited array",
        "type": "array",
        "items": {
              "type": "integer"
        }
},
@fehguy

This comment has been minimized.

Show comment
Hide comment
@fehguy

fehguy Feb 16, 2016

Contributor

Unfortunately $ref cannot have a peer in the json model, per JSON schema.

Contributor

fehguy commented Feb 16, 2016

Unfortunately $ref cannot have a peer in the json model, per JSON schema.

@webron

This comment has been minimized.

Show comment
Hide comment
@webron

webron Feb 21, 2016

Member

This is also covered by #301.

Parent issue: #565.

Member

webron commented Feb 21, 2016

This is also covered by #301.

Parent issue: #565.

@webron

This comment has been minimized.

Show comment
Hide comment
@webron

webron Jul 21, 2016

Member

Resolved with #654.

Member

webron commented Jul 21, 2016

Resolved with #654.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment