@opra/common
Version:
Opra common package
89 lines (88 loc) • 3.81 kB
TypeScript
import type { Combine, StrictOmit, ThunkAsync, Type } from 'ts-gems';
import { OpraSchema } from '../../schema/index.js';
import type { ApiDocument } from '../api-document';
import { DataTypeMap } from '../common/data-type-map.js';
import { DocumentElement } from '../common/document-element.js';
import type { DataType } from '../data-type/data-type.js';
import type { EnumType } from '../data-type/enum-type.js';
import { type HttpOperationDecorator } from '../decorators/http-operation.decorator.js';
import type { HttpController } from './http-controller.js';
import type { HttpOperationResponse } from './http-operation-response.js';
import type { HttpParameter } from './http-parameter.js';
import type { HttpRequestBody } from './http-request-body.js';
/**
* @namespace HttpOperation
*/
export declare namespace HttpOperation {
interface Metadata extends Pick<OpraSchema.HttpOperation, 'description' | 'method' | 'path' | 'mergePath' | 'composition' | 'compositionOptions'> {
types?: ThunkAsync<Type | EnumType.EnumObject | EnumType.EnumArray>[];
parameters?: HttpParameter.Metadata[];
responses?: HttpOperationResponse.Metadata[];
requestBody?: HttpRequestBody.Metadata;
immediateFetch?: boolean;
allowPatchOperators?: boolean;
}
interface Options extends Partial<Pick<Metadata, 'path' | 'mergePath' | 'description' | 'method' | 'immediateFetch' | 'allowPatchOperators'>> {
requestBody?: HttpRequestBody.Options;
}
interface InitArguments extends Combine<{
name: string;
types?: DataType[];
}, Pick<Metadata, 'description' | 'method' | 'path' | 'mergePath' | 'composition' | 'compositionOptions' | 'immediateFetch' | 'allowPatchOperators'>> {
}
}
/**
* Type definition for HttpOperation
* @class HttpOperation
*/
export interface HttpOperationStatic {
/**
* Class constructor of HttpOperation
* @param controller
* @param args
*/
new (controller: HttpController, args: HttpOperation.InitArguments): HttpOperation;
/**
* Property decorator
* @param options
*/ <T extends HttpOperation.Options>(options?: T): HttpOperationDecorator;
prototype: HttpOperation;
GET(options?: StrictOmit<HttpOperation.Options, 'method'>): HttpOperationDecorator;
DELETE(options?: StrictOmit<HttpOperation.Options, 'method'>): HttpOperationDecorator;
HEAD(options?: StrictOmit<HttpOperation.Options, 'method'>): HttpOperationDecorator;
OPTIONS(options?: StrictOmit<HttpOperation.Options, 'method'>): HttpOperationDecorator;
PATCH(options?: StrictOmit<HttpOperation.Options, 'method'>): HttpOperationDecorator;
POST(options?: StrictOmit<HttpOperation.Options, 'method'>): HttpOperationDecorator;
PUT(options?: StrictOmit<HttpOperation.Options, 'method'>): HttpOperationDecorator;
SEARCH(options?: StrictOmit<HttpOperation.Options, 'method'>): HttpOperationDecorator;
}
/**
* @class HttpOperation
*/
export interface HttpOperation extends HttpOperationClass {
}
/**
* HttpOperation
*/
export declare const HttpOperation: HttpOperationStatic;
/**
* @class HttpOperation
*/
declare class HttpOperationClass extends DocumentElement {
readonly owner: HttpController;
readonly name: string;
method: OpraSchema.HttpMethod;
description?: string;
path?: string;
mergePath?: boolean;
types: DataTypeMap;
parameters: HttpParameter[];
responses: HttpOperationResponse[];
requestBody?: HttpRequestBody;
composition?: string;
compositionOptions?: Record<string, any>;
findParameter(paramName: string, location?: OpraSchema.HttpParameterLocation): HttpParameter | undefined;
getFullUrl(): string;
toJSON(options?: ApiDocument.ExportOptions): OpraSchema.HttpOperation;
}
export {};