Skip to content

Support command-specific preprocessor execution (lint vs bundle vs docs) #2504

@vscaiceanu-1a

Description

@vscaiceanu-1a

Is your feature request related to a problem? Please describe.

As a user developing custom preprocessors for Redocly CLI, I need the ability to run preprocessors only for specific commands (e.g., only during lint, but not during bundle, preview-docs, or build-docs).

Currently, preprocessors defined in redocly.yaml run for all commands that support them. The only way to skip a preprocessor is using the --skip-preprocessor CLI flag, which requires:

  • Remembering to add the flag to every command where you don't want the preprocessor
  • Maintaining this across multiple npm scripts and CI/CD pipelines
  • An opt-out approach instead of opt-in

Use case

I've created a custom preprocessor that filters/modifies schemas from specific paths (e.g., auto-generated files, external vendor schemas, legacy code). This preprocessing is useful only during linting because:

  • During bundle: I want the original schemas preserved in the bundled output
  • During preview-docs/build-docs: I want the full documentation generated, not filtered content
  • During lint: I want to skip validation for specific paths

Current workaround

# Must add --skip-preprocessor to every non-lint command
redocly lint                                                    # preprocessor runs
redocly bundle --skip-preprocessor=my-plugin/my-preprocessor
redocly preview-docs --skip-preprocessor=my-plugin/my-preprocessor
redocly build-docs --skip-preprocessor=my-plugin/my-preprocessor

This is error-prone and requires coordination across teams and CI/CD pipelines.

Describe the solution you'd like

I'd like to understand what options are available to solve this problem:

  1. Is the current command already available in the preprocessor context? If so, documentation on how to access it would solve this issue.

  2. If not available, could command context be added? For example:

    export const myPreprocessor: Oas3Preprocessor = (options) => {
      return {
        Schema: {
          leave: (schema, ctx) => {
            // Check which command is running
            if (ctx.command !== 'lint') {
              return; // Skip for non-lint commands
            }
            // ... preprocessor logic
          }
        }
      };
    };
  3. Alternatively, could command-specific preprocessor configuration be added to redocly.yaml? For example:

    preprocessors:
      my-plugin/my-preprocessor:
        pathPatterns: ['**/generated/**']
        commands: ['lint']  # Only run for lint command

Describe alternatives you've considered

  1. CLI flags with npm scripts - Current workaround, but requires maintenance and is error-prone
  2. Separate config file for linting - Creates duplication and maintenance overhead

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions