OpenAPI document
OasOperation
An operation of the document: one method on one path, with its parameters, request body and responses. It is the subject of an operation generator.
parametershas only the operation's own parameters.toParamsadds those of its path item and resolves the references.- When
securityisundefined, the security of the document applies. An empty array means that the operation needs none.
Signature
import { OasOperation } from '@skmtc/core'
class OasOperation extends OasBaseConstructor
constructor
constructor(fields: OperationFields, context?: ParseContextType)Creates a new OasOperation instance from operation field data.
Operation field data from OpenAPI specification
Properties
Type identifier for OAS operation objects
The API path for this operation
The HTTP method for this operation
The parent path item containing this operation
Unique identifier for the operation
Brief summary of the operation
Tags for organizing operations in documentation
Detailed description of the operation
Parameters accepted by this operation
Request body specification for this operation
Response specifications mapped by status code
Security requirements for this operation
Whether this operation is deprecated
External documentation for this operation
OpenAPI specification extensions
Servers for this operation
Methods
toSuccessResponse
toSuccessResponse(): OasResponse | OasRef<'response'> | undefinedReturns the successful response definition for this operation.
Looks for the lowest numbered 2xx response code and returns its response definition.
Success response object or undefined if none found
toSuccessResponseCode
toSuccessResponseCode(): string | undefinedReturns the HTTP status code for the primary success response.
Finds the lowest numbered 2xx status code in the responses.
Success status code as string or undefined if none found
toRequestBody
toRequestBody<V>(
map: (args: ToRequestBodyMapArgs) => V,
mediaType?: string
): V | undefinedMaps the request body schema to a custom value using the provided mapping function.
Function to transform the request body schema and metadata
Media type to extract schema from, an exact lookup. Omitted: the media type OasRequestBody.toJsonContent picks.
Mapped value or undefined if no request body schema found
traverse
traverse(path: SchemaPath, mediaType?: string): OasSchema | OasRef<'schema'>Navigate into this operation's response or request body schema along an SchemaPath. The first segment selects the entry point - 'SuccessResponse' (the 2xx response body schema) or 'RequestBody' (the request body schema) - and the rest descend through object properties, array items, and union members, resolving $refs on the way. See traverseSchema.
Schema path; path[0] must be 'SuccessResponse' or 'RequestBody'.
Media type the body schema is read from, an exact lookup. Omitted: the JSON media type (application/json, else the first JSON-like type, else *\/*).
The schema at the path (may be an unresolved $ref).
Error on an unknown root, a missing response/request body, or a non-navigable segment.
toEffectiveParameters
toEffectiveParameters(): (OasParameter | OasRef<'parameter'>)[]The parameters that apply to this operation, as OpenAPI defines them: the path item's parameters apply to each of its operations, and an operation's own parameter with the same name and location replaces the path item's. The path item's come first.
References stay references, so a caller can resolve each one on its own. A reference that names nothing (kept when parse.danglingRefs lists parameter) keeps its place, and resolving it throws DanglingRefError. OasOperation.toParams resolves them all.
the parameters, path item's first
toParams
toParams(filter?: OasParameterLocation[]): OasParameter[]Resolve all parameters and optionally filter by location: the resolved OasOperation.toEffectiveParameters.
only include parameters from specified locations
when a parameter is a reference that names nothing
toParametersObject
toParametersObject(filter?: OasParameterLocation[]): OasObjectCreates an OAS object representation of operation parameters.
Optional array of parameter locations to include
OAS object with parameter properties
toJsonSchema
toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.OperationObjectConverts the operation to OpenAPI v3 JSON schema format.
Conversion options for nested components
OpenAPI v3 operation object
when a parameter is a reference that names nothing, as OasOperation.toParams does: there is no parameter to write, and the caller decides what to do
toJSON
toJSON(): objectSerializes the operation to a plain JavaScript object.
Plain object representation of the operation