Skip to content

Latest commit

 

History

History
157 lines (124 loc) · 4.34 KB

File metadata and controls

157 lines (124 loc) · 4.34 KB

🇺🇸 English | 🇷🇺 Русский | 🇨🇳 中文

remove-parameter

Removes a parameter from an endpoint in the OpenAPI specification

Configuration

Parameter Description Example Typing Default
endpointDescriptor [required] Description of the endpoint from which to remove the parameter "GET /pets" string \ { path: string; method: string } -
parameterDescriptor [required] Description of the parameter to remove. In the in parameter, you can specify: "query", "path", "header", "cookie". {"name": "petId", "in": "path"} { name: string; in: "query" \ "path" \ "header" \ "cookie" } -

Configuration example:

module.exports = {
    pipeline: [
        // ... other rules
        {
            rule: "remove-parameter",
            config: {
                endpointDescriptor: "GET /pets/{petId}", // specify the endpoint from which to remove the parameter
                parameterDescriptor: {
                    name: "version", // specify the name of the parameter to be deleted
                    in: "query" // specify the parameter location (query parameter)
                }
            },
        }
        // ... other rules
    ]
}

If you need to modify multiple specifications, you can use this rule multiple times in the overall configuration pipeline.

Motivation

1. Need to remove an unused parameter from an endpoint to stop using it and remove it later

Practical example:

In the openapi.yaml file, the endpoint documentation looks like this:

paths:
  /pets/{petId}:
    get:
      summary: Get pet by ID
      parameters:
        - name: petId
          in: path
          required: true
          schema:
            type: string
        - name: version
          in: query
          required: false
          schema:
            type: string

Need to remove the unused parameter version.

In the configuration file openapi-modifier-config.js, add the remove-parameter rule:

module.exports = {
    pipeline: [
        {
            rule: "remove-parameter",
            config: {
                endpointDescriptor: "GET /pets/{petId}",
                parameterDescriptor: {
                    name: "version",
                    in: "query"
                }
            },
        }
    ]
}

After applying the rule, the openapi.yaml file looks like this:

paths:
  /pets/{petId}:
    get:
      summary: Get pet by ID
      parameters:
        - name: petId
          in: path
          required: true
          schema:
            type: string

2. Need to remove a common parameter that interferes with TypeScript type generation

Practical example:

In the openapi.yaml file, there is a component with a parameter:

components:
  parameters:
    ApiKeyHeader:
      name: X-API-Key
      in: header
      required: true
      schema:
        type: string

Need to remove the ApiKeyHeader parameter component.

In the configuration file openapi-modifier-config.js, add the remove-parameter rule:

module.exports = {
    pipeline: [
        {
            rule: "remove-parameter",
            config: {
                parameterDescriptor: {
                    name: "X-API-Key",
                    in: "header"
                }
            },
        }
    ]
}

After applying the rule, the openapi.yaml file looks like this:

components:
  parameters: {}

Important Notes

  • If the endpoint or parameter is not found, the rule outputs a warning and leaves the specification unchanged, for timely updating of the openapi-modifier configuration
  • The rule can be applied to parameters of any type (query, path, header, cookie)

Useful Links