Skip to content

Commit

Permalink
Merge pull request #33 from samchon/features/media
Browse files Browse the repository at this point in the history
Add `IMigrateRoute.IBody.media()` and some utility property functions.
  • Loading branch information
samchon authored Jul 12, 2024
2 parents 55f41e6 + 0a64e95 commit 4c5bf06
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@samchon/openapi",
"version": "0.4.1",
"version": "0.4.2",
"description": "OpenAPI definitions and converters for 'typia' and 'nestia'.",
"main": "./lib/index.js",
"module": "./lib/index.mjs",
Expand All @@ -16,6 +16,8 @@
"keywords": [
"swagger",
"openapi",
"converter",
"migrate",
"typia",
"nestia"
],
Expand Down
16 changes: 16 additions & 0 deletions src/IMigrateRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export interface IMigrateRoute<

/**
* List of path parameters.
*
* Note that, not a list of every parameters, but only path parameters.
*/
parameters: IMigrateRoute.IParameter<Schema>[];

Expand Down Expand Up @@ -224,6 +226,8 @@ export namespace IMigrateRoute {
schema: Schema;
title: () => string | undefined;
description: () => string | undefined;
example: () => any | undefined;
examples: () => Record<string, any> | undefined;
}

/**
Expand All @@ -237,6 +241,8 @@ export namespace IMigrateRoute {
schema: Schema;
title: () => string | undefined;
description: () => string | undefined;
example: () => any | undefined;
examples: () => Record<string, any> | undefined;
}

/**
Expand Down Expand Up @@ -274,6 +280,11 @@ export namespace IMigrateRoute {
*/
description: () => string | undefined;

/**
* Media type of the request/response body.
*/
media: () => OpenApi.IOperation.IMediaType<Schema>;

/**
* Whether the body is encrypted or not.
*/
Expand All @@ -295,5 +306,10 @@ export namespace IMigrateRoute {
* Description comment for the exception.
*/
response: () => OpenApi.IOperation.IResponse<Schema>;

/**
* Media type of the response body.
*/
media: () => OpenApi.IOperation.IMediaType<Schema>;
}
}
4 changes: 2 additions & 2 deletions src/OpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,18 +506,18 @@ export namespace OpenApi {
* Request body of the operation.
*/
export interface IRequestBody<Schema extends IJsonSchema = IJsonSchema> {
content?: IContent<Schema>;
description?: string;
required?: boolean;
content?: IContent<Schema>;
"x-nestia-encrypted"?: boolean;
}

/**
* Response of the operation.
*/
export interface IResponse<Schema extends IJsonSchema = IJsonSchema> {
content?: IContent<Schema>;
headers?: Record<string, IOperation.IParameter<Schema>>;
content?: IContent<Schema>;
description?: string;
"x-nestia-encrypted"?: boolean;
}
Expand Down
11 changes: 10 additions & 1 deletion src/internal/MigrateRouteConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,17 @@ export namespace MigrateRouteConverter {
schema: OpenApi.IJsonSchema;
title?: string;
description?: string;
example?: any;
examples?: Record<string, any>;
}) =>
({
...elem,
name: type,
key: type,
title: () => elem.title,
description: () => elem.description,
example: () => elem.example,
examples: () => elem.examples,
}) satisfies IMigrateRoute.IHeaders;

if (objects.length === 1 && primitives.length === 0)
Expand Down Expand Up @@ -269,6 +273,7 @@ export namespace MigrateRouteConverter {
{
schema: response.content?.["application/json"]?.schema ?? {},
response: () => response,
media: () => response.content?.["application/json"] ?? {},
},
]),
),
Expand Down Expand Up @@ -373,8 +378,9 @@ export namespace MigrateRouteConverter {
? schema
: emplacer(schema)
: {},
"x-nestia-encrypted": meta["x-nestia-encrypted"],
description: () => meta.description,
media: () => json[1],
"x-nestia-encrypted": meta["x-nestia-encrypted"],
};
}

Expand All @@ -393,6 +399,7 @@ export namespace MigrateRouteConverter {
: emplacer(schema)
: {},
description: () => meta.description,
media: () => query[1],
};
}

Expand All @@ -404,6 +411,7 @@ export namespace MigrateRouteConverter {
key: "body",
schema: { type: "string" },
description: () => meta.description,
media: () => text[1],
};

if (from === "request") {
Expand All @@ -422,6 +430,7 @@ export namespace MigrateRouteConverter {
: emplacer(schema)
: {},
description: () => meta.description,
media: () => multipart[1],
};
}
}
Expand Down

0 comments on commit 4c5bf06

Please sign in to comment.