redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

TypeExtension isn't available to configurable rules

Open lornajane opened this issue 1 year ago • 0 comments

Describe the bug

I used a custom plugin and added a new type to my type tree. I expected to be able to use the type as a subject in a configurable rule, but I get the error ``type can be one of the following only: "any", "Root", "Tag", "TagList", ... as if my new type isn't available. I think the type is correctly added because the spec rule picks up if the structure of the data isn't correct.

To Reproduce Steps to reproduce the behavior:

  1. With a custom plugin plugins/type-extension.js that contains the following code:
const XMetaData = {
  properties: {
    lifecycle: { type: 'string'},
    'owner-team': { type: 'string'},
  },
  required: ['lifecycle']
};

module.exports = {
  id: 'type-extension',
  typeExtension: {
    oas3(types) {
      newTypes = {
        ...types,
        XMetaData: XMetaData,
        Info: {
          ...types.Info,
          properties: {
            ...types.Info.properties,
            'x-metadata': 'XMetaData',
          }
        }
      };
      return newTypes;
    }
  }
};

  1. Given this redocly.yaml file
extends: []

plugins:
  - 'plugins/type-extension.js'

rules:
  spec: warn
  rule/metadata-lifecycle:
    subject:
      type: XMetaData
      property: lifecycle
    assertions:
      enum: ["alpha", "beta", "production", "deprecated"]
  1. And an OpenAPI file with this (snippet from the start of the file)
  x-metadata:
    lifecycle: production
    owner-team: Engineering/Integrations
  1. Run this command with these arguments... redocly lint openapi.yaml
  2. See error

Expected behavior

I want to be able to write a configurable rule that uses the new type.

Redocly Version(s)

1.0.0

Node.js Version(s) v16.20.0

lornajane avatar Aug 08 '23 13:08 lornajane