Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
220 changes: 220 additions & 0 deletions integration/openApiGenerator/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`openApiGenerator > correct generate file 1`] = `
"{
"openapi": "3.1.0",
"info": {
"title": "Swagger API",
"version": "0.0.0"
},
"paths": {
"/users": {
"get": {
"parameters": [],
"responses": {
"200": {
"headers": {
"information": {
"schema": {
"const": "users.findMany",
"type": "string"
},
"description": "users.findMany"
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NotIdentified0"
}
}
}
}
}
},
"post": {
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NotIdentified3"
}
}
}
},
"responses": {
"200": {
"headers": {
"information": {
"schema": {
"const": "users.create",
"type": "string"
},
"description": "users.create"
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NotIdentified4"
}
}
}
},
"422": {
"headers": {
"information": {
"schema": {
"const": "extract-error",
"type": "string"
},
"description": "extract-error"
}
}
}
}
}
},
"/users/{userId}": {
"get": {
"parameters": [
{
"name": "userId",
"in": "path",
"required": true,
"schema": {
"$ref": "#/components/schemas/NotIdentified1"
}
}
],
"responses": {
"200": {
"headers": {
"information": {
"schema": {
"const": "users.find",
"type": "string"
},
"description": "users.find"
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NotIdentified2"
}
}
}
},
"422": {
"headers": {
"information": {
"schema": {
"const": "extract-error",
"type": "string"
},
"description": "extract-error"
}
}
}
}
}
}
},
"components": {
"schemas": {
"NotIdentified0": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"name": {
"type": "string"
},
"age": {
"type": "number"
}
},
"required": [
"id",
"name",
"age"
]
}
},
"NotIdentified1": {
"anyOf": [
{
"type": "number"
},
{
"type": "string"
}
]
},
"NotIdentified2": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"name": {
"type": "string"
},
"age": {
"type": "number"
}
},
"required": [
"id",
"name",
"age"
]
},
"NotIdentified3": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"name": {
"type": "string"
},
"age": {
"type": "number"
}
},
"required": [
"id",
"name",
"age"
]
},
"NotIdentified4": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"name": {
"type": "string"
},
"age": {
"type": "number"
}
},
"required": [
"id",
"name",
"age"
]
}
}
}
}"
`;
29 changes: 29 additions & 0 deletions integration/openApiGenerator/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { hub } from "@core";
import { existsSync, readFileSync, rmSync } from "fs";
import { launchHookServer } from "../../dist/core";
import { openApiGeneratorPlugin } from "@duplojs/http/openApiGenerator";

describe("openApiGenerator", () => {
const fileName = `${import.meta.dirname}/swagger.generate.json`;
beforeAll(() => {
if (existsSync(fileName)) {
rmSync(fileName);
}
});

it("correct generate file", async() => {
const hubWithPlugins = hub.plug(
openApiGeneratorPlugin({
outputFilePath: fileName,
routePath: "/swagger",
}),
);
await launchHookServer(
hubWithPlugins.aggregatesHooksHubLifeCycle("beforeServerBuildRoutes"),
hubWithPlugins,
{},
);

expect(readFileSync(fileName, "utf-8")).toMatchSnapshot();
});
});
11 changes: 11 additions & 0 deletions integration/openApiGenerator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.test.json",
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@core": ["../core/index.ts"]
},
"types": ["vitest/globals", "node"]
},
"include": ["**/*.ts", "../core/**/*.ts"],
}
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,20 @@
"import": "./dist/plugins/codeGenerator/index.mjs",
"require": "./dist/plugins/codeGenerator/index.cjs",
"types": "./dist/plugins/codeGenerator/index.d.ts"
},
"./openApiGenerator": {
"import": "./dist/plugins/openApiGenerator/index.mjs",
"require": "./dist/plugins/openApiGenerator/index.cjs",
"types": "./dist/plugins/openApiGenerator/index.d.ts"
}
},
"files": [
"dist",
"README.md"
],
"peerDependencies": {
"@duplojs/data-parser-tools": ">=0.2.2 <1.0.0",
"@duplojs/utils": ">=1.3.32 <2.0.0"
"@duplojs/data-parser-tools": ">=0.2.3 <1.0.0",
"@duplojs/utils": ">=1.3.33 <2.0.0"
},
"devDependencies": {
"@commitlint/cli": "19.8.1",
Expand Down
25 changes: 25 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,31 @@ export default defineConfig([
tscAlias({ configFile: "scripts/plugins/codeGenerator/tsconfig.build.json" }),
],
},
{
input: "scripts/plugins/openApiGenerator/index.ts",
output: [
{
dir: "dist",
format: "esm",
preserveModules: true,
preserveModulesRoot: "scripts",
entryFileNames: "[name].mjs"
},
{
dir: "dist",
format: "cjs",
preserveModules: true,
preserveModulesRoot: "scripts",
entryFileNames: "[name].cjs"
},
],
treeshake: false,
plugins: [
del({ targets: "dist/plugins/openApiGenerator" }),
typescript({ tsconfig: "scripts/plugins/openApiGenerator/tsconfig.build.json" }),
tscAlias({ configFile: "scripts/plugins/openApiGenerator/tsconfig.build.json" }),
],
},

// interfaces
{
Expand Down
Loading
Loading