Constructors

Properties

OpenAPI document initial value, will be merged with the result of define method.

operationSchemas: Map<string, OperationSchemas> = ...

Internal save of original schemas, could be reused for valiation or other usages.

Methods

  • Define an operation for a path, save original schemas and transform the schemas into OpenAPI format.

    Parameters

    • path: `/${string}`

      API endpoint path, used as key in paths object.

    • method: HttpMethod

      HTTP method that this operation is for, will overwrite existing path item if it exists.

    • operationSchemas: OperationSchemas

      Schemas for this operation.

    • options: TransformPathItemOptions = {}

    Returns PathItemObject

    Generated path item object.

  • Stringify the document to JSON format.

    Returns string

    OpenAPI document string in JSON format.

  • Validate the data against the defined schemas. Only validate the schema if the key present in the data.

    Parameters

    • path: `/${string}`

      API endpoint path, used as key in paths object.

    • method: HttpMethod

      HTTP method that this operation is for, will overwrite existing path item if it exists.

    • data: Partial<Record<keyof OperationSchemas, unknown>>

      Data object to be validated. The key is the schema name. If the key is not present in the data, the schema will not be validated.

    • options: Options

      Options for Ajv instance.

    Returns Record<keyof OperationSchemas, undefined | null | ErrorObject<string, Record<string, any>, unknown>[]>

    Validation result of each schema.

  • Stringify the document to YAML format.

    Returns string

    OpenAPI document string in YAML format.