Files
redocly-cli/docs/rules/no-invalid-parameter-examples.md
Adam Altman fcdd782d18 refactor: rename four types (#906)
Co-authored-by: Roman Hotsiy <gotsijroman@gmail.com>
2022-10-10 15:36:35 -05:00

2.5 KiB

no-invalid-parameter-examples

Disallow invalid parameter examples.

OAS Compatibility
2.0
3.0
3.1
flowchart TD

Root ==> Paths --> PathItem --> Operation --> Parameter --> Example
PathItem --> Parameter
Parameter --> Schema
Root ==> components

NamedParameter --> Parameter

Schema -.compares schema\nto example.- Example

subgraph components
NamedParameter
end


style Example fill:#codaf9,stroke:#0044d4,stroke-width:5px
style Schema fill:#codaf9,stroke:#0044d4,stroke-width:5px

API design principles

If your parameter schema and example conflict, there is a problem in the definition of the schema or the example. Solve it before you ship it.

Configuration

Option Type Description
severity string Possible values: off, warn, error. Default warn.
allowAdditionalProperties boolean Determines if additional properties are allowed in examples. Default false.
rules:
  no-invalid-parameter-examples:
    severity: error
    allowAdditionalProperties: false

Examples

Given the following configuration:

rules:
  no-invalid-parameter-examples:
    severity: error
    allowAdditionalProperties: false

Example of incorrect parameter example:

paths:
  /results:
    get:
      summary: Search Chess Results
      operationId: searchChessResult
      parameters:
        - name: username
          in: query
          schema:
            type: string
            maxLength: 15
          description: Value to query the chess results against usernames
          example: ThisUsernameIsTooLong

Example of correct parameter example:

paths:
  /results:
    get:
      summary: Search Chess Results
      operationId: searchChessResult
      parameters:
        - name: username
          in: query
          schema:
            type: string
            maxLength: 10
          description: Value to query the chess results against usernames
          example: ella

Resources