OpenAPI document
OasParameter
Represents a Parameter Object in the OpenAPI Specification.
The OasParameter class encapsulates the definition of a single operation parameter, including its location, data type, validation rules, and serialization behavior. Parameters can be located in the path, query string, headers, or cookies.
This class provides comprehensive support for parameter validation, serialization styles, and complex data types through schema definitions or content specifications.
Key Features
- Location Support: Path, query, header, and cookie parameters
- Schema Validation: Comprehensive data type validation through schemas
- Serialization Styles: Various parameter serialization formats
- Content Types: Support for complex parameter content with media types
- Examples & Documentation: Parameter examples and descriptive documentation
- Advanced Options: Empty values, reserved characters, and explode behavior
Signature
import { OasParameter } from '@skmtc/core'
class OasParameter extends OasBaseExamples
import { OasParameter, OasString } from '@skmtc/core';
const userIdParam = new OasParameter({
name: 'userId',
location: 'path',
description: 'Unique identifier for the user',
required: true,
schema: new OasString({
pattern: '^[0-9a-f]{24}$',
example: '507f1f77bcf86cd799439011'
}),
style: 'simple',
explode: false
});
// Used in path: /users/{userId}const pageSizeParam = new OasParameter({
name: 'pageSize',
location: 'query',
description: 'Number of items to return per page',
required: false,
schema: new OasInteger({
minimum: 1,
maximum: 100,
default: 20
}),
style: 'form',
explode: true,
examples: {
small: new OasExample({ value: 10 }),
medium: new OasExample({ value: 25 }),
large: new OasExample({ value: 50 })
}
});
// Used in query: ?pageSize=20const authHeaderParam = new OasParameter({
name: 'Authorization',
location: 'header',
description: 'Bearer token for authentication',
required: true,
schema: new OasString({
pattern: '^Bearer [A-Za-z0-9+/=]+$',
example: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
}),
style: 'simple',
explode: false
});const filterParam = new OasParameter({
name: 'filter',
location: 'query',
description: 'Complex filter object',
required: false,
content: {
'application/json': new OasMediaType({
schema: new OasObject({
properties: {
category: new OasString(),
priceRange: new OasObject({
properties: {
min: new OasNumber(),
max: new OasNumber()
}
})
}
})
})
},
style: 'deepObject',
explode: true
});
// Used as: ?filter[category]=electronics&filter[priceRange][min]=100const tagsParam = new OasParameter({
name: 'tags',
location: 'query',
description: 'Filter by multiple tags',
required: false,
schema: new OasArray({
items: new OasString(),
minItems: 1,
maxItems: 10
}),
style: 'form',
explode: true // Results in: ?tags=tech&tags=api&tags=rest
});
// Without explode: ?tags=tech,api,rest
// With explode: ?tags=tech&tags=api&tags=restconst sessionParam = new OasParameter({
name: 'sessionId',
location: 'cookie',
description: 'Session identifier cookie',
required: false,
schema: new OasString({
minLength: 32,
maxLength: 128
}),
style: 'form',
explode: false
});Constructor
constructor
constructor(fields: ParameterFields, context?: ParseContextType)Creates a new OasParameter instance.
Parameter configuration fields including name, location, schema, and serialization options
Properties
Type identifier for OAS parameter objects
The name of the parameter
Where the parameter is located (path, query, header, cookie)
A brief description of the parameter's purpose and usage
Determines whether this parameter is mandatory for the operation
Indicates that the parameter is deprecated and should be avoided
Whether to allow empty values for this parameter
Whether reserved characters are allowed in parameter values
The schema defining the parameter's data type and validation rules
Example values demonstrating parameter usage
Media type definitions for complex parameter content
The serialization style for the parameter (form, simple, etc.)
Whether to explode parameter values into separate key-value pairs
Custom extension fields (x-* properties) defined for this parameter
Methods
isRef
isRef(): this is OasRef<'parameter'>Determines if this parameter is a reference object.
Always false since this is a concrete parameter instance, not a reference
isReadOnly
isReadOnly(): booleanAlways false: readOnly is a schema keyword.
isWriteOnly
isWriteOnly(): booleanAlways false: writeOnly is a schema keyword.
resolve
resolve(): OasParameterResolves this parameter object.
The parameter instance itself since it's already a concrete object
resolveOnce
resolveOnce(): OasParameterResolves this parameter object one level.
The parameter instance itself since it's already a concrete object
toSchema
toSchema(mediaType?: string): OasSchema | OasRef<'schema'>Extracts the schema for this parameter.
Returns the direct schema if available, or extracts schema from content for the specified media type. When content has exactly one entry, its schema is used whatever the media type.
Media type to extract schema from when using content definitions, an exact lookup. Omitted: the JSON media type (application/json, else the first JSON-like type, else *\/*).
The parameter's schema object
Error if the parameter has neither schema nor content, or no schema is found for the specified media type
toJsonSchema
toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.ParameterObjectConverts this OAS parameter to an OpenAPI v3 JSON schema representation.
Conversion options including reference handling and formatting preferences
OpenAPI v3 parameter object with all properties and validation constraints