Redocly / Redocly/redocly-cli

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

Open
#2,504 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Enhancement
Dominant language
TypeScript
Stars
1.5k
Forks
228
Avg merge
1d 14h
Merged PRs (30d)
48

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with redocly.yaml, the preprocessor context, and the lint, bundle, preview-docs, and build-docs command entry points. Compare how --skip-preprocessor is applied today; done means users can limit a preprocessor to selected commands without repeating flags, with the supported behavior documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.