Skip to content
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

sort - order request parameters by name #82

Open
ed-randall-blk opened this issue Jul 7, 2023 · 5 comments
Open

sort - order request parameters by name #82

ed-randall-blk opened this issue Jul 7, 2023 · 5 comments
Assignees
Labels
awaiting feedback enhancement New feature or request

Comments

@ed-randall-blk
Copy link

ed-randall-blk commented Jul 7, 2023

I couldn't figure out how to do this.
I need the get, post etc. request parameters to be ordered by the value of the name field.
The parameter fields themselves are ordered consistently according to the config but I'd like the the parameter ordering itself to be alphabetical.

    "/api/products": {
      "get": {
        "summary": "Get the list of existing products.",
        "parameters": [
          {
            "name": "offset",    _this should be the second one_
            "in": "query",
            "description": "The offset to apply to the paginated query.",
            "required": false,
            "default": 0,
            "format": "int32",
            "minimum": 0,
            "type": "integer"
          },
          {
            "name": "limit",        _l comes before o, this should be the first one_
            "in": "query",
            "description": "The limit to apply to the paginated query.",
            "required": false,
            "default": null,
            "format": "int32",
            "maximum": 100,
            "minimum": 0,
            "type": "integer",
            "x-nullable": true
          }
        ],
@thim81
Copy link
Owner

thim81 commented Jul 9, 2023

hi @ed-randall-blk

Usually the parameters are used as $ref to be re-used, so this is an interesting case, I'll have to investigate the behaviour of inline parameters.

@thim81
Copy link
Owner

thim81 commented Sep 17, 2023

hi @ed-randall-blk

I have a PR ready for this, but I wonder if people expect this to be sorted or rather want to keep it in the order that they defined it? Since it might be linked to a priority related to the business rules?

Example before:

  '/pet/{petId}/uploadImage':
    post:
      operationId: uploadFile
      summary: uploads an image
      description: ''
      parameters:
        - required: true
          schema:
            type: integer
            format: int64
          name: petId
          in: path
          description: ID of pet to update
        - required: false
          schema:
            type: string
          name: additionalMetadata
          in: query
          description: Additional Metadata
  /user/login:
    get:
      parameters:
        - required: false
          schema:
            type: string
          name: username
          in: query
          description: The user name for login
        - required: false
          schema:
            type: string
          name: password
          in: query
          description: The password for login in clear text

Example after:

  '/pet/{petId}/uploadImage':
    post:
      operationId: uploadFile
      summary: uploads an image
      description: ''
      parameters:
        - required: false
          schema:
            type: string
          name: additionalMetadata
          in: query
          description: Additional Metadata
        - required: true
          schema:
            type: integer
            format: int64
          name: petId
          in: path
          description: ID of pet to update
  /user/login:
    get:
      parameters:
        - required: false
          schema:
            type: string
          name: password
          in: query
          description: The password for login in clear text
        - required: false
          schema:
            type: string
          name: username
          in: query
          description: The user name for login

@thim81 thim81 added enhancement New feature or request awaiting feedback and removed Investigate labels Sep 17, 2023
@thim81
Copy link
Owner

thim81 commented Oct 29, 2023

hi @ed-randall-blk

Did you had some time to review the PR and the question above?

@edrandall
Copy link

Hi - thanks!

Ours swagger.json is generated from either golang protoc or Python ApiSpec hence why I think we don't see the $ref.
But the generating is not always consistently ordered - hence we want this tool so that the diff shows true diffs without any noise.

Really our main use-case then is a cross-check reviewing the changes vs the previous version before installing the swagger.json into Apigee. No business rule ordering as such. But in any case this sort would be the up to the end-user right, depending on whether they choose to configure it this way, or not. No-one is forced into anything they don't want.

@thim81
Copy link
Owner

thim81 commented Aug 1, 2024

@ed-randall-blk @edrandall It has been a while, but is there still a need to be able to sort header & param items by alphabet?

We are introducing the option to sort Paths, in a similar config we could provide the option controlling the header & param items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting feedback enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants