JsonMethodStore
Usage
import { JsonMethodStore } from "@tsed/schema";Overview
class JsonMethodStore extends JsonEntityStore {
readonly parent: JsonClassStore;
middlewares: any[];
beforeMiddlewares: any[];
afterMiddlewares: any[];
readonly operation: JsonOperation;
readonly children: Map<string | number, JsonParameterStore>;
constructor(options: JsonEntityStoreOptions);
get params(): JsonParameterStore[];
get view(): JsonViewOptions;
set view(view: JsonViewOptions);
get acceptMimes(): string[];
set acceptMimes(mimes: string[]);
get parameters(): JsonParameterStore[];
get operationPaths(): Map<string, import("./JsonOperation.js").JsonMethodPath>;
get collectionType(): Type<any>;
set collectionType(type: Type<any>);
get isCollection(): boolean;
get schema(): JsonSchema;
static get(target: Type<any>, propertyKey: string | symbol, descriptor?: PropertyDescriptor): JsonMethodStore;
getResponseOptions(status: number, { contentType, includes }?: {
contentType?: string;
includes?: string[];
}): undefined | any;
before(args: Function[]): this;
after(args: Function[]): this;
use(args: Function[]): this;
get<T = any>(key: any): T;
getParamTypes(): Record<string, boolean>;
protected build(): void;
}Description
Store for method metadata, operations, and parameter information.
JsonMethodStore manages metadata for controller methods decorated with operation decorators like @Get(), @Post(), @Returns(), etc. It maintains the JsonOperation for OpenAPI generation and coordinates method parameters.
Responsibilities
- Operation Management: Maintains JsonOperation for OpenAPI spec generation
- Parameter Coordination: Manages child JsonParameterStore instances
- Middleware Configuration: Handles before/after/use middleware registration
- Response Configuration: Manages return types and status codes
- Route Information: Stores HTTP methods, paths, and route metadata
Usage
// Get method store
const methodStore = JsonEntityStore.from(MyController, "myMethod");
// Access operation for OpenAPI
const operation = methodStore.operation;
// Get parameters
const params = methodStore.parameters;
// Check response type
const returnType = methodStore.type;Operation Structure
Each method store contains a JsonOperation that includes:
- HTTP method and path information
- Request parameters (path, query, body, headers)
- Response definitions by status code
- Security requirements
- Tags and metadata
Parameter Management
The store maintains parameter metadata:
- Parameters stored in
childrenmap by index - Accessible via
parametersorparamsgetters - Each parameter has its own JsonParameterStore
Middleware Integration
Supports three middleware phases:
- before: Execute before the method
- use: Execute as main middleware
- after: Execute after the method
readonly parent
readonly parent: JsonClassStore;middlewares
middlewares: any[];beforeMiddlewares
beforeMiddlewares: any[];afterMiddlewares
afterMiddlewares: any[];readonly operation
readonly operation: JsonOperation;Ref to JsonOperation when the decorated object is a method.
readonly children
readonly children: Map<string | number, JsonParameterStore>;List of children JsonEntityStore (properties or methods or params)
get params
get params(): JsonParameterStore[];get view
get view(): JsonViewOptions;set view
set view(view: JsonViewOptions);get acceptMimes
get acceptMimes(): string[];set acceptMimes
set acceptMimes(mimes: string[]);get parameters
get parameters(): JsonParameterStore[];get operationPaths
get operationPaths(): Map<string, import("./JsonOperation.js").JsonMethodPath>;get collectionType
get collectionType(): Type<any>;set collectionType
set collectionType(type: Type<any>);get isCollection
get isCollection(): boolean;get schema
get schema(): JsonSchema;static get
static get(target: Type<any>, propertyKey: string | symbol, descriptor?: PropertyDescriptor): JsonMethodStore;Get an endpoint.
getResponseOptions
getResponseOptions(status: number, { contentType, includes }?: {
contentType?: string;
includes?: string[];
}): undefined | any;TODO must be located on JsonOperation level directly
before
before(args: Function[]): this;Append middlewares to the beforeMiddlewares list.
after
after(args: Function[]): this;Append middlewares to the afterMiddlewares list.
use
use(args: Function[]): this;Store all arguments collected via Annotation.
get
get<T = any>(key: any): T;Find the value at the controller level. Let this value be extended or overridden by the endpoint itself.
getParamTypes
getParamTypes(): Record<string, boolean>;protected build
protected build(): void;