OpenAPI document
OasHeader
Represents a Header Object in the OpenAPI Specification.
The OasHeader class encapsulates the definition of a single HTTP header that can be sent with responses or expected in requests. Headers provide additional metadata about the HTTP message and can include authentication tokens, content information, pagination data, rate limiting details, and more.
This class provides comprehensive support for header definitions with typed values, validation schemas, examples, and documentation.
Signature
import { OasHeader } from '@skmtc/core'
class OasHeaderExamples
import { OasHeader, OasString } from '@skmtc/core';
const authHeader = new OasHeader({
description: 'Bearer token for API authentication',
required: true,
schema: new OasString({
pattern: '^Bearer [A-Za-z0-9+/=]+$',
description: 'JWT bearer token'
}),
examples: {
valid: new OasExample({
summary: 'Valid bearer token',
value: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
})
}
});Constructor
constructor
constructor(fields: HeaderFields)Properties
Brief description of header
Indicates if header is mandatory. Default value is false
Indicates if header is deprecated and should no longer be used. Default value is false
Examples of the header
Content of the header
Specification Extension fields
Methods
isRef
isRef(): this is OasRef<'header'>Returns true if object is a reference
isReadOnly
isReadOnly(): booleanAlways false: readOnly is a schema keyword.
isWriteOnly
isWriteOnly(): booleanAlways false: writeOnly is a schema keyword.
resolve
resolve(): OasHeaderReturns itself
resolveOnce
resolveOnce(): OasHeadertoSchema
toSchema(mediaType?: string): OasSchema | OasRef<'schema'>Returns schema for the header. Either, schema property if defined or value matching mediaType from content property. When content has exactly one entry (the spec requires one), its schema is used whatever the media type, as in OasParameter.toSchema.
Optional media type to get schema for, an exact lookup. Omitted: the JSON media type (application/json, else the first JSON-like type, else *\/*).
toJsonSchema
toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.HeaderObject