Skip to content

Latest commit

 

History

History
112 lines (86 loc) · 2.77 KB

File metadata and controls

112 lines (86 loc) · 2.77 KB

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

remove-max-items

Removes the maxItems property from all schemas in the OpenAPI specification.

Configuration

Parameter Description Example Type Default
showUnusedWarning [optional] Show a warning if no schemas with maxItems are found true boolean false

Configuration example:

module.exports = {
    pipeline: [
        // ... other rules
        {
            rule: "remove-max-items",
            config: {} // remove maxItems property from all schemas, don't show warnings
        }
        // ... other rules
    ]
}

Example of more detailed configuration:

module.exports = {
    pipeline: [
        // ... other rules
        {
            rule: "remove-max-items",
            config: {
                showUnusedWarning: true // show warning if no schemas with maxItems are found in the specification
            }
        }
        // ... 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 maxItems constraint from schemas for TypeScript type generation

In some cases, the maxItems constraint can interfere with code generation or create unnecessary checks. Removing this property makes the schema more flexible and universal.

Practical example:

In the openapi.yaml file, the schema looks like this:

components:
  schemas:
    Pet:
      type: object
      properties:
        tags:
          type: array
          maxItems: 10
          items:
            type: string

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

module.exports = {
    pipeline: [
        {
            rule: "remove-max-items",
            config: {
                showUnusedWarning: true
            },
        }
    ]
}

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

components:
  schemas:
    Pet:
      type: object
      properties:
        tags:
          type: array
          items:
            type: string

Important Notes

  • The rule does not affect schemas defined via references ($ref)
  • If showUnusedWarning is enabled, the rule will show a warning if no schemas with maxItems are found, to help keep the openapi-modifier configuration up to date

Useful Links