UNPKG

@tsed/schema

Version:
55 lines (54 loc) 1.98 kB
import { OpenSpecHash, OpenSpecRef, OS3Example, OS3Parameter } from "@tsed/openspec"; import { JsonSchemaOptions } from "../interfaces/JsonSchemaOptions.js"; import { JsonMap } from "./JsonMap.js"; import { JsonSchema } from "./JsonSchema.js"; /** * Represents an HTTP operation parameter for OpenAPI specifications. * * JsonParameter defines a single parameter for an HTTP operation, supporting * various parameter locations (path, query, header, body, files) and providing * a fluent API for building parameter metadata compatible with OpenAPI 3. * * ### Parameter Types * * - **path**: Parameter in the URL path (e.g., `/users/{id}`) * - **query**: Query string parameter (e.g., `?page=1`) * - **header**: HTTP header parameter * - **body**: Request body parameter * - **files**: File upload parameter * * ### Usage * * ```typescript * const param = new JsonParameter() * .name("userId") * .in("path") * .required(true) * .description("The user identifier") * .schema(JsonSchema.from(String)); * ``` * * ### Key Features * * - **Schema Integration**: Associated JSON schema for validation * - **Examples**: Support for parameter examples * - **Expression**: Custom parameter expressions for complex bindings * - **Validation**: Required/optional flags and schema constraints * * @public */ export declare class JsonParameter extends JsonMap<OS3Parameter<JsonSchema>> { $kind: string; expression: string; constructor(obj?: Partial<OS3Parameter<JsonSchema>>); getName(): any; name(name: string): this; examples(examples: OpenSpecHash<OS3Example | OpenSpecRef>): this; description(description: string): this; in(inType: string, expression?: string | any): this; required(required: boolean): this; schema(): JsonSchema; schema(schema: JsonSchema): this; itemSchema(schema?: JsonSchema): JsonSchema<import("json-schema").JSONSchema7Type>; toJSON(options?: JsonSchemaOptions): any; }