Skip to content

Commit

Permalink
Merge pull request #869 from samchon/features/openapi
Browse files Browse the repository at this point in the history
Enhance `@nestia/migrate` for invalid path parameterized.
  • Loading branch information
samchon authored Apr 12, 2024
2 parents 8f5d6b5 + c6bff54 commit fe37838
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 1,334 deletions.
4 changes: 3 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ updates:
versioning-strategy: increase
open-pull-requests-limit: 25
allow:
- dependency-name: "@samchon/openapi"
- dependency-name: "@nestjs/*"
- dependency-name: "tstl"
- dependency-name: "typia"
- dependency-name: "@nestjs/*"
- dependency-name: ts-node
- dependency-name: ts-patch
- dependency-name: typescript
Expand All @@ -19,6 +20,7 @@ updates:
- "@nestjs/*"
Samchon:
patterns:
- "@samchon/openapi"
- "tstl"
- "typia"
TypeScript:
Expand Down
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/core": "^2.6.3",
"typia": "^6.0.0"
"typia": "^6.0.1"
},
"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.0.0",
"version": "3.0.1",
"description": "Nestia station",
"main": "prettier.config.js",
"scripts": {
Expand Down
16 changes: 8 additions & 8 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/core",
"version": "3.0.0",
"version": "3.0.1",
"description": "Super-fast validation decorators of NestJS",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -36,25 +36,25 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/fetcher": "^3.0.0",
"@nestia/fetcher": "^3.0.1",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"@samchon/openapi": "^0.1.2",
"@samchon/openapi": "^0.1.5",
"detect-ts-node": "^1.0.5",
"glob": "^7.2.0",
"multer": "1.4.5-lts.1",
"raw-body": "^2.0.0",
"reflect-metadata": ">=0.1.12",
"rxjs": ">=6.0.0",
"typia": "^6.0.0"
"rxjs": ">=6.0.1",
"typia": "^6.0.1"
},
"peerDependencies": {
"@nestia/fetcher": ">=3.0.0",
"@nestia/fetcher": ">=3.0.1",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"reflect-metadata": ">=0.1.12",
"rxjs": ">=6.0.0",
"typia": ">=6.0.0 <7.0.0"
"rxjs": ">=6.0.1",
"typia": ">=6.0.1 <7.0.0"
},
"devDependencies": {
"@fastify/multipart": "^8.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"ts-node": "^10.9.1",
"ts-patch": "^3.1.0",
"typescript": "^5.4.2",
"typia": "^6.0.0"
"typia": "^6.0.1"
},
"dependencies": {
"chalk": "^4.1.2",
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.0.0",
"version": "3.0.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/migrate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/migrate",
"version": "0.13.0",
"version": "0.13.1",
"description": "Migration program from swagger to NestJS",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -34,9 +34,9 @@
},
"homepage": "https://nestia.io",
"devDependencies": {
"@nestia/core": "^3.0.0",
"@nestia/core": "^3.0.1",
"@nestia/e2e": "^0.4.3",
"@nestia/fetcher": "^3.0.0",
"@nestia/fetcher": "^3.0.1",
"@nestjs/common": "^10.3.5",
"@nestjs/core": "^10.3.5",
"@nestjs/platform-express": "^10.3.5",
Expand All @@ -58,14 +58,14 @@
"typescript-transform-paths": "^3.4.6"
},
"dependencies": {
"@samchon/openapi": "^0.1.2",
"@samchon/openapi": "^0.1.5",
"commander": "10.0.0",
"inquirer": "8.2.5",
"openapi-types": "^12.1.3",
"prettier": "^3.2.5",
"tstl": "^3.0.0",
"typescript": "^5.4.3",
"typia": "^6.0.0"
"typia": "^6.0.1"
},
"files": [
"lib",
Expand Down
36 changes: 28 additions & 8 deletions packages/migrate/src/analyzers/MigrateMethodAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,34 @@ export namespace MigrateMethodAnalzyer {
.map((str) =>
str[0] === "{" ? str.substring(1, str.length - 1) : str.substring(1),
);
if (
parameterNames.length !==
route.parameters.filter((p) => p.in === "path").length
)
failures.push(
"number of path parameters are not matched with its full path.",
);

const pathParameters: OpenApi.IOperation.IParameter[] =
route.parameters.filter((p) => p.in === "path");
if (parameterNames.length !== pathParameters.length)
if (
pathParameters.length < parameterNames.length &&
pathParameters.every(
(p) => p.name !== undefined && parameterNames.includes(p.name),
)
) {
for (const name of parameterNames)
if (pathParameters.find((p) => p.name === name) === undefined)
pathParameters.push({
name,
in: "path",
schema: { type: "string" },
});
pathParameters.sort(
(a, b) =>
parameterNames.indexOf(a.name!) - parameterNames.indexOf(b.name!),
);
route.parameters = [
...pathParameters,
...route.parameters.filter((p) => p.in !== "path"),
];
} else
failures.push(
"number of path parameters are not matched with its full path.",
);
if (failures.length) {
console.log(
`Failed to migrate ${endpoint.method.toUpperCase()} ${endpoint.path}`,
Expand Down
12 changes: 9 additions & 3 deletions packages/migrate/src/internal/MigrateCommander.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenApi } from "@samchon/openapi";
import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
import fs from "fs";
import path from "path";
import { format } from "prettier";
Expand All @@ -23,14 +23,20 @@ export namespace MigrateCommander {
halt("Output directory's parent is not a directory.");

// READ SWAGGER
const document: OpenApi.IDocument = (() => {
const document:
| SwaggerV2.IDocument
| OpenApiV3.IDocument
| OpenApiV3_1.IDocument = (() => {
if (fs.existsSync(options.input) === false)
halt("Unable to find the input swagger.json file.");
const stats: fs.Stats = fs.statSync(options.input);
if (stats.isFile() === false)
halt("The input swagger.json is not a file.");
const content: string = fs.readFileSync(options.input, "utf-8");
const swagger: OpenApi.IDocument = JSON.parse(content);
const swagger:
| SwaggerV2.IDocument
| OpenApiV3.IDocument
| OpenApiV3_1.IDocument = JSON.parse(content);
return swagger;
})();

Expand Down
12 changes: 6 additions & 6 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/sdk",
"version": "3.0.0",
"version": "3.0.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/fetcher": "^3.0.0",
"@samchon/openapi": "^0.1.2",
"@nestia/fetcher": "^3.0.1",
"@samchon/openapi": "^0.1.5",
"cli": "^1.0.1",
"get-function-location": "^2.0.0",
"glob": "^7.2.0",
Expand All @@ -43,15 +43,15 @@
"tsconfig-paths": "^4.1.1",
"ts-node": ">=10.6.0",
"tstl": "^3.0.0",
"typia": "^6.0.0"
"typia": "^6.0.1"
},
"peerDependencies": {
"@nestia/fetcher": ">=3.0.0",
"@nestia/fetcher": ">=3.0.1",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"reflect-metadata": ">=0.1.12",
"ts-node": ">=10.6.0",
"typia": ">=6.0.0 <7.0.0"
"typia": ">=6.0.1 <7.0.0"
},
"devDependencies": {
"@nestia/e2e": "^0.4.1",
Expand Down
12 changes: 6 additions & 6 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@nestia/test",
"version": "3.0.0",
"version": "3.0.1",
"description": "Test program of Nestia",
"main": "index.js",
"scripts": {
Expand All @@ -26,9 +26,9 @@
},
"homepage": "https://nestia.io",
"devDependencies": {
"@nestia/sdk": "^3.0.0",
"@nestia/sdk": "^3.0.1",
"@nestjs/swagger": "^7.1.2",
"@samchon/openapi": "^0.1.2",
"@samchon/openapi": "^0.1.5",
"@types/express": "^4.17.17",
"@types/node": "20.11.16",
"@types/uuid": "^9.0.8",
Expand All @@ -40,15 +40,15 @@
},
"dependencies": {
"@fastify/multipart": "^8.1.0",
"@nestia/core": "^3.0.0",
"@nestia/core": "^3.0.1",
"@nestia/e2e": "^0.3.6",
"@nestia/fetcher": "^3.0.0",
"@nestia/fetcher": "^3.0.1",
"@nestjs/common": "^10.3.5",
"@nestjs/core": "^10.3.5",
"@nestjs/platform-express": "^10.3.5",
"@nestjs/platform-fastify": "^10.3.5",
"tstl": "^3.0.0",
"typia": "^6.0.0",
"typia": "^6.0.1",
"uuid": "^9.0.1"
}
}
4 changes: 2 additions & 2 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"@mui/icons-material": "5.15.6",
"@mui/material": "5.15.6",
"@mui/system": "5.15.6",
"@nestia/migrate": "^0.13.0",
"@samchon/openapi": "^0.1.2",
"@nestia/migrate": "^0.13.1",
"@samchon/openapi": "^0.1.5",
"@stackblitz/sdk": "^1.9.0",
"js-yaml": "^4.1.0",
"next": "14.1.0",
Expand Down
Loading

0 comments on commit fe37838

Please sign in to comment.