Skip to content

Latest commit

 

History

History

openai-is-consequential

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Decorator to add x-openai-isConsequential tag to GET operations

Authors:

What this does and why

OpenAI Actions uses OpenAPI to enable GPTs to make API calls.

It has support for a consequential flag (documentation no longer available, but originally at https://platform.openai.com/docs/actions/consequential-flag):

If the field isn't present, we default all GET operations to false and all other operations to true

If you want to set the GET operations to true too, then this decorator is for you.

Code

The code is entirely in openai-is-consequential.js:

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

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

The code sets the plugin name to openai-plugin and adds a decorator named is-consequential.

It operates on the PathItem element (in OpenAPI 3.x descriptions).

The conditional logic applies to get operations. Modify the if statement if you want to target different operations.

Examples

Add the plugin to redocly.yaml and enable the decorator:

plugins:
  - ./openai-is-consequential.js

decorators:
  openai-plugin/is-consequential: on

Here is an example of an operation before and after:

Before:

/aml-settings:
  get:
    summary: Retrieve AML settings
    operationId: GetAmlSettings
    x-sdk-operation-name: getAmlSettings
    description: Retrieves AML settings.
    responses:
      "200":
        description: AML settings retrieved.
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AmlSettings"
      "401":
        $ref: "#/components/responses/Unauthorized"
      "403":
        $ref: "#/components/responses/Forbidden"
      "404":
        $ref: "#/components/responses/NotFound"

After:

/aml-settings:
  get:
    summary: Retrieve AML settings
    operationId: GetAmlSettings
    x-sdk-operation-name: getAmlSettings
    description: Retrieves AML settings.
    responses:
      "200":
        description: AML settings retrieved.
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AmlSettings"
      "401":
        $ref: "#/components/responses/Unauthorized"
      "403":
        $ref: "#/components/responses/Forbidden"
      "404":
        $ref: "#/components/responses/NotFound"
    x-openai-isConsequential: true

🎉 Notice x-openai-isConsequential: true at the last line of the after example.

References