Skip to content

Instantly share code, notes, and snippets.

@adamaltman
Last active November 29, 2023 04:23
Show Gist options
  • Save adamaltman/338161349d47e4e95b6fa7ce5ae98481 to your computer and use it in GitHub Desktop.
Save adamaltman/338161349d47e4e95b6fa7ce5ae98481 to your computer and use it in GitHub Desktop.
Adds x-openai-isConsequential to GET operations of OpenAPI files. To use, register the decorator in a plugin.
module.exports = OpenAIConsequential;
/** @type {import('@redocly/cli').OasDecorator} */
function OpenAIConsequential() {
return {
PathItem(PathItem) {
if (PathItem['get']) {
PathItem['get']['x-openai-isConsequential'] = true;
}
}
}
};
@RomanHotsiy
Copy link

RomanHotsiy commented Nov 29, 2023

Can be simpler:

module.exports = OpenAIConsequential;

/** @type {import('@redocly/cli').OasDecorator} */
function OpenAIConsequential({title}) {
  return {
    PathItem(PathItem) {
      if (PathItem['get']) {
        PathItem['get']['x-openai-isConsequential'] = true;
      }
    }
  }
};

@adamaltman
Copy link
Author

Fixed in revision 3. 👍

@RomanHotsiy
Copy link

One file:

module.exports = {
  id: "openai-plugin",
  decorators: {
    oas3: {
      "is-consequential": OpenAIConsequential,
    },
  },
};

/** @type {import('@redocly/cli').OasDecorator} */
function OpenAIConsequential({title}) {
  return {
    PathItem(PathItem) {
      if (PathItem['get']) {
        PathItem['get']['x-openai-isConsequential'] = true;
      }
    }
  }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment