Skip to content

Commit

Permalink
Merge pull request #1049 from samchon/feature/migrate
Browse files Browse the repository at this point in the history
Close #1046: support ``@ApiProduces()` decorator of `@nestjs/swagger`
  • Loading branch information
samchon authored Sep 25, 2024
2 parents 6f9509a + 4ef7c71 commit 339b7ee
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"reflect-metadata": "^0.2.2",
"tgrid": "^1.0.3",
"tstl": "^3.0.0",
"typia": "^6.10.0"
"typia": "^6.10.4"
},
"devDependencies": {
"@types/autocannon": "^7.9.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@nestia/station",
"version": "3.14.0",
"version": "3.14.1",
"description": "Nestia station",
"scripts": {
"build": "node build/index.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/core",
"version": "3.14.0",
"version": "3.14.1",
"description": "Super-fast validation decorators of NestJS",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -36,7 +36,7 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/fetcher": "^3.14.0",
"@nestia/fetcher": "^3.14.1",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"@samchon/openapi": "^1.0.2",
Expand All @@ -53,7 +53,7 @@
"ws": "^7.5.3"
},
"peerDependencies": {
"@nestia/fetcher": ">=3.14.0",
"@nestia/fetcher": ">=3.14.1",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"reflect-metadata": ">=0.1.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/fetcher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/fetcher",
"version": "3.14.0",
"version": "3.14.1",
"description": "Fetcher library of Nestia SDK",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
10 changes: 5 additions & 5 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/sdk",
"version": "3.14.0",
"version": "3.14.1",
"description": "Nestia SDK and Swagger generator",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -32,8 +32,8 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/core": "^3.14.0",
"@nestia/fetcher": "^3.14.0",
"@nestia/core": "^3.14.1",
"@nestia/fetcher": "^3.14.1",
"@samchon/openapi": "^1.0.2",
"cli": "^1.0.1",
"get-function-location": "^2.0.0",
Expand All @@ -47,8 +47,8 @@
"typia": "^6.10.0"
},
"peerDependencies": {
"@nestia/core": ">=3.14.0",
"@nestia/fetcher": ">=3.14.0",
"@nestia/core": ">=3.14.1",
"@nestia/fetcher": ">=3.14.1",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"reflect-metadata": ">=0.1.12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ export namespace ReflectHttpOperationResponseAnalyzer {
function: ctx.function,
})
? "application/x-www-form-urlencoded"
: Reflect.getMetadata(HEADERS_METADATA, ctx.function)?.find(
: (Reflect.getMetadata(HEADERS_METADATA, ctx.function)?.find(
(h: Record<string, string>) =>
typeof h?.name === "string" &&
typeof h?.value === "string" &&
h.name.toLowerCase() === "content-type",
)?.value ?? (ctx.httpMethod === "HEAD" ? null : "application/json");
)?.value ??
Reflect.getMetadata("swagger/apiProduces", ctx.function)?.[0] ??
(ctx.httpMethod === "HEAD" ? null : "application/json"));

const schema =
contentType === "application/json"
Expand Down
3 changes: 2 additions & 1 deletion test/features/plain/src/controllers/PlainController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import core from "@nestia/core";
import { Controller, Header, Post } from "@nestjs/common";
import { ApiProduces } from "@nestjs/swagger";

@Controller("plain")
export class PlainController {
Expand All @@ -9,7 +10,7 @@ export class PlainController {
return body;
}

@Header("Content-Type", "text/plain")
@ApiProduces("text/plain")
@Post("template")
public async template(
@core.PlainBody()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const test_api_plan_template = async (
): Promise<void> => {
const x = "something_123_interesting_abc_is_not_true_it?";
const y: string = await api.functional.plain.template(connection, x);

TestValidator.equals("template")(x as string)(y);

// TestValidator.error("wrong template")(
Expand Down
2 changes: 1 addition & 1 deletion test/features/plain/swagger.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"openapi":"3.1.0","servers":[{"url":"https://github.com/samchon/nestia","description":"insert your server url"}],"info":{"version":"3.13.0-dev.2024910","title":"@samchon/nestia-test","description":"Test program of Nestia","license":{"name":"MIT"}},"paths":{"/health":{"get":{"tags":[],"parameters":[],"responses":{"200":{"description":"","content":{"application/json":{}}}}}},"/performance":{"get":{"tags":[],"parameters":[],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/IPerformance"}}}}}}},"/plain/string":{"post":{"tags":[],"parameters":[],"requestBody":{"content":{"text/plain":{"schema":{"type":"string"}}},"required":true},"responses":{"201":{"description":"","content":{"text/plain":{"schema":{"type":"string"}}}}}}},"/plain/template":{"post":{"tags":[],"parameters":[],"requestBody":{"content":{"text/plain":{"schema":{"type":"string","pattern":"^((something_[+-]?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?_interesting_(.*)_is_not_false_it\\?)|(something_[+-]?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?_interesting_(.*)_is_not_true_it\\?))$"}}},"required":true},"responses":{"201":{"description":"","content":{"text/plain":{"schema":{"type":"string"}}}}}}},"/plain/constant":{"post":{"tags":[],"parameters":[],"requestBody":{"content":{"text/plain":{"schema":{"oneOf":[{"const":"A"},{"const":"B"},{"const":"C"}]}}},"required":true},"responses":{"201":{"description":"","content":{"text/plain":{"schema":{"type":"string"}}}}}}}},"components":{"schemas":{"IPerformance":{"type":"object","properties":{"cpu":{"$ref":"#/components/schemas/process.global.NodeJS.CpuUsage"},"memory":{"$ref":"#/components/schemas/process.global.NodeJS.MemoryUsage"},"resource":{"$ref":"#/components/schemas/process.global.NodeJS.ResourceUsage"}},"required":["cpu","memory","resource"],"description":"Performance info."},"process.global.NodeJS.CpuUsage":{"type":"object","properties":{"user":{"type":"number"},"system":{"type":"number"}},"required":["user","system"]},"process.global.NodeJS.MemoryUsage":{"type":"object","properties":{"rss":{"type":"number"},"heapTotal":{"type":"number"},"heapUsed":{"type":"number"},"external":{"type":"number"},"arrayBuffers":{"type":"number"}},"required":["rss","heapTotal","heapUsed","external","arrayBuffers"]},"process.global.NodeJS.ResourceUsage":{"type":"object","properties":{"fsRead":{"type":"number"},"fsWrite":{"type":"number"},"involuntaryContextSwitches":{"type":"number"},"ipcReceived":{"type":"number"},"ipcSent":{"type":"number"},"majorPageFault":{"type":"number"},"maxRSS":{"type":"number"},"minorPageFault":{"type":"number"},"sharedMemorySize":{"type":"number"},"signalsCount":{"type":"number"},"swappedOut":{"type":"number"},"systemCPUTime":{"type":"number"},"unsharedDataSize":{"type":"number"},"unsharedStackSize":{"type":"number"},"userCPUTime":{"type":"number"},"voluntaryContextSwitches":{"type":"number"}},"required":["fsRead","fsWrite","involuntaryContextSwitches","ipcReceived","ipcSent","majorPageFault","maxRSS","minorPageFault","sharedMemorySize","signalsCount","swappedOut","systemCPUTime","unsharedDataSize","unsharedStackSize","userCPUTime","voluntaryContextSwitches"]}},"securitySchemes":{"bearer":{"type":"apiKey"}}},"tags":[],"x-samchon-emended":true}
{"openapi":"3.1.0","servers":[{"url":"https://github.com/samchon/nestia","description":"insert your server url"}],"info":{"version":"3.14.1-dev.20240925","title":"@samchon/nestia-test","description":"Test program of Nestia","license":{"name":"MIT"}},"paths":{"/health":{"get":{"tags":[],"parameters":[],"responses":{"200":{"description":"","content":{"application/json":{}}}}}},"/performance":{"get":{"tags":[],"parameters":[],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/IPerformance"}}}}}}},"/plain/string":{"post":{"tags":[],"parameters":[],"requestBody":{"content":{"text/plain":{"schema":{"type":"string"}}},"required":true},"responses":{"201":{"description":"","content":{"text/plain":{"schema":{"type":"string"}}}}}}},"/plain/template":{"post":{"tags":[],"parameters":[],"requestBody":{"content":{"text/plain":{"schema":{"type":"string","pattern":"^((something_[+-]?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?_interesting_(.*)_is_not_false_it\\?)|(something_[+-]?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?_interesting_(.*)_is_not_true_it\\?))$"}}},"required":true},"responses":{"201":{"description":"","content":{"text/plain":{"schema":{"type":"string"}}}}}}},"/plain/constant":{"post":{"tags":[],"parameters":[],"requestBody":{"content":{"text/plain":{"schema":{"oneOf":[{"const":"A"},{"const":"B"},{"const":"C"}]}}},"required":true},"responses":{"201":{"description":"","content":{"text/plain":{"schema":{"type":"string"}}}}}}}},"components":{"schemas":{"IPerformance":{"type":"object","properties":{"cpu":{"$ref":"#/components/schemas/process.global.NodeJS.CpuUsage"},"memory":{"$ref":"#/components/schemas/process.global.NodeJS.MemoryUsage"},"resource":{"$ref":"#/components/schemas/process.global.NodeJS.ResourceUsage"}},"required":["cpu","memory","resource"],"description":"Performance info."},"process.global.NodeJS.CpuUsage":{"type":"object","properties":{"user":{"type":"number"},"system":{"type":"number"}},"required":["user","system"]},"process.global.NodeJS.MemoryUsage":{"type":"object","properties":{"rss":{"type":"number"},"heapTotal":{"type":"number"},"heapUsed":{"type":"number"},"external":{"type":"number"},"arrayBuffers":{"type":"number"}},"required":["rss","heapTotal","heapUsed","external","arrayBuffers"]},"process.global.NodeJS.ResourceUsage":{"type":"object","properties":{"fsRead":{"type":"number"},"fsWrite":{"type":"number"},"involuntaryContextSwitches":{"type":"number"},"ipcReceived":{"type":"number"},"ipcSent":{"type":"number"},"majorPageFault":{"type":"number"},"maxRSS":{"type":"number"},"minorPageFault":{"type":"number"},"sharedMemorySize":{"type":"number"},"signalsCount":{"type":"number"},"swappedOut":{"type":"number"},"systemCPUTime":{"type":"number"},"unsharedDataSize":{"type":"number"},"unsharedStackSize":{"type":"number"},"userCPUTime":{"type":"number"},"voluntaryContextSwitches":{"type":"number"}},"required":["fsRead","fsWrite","involuntaryContextSwitches","ipcReceived","ipcSent","majorPageFault","maxRSS","minorPageFault","sharedMemorySize","signalsCount","swappedOut","systemCPUTime","unsharedDataSize","unsharedStackSize","userCPUTime","voluntaryContextSwitches"]}},"securitySchemes":{"bearer":{"type":"apiKey"}}},"tags":[],"x-samchon-emended":true}
8 changes: 4 additions & 4 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@samchon/nestia-test",
"version": "3.14.0",
"version": "3.14.1",
"description": "Test program of Nestia",
"main": "index.js",
"scripts": {
Expand All @@ -26,7 +26,7 @@
},
"homepage": "https://nestia.io",
"devDependencies": {
"@nestia/sdk": "^3.14.0",
"@nestia/sdk": "^3.14.1",
"@nestjs/swagger": "^7.4.2",
"@samchon/openapi": "^1.0.3",
"@types/express": "^4.17.17",
Expand All @@ -40,9 +40,9 @@
},
"dependencies": {
"@fastify/multipart": "^8.1.0",
"@nestia/core": "^3.14.0",
"@nestia/core": "^3.14.1",
"@nestia/e2e": "^0.7.0",
"@nestia/fetcher": "^3.14.0",
"@nestia/fetcher": "^3.14.1",
"@nestjs/common": "^10.4.4",
"@nestjs/core": "^10.4.4",
"@nestjs/platform-express": "^10.4.4",
Expand Down

0 comments on commit 339b7ee

Please sign in to comment.