Skip to main content

HttpParameter

Package: @opra/common

HttpParameter represents a single declared parameter on an HttpController or HttpOperation. Parameters can be located in the query string, URL path, request headers, or cookies. The adapter decodes and validates each parameter against its declared type before calling the operation handler.


Inheritance

DocumentElement
└── Value
└── HttpParameter

Value contributes name, type, description, isArray, and examples.


Properties

Properties inherited from Value:

PropertyTypeDescription
namestring | RegExpParameter name, or a RegExp for pattern-based matching.
typeDataType | undefinedDeclared type used for decoding and validation.
descriptionstring | undefinedHuman-readable description.
isArrayboolean | undefinedWhether the parameter holds an array of values.
examplesany[] | Record<string, any> | undefinedExample values.

Properties on HttpParameter:

PropertyTypeDescription
location'query' | 'path' | 'header' | 'cookie'Where the parameter appears in the HTTP request.
requiredboolean | undefinedWhether the parameter must be present. Always true for 'path' parameters.
defaultanyDefault value applied when the parameter is absent.
arraySeparatorstring | undefinedSeparator used to split a comma-separated string into an array (e.g. ',').
keyParamboolean | undefinedMarks this parameter as the entity key parameter.
deprecatedboolean | string | undefinedMarks the parameter as deprecated.
parser((v: any) => any) | undefinedCustom parsing function applied after type decoding.

Methods

generateCodec(codec, options?)

Compiles a validator for this parameter's type. If a default value is declared, wraps the validator so the default is applied when the parameter is absent.

generateCodec(
codec: 'encode' | 'decode',
options?: DataType.GenerateCodecOptions
): Validator

toJSON(options?)

Returns an OpraSchema.HttpParameter plain object for schema export.

toJSON(options?: ApiDocument.ExportOptions): OpraSchema.HttpParameter

Accessing parameters at runtime

Parameters are not accessed directly via HttpParameter — the adapter decodes them before the handler is called. Inside a handler use HttpContext:

async get(ctx: HttpContext) {
const id = ctx.pathParams.customerId; // path parameter
const limit = ctx.queryParams.limit; // query parameter
const token = ctx.headers['authorization']; // header
}

To inspect parameter declarations programmatically:

const op = document.httpApi.findOperation('/customers', 'get');
for (const prm of op.parameters) {
console.log(prm.name, prm.location, prm.type?.name);
}

HttpController · HttpOperation