Redocly / redoc

đŸ“˜ OpenAPI/Swagger-generated API Reference Documentation
https://redocly.github.io/redoc/
MIT License
22.89k stars 2.27k forks source link

Decorators not running with build-docs but do in docs-preview #2486

Closed Apoorva64 closed 5 months ago

Apoorva64 commented 5 months ago

Describe the bug I have an OpenApi with a lot of exemples. I wrote a decorator plugin to remove all the exemples from the specification. When i build the docs with "build-docs" the plugin does not run. When i preview the docs with "docs-preview" the plugin runs. Expected behavior The plugin should run in both cases

Minimal reproducible OpenAPI snippet(if possible)

openapi: 3.0.3
info:
  version: 1.1.0
  title: Pet API

security: []

paths:
  /pet/{petId}:
    get:
      summary: Gets the Pet from petId
      operationId: getPet
      parameters:
        - name: petId
          in: path
          required: true
          schema:
            type: integer
          examples:
            DEX:
              description: Dex est un chien qui aime jouer
              value: 0
            EDDY:
              description: Eddy est un chien qui n'aime pas jouer
              value: 1
      responses:
        "200":
          description: successful operation
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pet"

              examples:
                DEX:
                  description: RĂ©ponse 200 OK pour Dex
                  value: 
                    {
                      "id": 0,
                      "name": "Dex"
                    }
                EDDY:
                  description: RĂ©ponse 200 OK pour Eddy
                  value: 
                    {
                      "id": 1,
                      "name": "Eddy"
                    }
        "404":
          description: Pet not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
components:
  schemas:
    Pet:
      required:
        - name
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
    Error:
      required:
        - description
      type: object
      properties:
        description:
          type: string

plugin

function removeExamples() {
    return {
        any: {
            leave(target) {
                if (target.examples) {
                    target.examples = {};
                }
                if (target.example) {
                    delete target.example;
                }

            },
        },
    };
}

module.exports = {
    id: 'remove-examples',
    decorators: {
        oas3: {
            'remove-examples': removeExamples,
        },
    },
};

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.