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:
| Property | Type | Description |
|---|---|---|
name | string | RegExp | Parameter name, or a RegExp for pattern-based matching. |
type | DataType | undefined | Declared type used for decoding and validation. |
description | string | undefined | Human-readable description. |
isArray | boolean | undefined | Whether the parameter holds an array of values. |
examples | any[] | Record<string, any> | undefined | Example values. |
Properties on HttpParameter:
| Property | Type | Description |
|---|---|---|
location | 'query' | 'path' | 'header' | 'cookie' | Where the parameter appears in the HTTP request. |
required | boolean | undefined | Whether the parameter must be present. Always true for 'path' parameters. |
default | any | Default value applied when the parameter is absent. |
arraySeparator | string | undefined | Separator used to split a comma-separated string into an array (e.g. ','). |
keyParam | boolean | undefined | Marks this parameter as the entity key parameter. |
deprecated | boolean | string | undefined | Marks the parameter as deprecated. |
parser | ((v: any) => any) | undefined | Custom 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);
}