Skip to content

Commit

Permalink
Make OpenApi.IDocument to be generic.
Browse files Browse the repository at this point in the history
To support dependent libraries utilizing `@samchon/openapi` which adds special plugin properties starting with `x-` key name, changed `OpenApi.IDocument` and its subsidiary structures to have two generic arguments: `Schema` and `Operation`.

  - `OpenApi.IDocument<Schema, Operation>`
  - `OpenApi.IOperation<Schema>`
  • Loading branch information
samchon committed Jul 3, 2024
1 parent 3bbdca0 commit f832014
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 126 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@samchon/openapi",
"version": "0.2.2",
"version": "0.3.0-dev.20240703",
"description": "OpenAPI definitions and converters for 'typia' and 'nestia'.",
"main": "./lib/index.js",
"typings": "./lib/index.d.ts",
Expand Down
16 changes: 11 additions & 5 deletions src/IMigrateDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,32 @@ import { OpenApi } from "./OpenApi";
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface IMigrateDocument {
export interface IMigrateDocument<
Schema extends OpenApi.IJsonSchema = OpenApi.IJsonSchema,
Operation extends OpenApi.IOperation<Schema> = OpenApi.IOperation<Schema>,
> {
/**
* List of routes for migration.
*/
routes: IMigrateRoute[];
routes: IMigrateRoute<Schema, Operation>[];

/**
* List of errors occurred during the migration.
*/
errors: IMigrateDocument.IError[];
errors: IMigrateDocument.IError<Operation>[];
}
export namespace IMigrateDocument {
/**
* Error of migration in the operation level.
*/
export interface IError {
export interface IError<
Operation extends
OpenApi.IOperation<any> = OpenApi.IOperation<OpenApi.IJsonSchema>,
> {
/**
* Target operation causing the error.
*/
operation: () => OpenApi.IOperation;
operation: () => Operation;

/**
* Method of the operation.
Expand Down
51 changes: 32 additions & 19 deletions src/IMigrateRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { OpenApi } from "./OpenApi";
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface IMigrateRoute {
export interface IMigrateRoute<
Schema extends OpenApi.IJsonSchema = OpenApi.IJsonSchema,
Operation extends OpenApi.IOperation<Schema> = OpenApi.IOperation<Schema>,
> {
/**
* Method of the route.
*
Expand Down Expand Up @@ -61,7 +64,7 @@ export interface IMigrateRoute {
* the reason why the `delete` is a reserved keyword in many programming
* languages.
*
* - Exxample 1
* - Example 1
* - path: `POST /shopping/sellers/sales`
* - accessor: `shopping.sellers.sales.post`
* - Example 2
Expand All @@ -73,7 +76,7 @@ export interface IMigrateRoute {
/**
* List of path parameters.
*/
parameters: IMigrateRoute.IParameter[];
parameters: IMigrateRoute.IParameter<Schema>[];

/**
* Metadata of headers.
Expand All @@ -90,7 +93,7 @@ export interface IMigrateRoute {
* forcibly, its property {@link IMigrateRoute.IHeaders.name name} and
* {@link IMigrateRoute.IHeaders.key key} are always "headers".
*/
headers: IMigrateRoute.IHeaders | null;
headers: IMigrateRoute.IHeaders<Schema> | null;

/**
* Metadata of query values.
Expand All @@ -107,7 +110,7 @@ export interface IMigrateRoute {
* forcibly, its property {@link IMigrateRoute.IQuery.name name} and
* {@link IMigrateRoute.IQuery.key key} are always "headers".
*/
query: IMigrateRoute.IQuery | null;
query: IMigrateRoute.IQuery<Schema> | null;

/**
* Metadata of request body.
Expand All @@ -118,7 +121,7 @@ export interface IMigrateRoute {
* If the `body` property is `null`, it means the operation does not require
* the request body data.
*/
body: IMigrateRoute.IBody | null;
body: IMigrateRoute.IBody<Schema> | null;

/**
* Metadata of response body for success case.
Expand All @@ -129,7 +132,7 @@ export interface IMigrateRoute {
* If the `success` property is `null`, it means the operation does not have
* the response body data. In other words, the RPC function would return `void`.
*/
success: IMigrateRoute.IBody | null;
success: IMigrateRoute.IBody<Schema> | null;

/**
* Metadata of response body for exceptional status cases.
Expand All @@ -142,7 +145,7 @@ export interface IMigrateRoute {
* stringified number, but sometimes it could be a string like "default",
* because the OpenAPI document allows the status code to be a string.
*/
exceptions: Record<string, IMigrateRoute.IException>;
exceptions: Record<string, IMigrateRoute.IException<Schema>>;

/**
* Description comment for the route function.
Expand All @@ -166,38 +169,48 @@ export interface IMigrateRoute {
* The `operation` is a function returning the original
* {@link OpenApi.IOperation} from the {@link OpenAPI} document.
*/
operation: () => OpenApi.IOperation;
operation: () => Operation;
}
export namespace IMigrateRoute {
export interface IParameter {
export interface IParameter<
Schema extends OpenApi.IJsonSchema = OpenApi.IJsonSchema,
> {
name: string;
key: string;
schema: OpenApi.IJsonSchema;
schema: Schema;
description?: string;
}
export interface IHeaders {
export interface IHeaders<
Schema extends OpenApi.IJsonSchema = OpenApi.IJsonSchema,
> {
name: string; // headers
key: string; // headers
schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;
schema: Schema;
}
export interface IQuery {
export interface IQuery<
Schema extends OpenApi.IJsonSchema = OpenApi.IJsonSchema,
> {
name: string;
key: string;
schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;
schema: Schema;
}
export interface IBody {
export interface IBody<
Schema extends OpenApi.IJsonSchema = OpenApi.IJsonSchema,
> {
name: string;
key: string;
type:
| "text/plain"
| "application/json"
| "application/x-www-form-urlencoded"
| "multipart/form-data";
schema: OpenApi.IJsonSchema;
schema: Schema;
"x-nestia-encrypted"?: boolean;
}
export interface IException {
export interface IException<
Schema extends OpenApi.IJsonSchema = OpenApi.IJsonSchema,
> {
description?: string;
schema: OpenApi.IJsonSchema;
schema: Schema;
}
}
Loading

0 comments on commit f832014

Please sign in to comment.