@zuplo/cli 6.65.8 → 6.66.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/import-openapi.test.js +90 -1
- package/dist/__tests__/import-openapi.test.js.map +1 -1
- package/dist/open-api/convert/handler.js +2 -2
- package/dist/open-api/convert/handler.js.map +1 -1
- package/dist/open-api/merge/handler.d.ts +1 -1
- package/dist/open-api/merge/handler.d.ts.map +1 -1
- package/dist/open-api/merge/handler.js +4 -5
- package/dist/open-api/merge/handler.js.map +1 -1
- package/dist/open-api/overlay/handler.js +1 -2
- package/dist/open-api/overlay/handler.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/dist/__tests__/import-openapi-utils.test.d.ts +0 -2
- package/dist/__tests__/import-openapi-utils.test.d.ts.map +0 -1
- package/dist/__tests__/import-openapi-utils.test.js +0 -125
- package/dist/__tests__/import-openapi-utils.test.js.map +0 -1
- package/dist/__tests__/oas-test-data.d.ts +0 -98
- package/dist/__tests__/oas-test-data.d.ts.map +0 -1
- package/dist/__tests__/oas-test-data.js +0 -114
- package/dist/__tests__/oas-test-data.js.map +0 -1
- package/dist/common/file-format.d.ts +0 -25
- package/dist/common/file-format.d.ts.map +0 -1
- package/dist/common/file-format.js +0 -72
- package/dist/common/file-format.js.map +0 -1
- package/dist/common/open-api/constants.d.ts +0 -13
- package/dist/common/open-api/constants.d.ts.map +0 -1
- package/dist/common/open-api/constants.js +0 -16
- package/dist/common/open-api/constants.js.map +0 -1
- package/dist/common/open-api/index.d.ts +0 -3
- package/dist/common/open-api/index.d.ts.map +0 -1
- package/dist/common/open-api/index.js +0 -3
- package/dist/common/open-api/index.js.map +0 -1
- package/dist/common/open-api/validation.d.ts +0 -297
- package/dist/common/open-api/validation.d.ts.map +0 -1
- package/dist/common/open-api/validation.js +0 -88
- package/dist/common/open-api/validation.js.map +0 -1
- package/dist/open-api/convert/convert-engine.d.ts +0 -26
- package/dist/open-api/convert/convert-engine.d.ts.map +0 -1
- package/dist/open-api/convert/convert-engine.js +0 -20
- package/dist/open-api/convert/convert-engine.js.map +0 -1
- package/dist/open-api/convert/convert-engine.spec.d.ts +0 -2
- package/dist/open-api/convert/convert-engine.spec.d.ts.map +0 -1
- package/dist/open-api/convert/convert-engine.spec.js +0 -268
- package/dist/open-api/convert/convert-engine.spec.js.map +0 -1
- package/dist/open-api/merge/ajv.d.ts +0 -34
- package/dist/open-api/merge/ajv.d.ts.map +0 -1
- package/dist/open-api/merge/ajv.js +0 -2
- package/dist/open-api/merge/ajv.js.map +0 -1
- package/dist/open-api/merge/interfaces.d.ts +0 -72
- package/dist/open-api/merge/interfaces.d.ts.map +0 -1
- package/dist/open-api/merge/interfaces.js +0 -5
- package/dist/open-api/merge/interfaces.js.map +0 -1
- package/dist/open-api/merge/merge-engine.d.ts +0 -20
- package/dist/open-api/merge/merge-engine.d.ts.map +0 -1
- package/dist/open-api/merge/merge-engine.js +0 -34
- package/dist/open-api/merge/merge-engine.js.map +0 -1
- package/dist/open-api/merge/merge-engine.spec.d.ts +0 -2
- package/dist/open-api/merge/merge-engine.spec.d.ts.map +0 -1
- package/dist/open-api/merge/merge-engine.spec.js +0 -117
- package/dist/open-api/merge/merge-engine.spec.js.map +0 -1
- package/dist/open-api/merge/utils.d.ts +0 -11
- package/dist/open-api/merge/utils.d.ts.map +0 -1
- package/dist/open-api/merge/utils.js +0 -33
- package/dist/open-api/merge/utils.js.map +0 -1
- package/dist/open-api/overlay/overlay-engine.d.ts +0 -45
- package/dist/open-api/overlay/overlay-engine.d.ts.map +0 -1
- package/dist/open-api/overlay/overlay-engine.js +0 -309
- package/dist/open-api/overlay/overlay-engine.js.map +0 -1
- package/dist/open-api/overlay/overlay-engine.spec.d.ts +0 -2
- package/dist/open-api/overlay/overlay-engine.spec.d.ts.map +0 -1
- package/dist/open-api/overlay/overlay-engine.spec.js +0 -687
- package/dist/open-api/overlay/overlay-engine.spec.js.map +0 -1
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { describe, it } from "node:test";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { mergeOpenApiDocuments } from "@zuplo/openapi-tools";
|
|
6
|
-
import { expect } from "chai";
|
|
7
|
-
import { addOperationIdsAsNecessary, BASE_TEMPLATE, parseOpenApiFile, } from "../open-api/merge/merge-engine.js";
|
|
8
|
-
import { baseRoutesFileOnImportTests, baseRoutesFileWOOperationIDs, } from "./oas-test-data.js";
|
|
9
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
-
const __dirname = path.dirname(__filename);
|
|
11
|
-
const testAssetsPath = path.join(__dirname, "..", "..", "src", "__tests__", "test-assets");
|
|
12
|
-
describe("Import open api utils", async function () {
|
|
13
|
-
it("should generate merge changes between two different oas files", async function () {
|
|
14
|
-
const toImportPath = path.join(testAssetsPath, "toimport.oas.json");
|
|
15
|
-
const toImportContent = await fs.readFile(toImportPath, "utf-8");
|
|
16
|
-
const toImportOpenApiSpec = await parseOpenApiFile(".json", toImportContent);
|
|
17
|
-
const originalDocument = (await parseOpenApiFile(".json", JSON.stringify(baseRoutesFileOnImportTests)));
|
|
18
|
-
const { created, merged, retained } = mergeOpenApiDocuments(originalDocument, toImportOpenApiSpec, "path-method");
|
|
19
|
-
const expectedMergedResult = new Set().add("post>/v2/second/{userUid}/nature");
|
|
20
|
-
const expectedRetainedResult = new Set().add("post>/v1/second/{userUid}/nature");
|
|
21
|
-
expect(created).to.deep.equals(new Set());
|
|
22
|
-
expect(merged).to.deep.equals(expectedMergedResult);
|
|
23
|
-
expect(retained).to.deep.equals(expectedRetainedResult);
|
|
24
|
-
});
|
|
25
|
-
it("should generate merge changes between a oas file and the default base template", async function () {
|
|
26
|
-
const toImportPath = path.join(testAssetsPath, "toimport.oas.json");
|
|
27
|
-
const toImportContent = await fs.readFile(toImportPath, "utf-8");
|
|
28
|
-
const toImportOpenApiSpec = await parseOpenApiFile(".json", toImportContent);
|
|
29
|
-
const originalDocument = (await parseOpenApiFile(".json", BASE_TEMPLATE));
|
|
30
|
-
const { created, merged, retained } = mergeOpenApiDocuments(originalDocument, toImportOpenApiSpec, "path-method");
|
|
31
|
-
expect(created).to.deep.equals(new Set().add("post>/v2/second/{userUid}/nature"));
|
|
32
|
-
expect(merged).to.deep.equals(new Set());
|
|
33
|
-
expect(retained).to.deep.equals(new Set());
|
|
34
|
-
});
|
|
35
|
-
it("should generate missing operation ids", async function () {
|
|
36
|
-
const oasDocument = await parseOpenApiFile(".json", JSON.stringify(baseRoutesFileWOOperationIDs));
|
|
37
|
-
addOperationIdsAsNecessary(oasDocument);
|
|
38
|
-
expect(oasDocument.paths).to.not.be.empty;
|
|
39
|
-
expect(oasDocument.paths["/v2/second/{userUid}/nature"]?.post?.operationId)
|
|
40
|
-
.to.not.be.empty;
|
|
41
|
-
});
|
|
42
|
-
it("should not change existing operation ids", async function () {
|
|
43
|
-
const oasDocument = await parseOpenApiFile(".json", JSON.stringify(baseRoutesFileOnImportTests));
|
|
44
|
-
addOperationIdsAsNecessary(oasDocument);
|
|
45
|
-
expect(oasDocument.paths).to.not.be.empty;
|
|
46
|
-
expect(oasDocument.paths["/v1/second/{userUid}/nature"]?.post?.operationId).to.equal("12345");
|
|
47
|
-
expect(oasDocument.paths["/v2/second/{userUid}/nature"]?.post?.operationId).to.equal("67920");
|
|
48
|
-
});
|
|
49
|
-
it("should successfully parse a yaml open api file", async function () {
|
|
50
|
-
const toImportPath = path.join(testAssetsPath, "toimportv2.yaml");
|
|
51
|
-
const toImportContent = await fs.readFile(toImportPath, "utf-8");
|
|
52
|
-
const toImportOpenApiSpec = await parseOpenApiFile(".yaml", toImportContent);
|
|
53
|
-
expect(toImportOpenApiSpec).to.not.be.empty;
|
|
54
|
-
expect(toImportOpenApiSpec.info).to.deep.equals({
|
|
55
|
-
title: "Protect API",
|
|
56
|
-
description: "Buy & sell",
|
|
57
|
-
version: "0.2.0",
|
|
58
|
-
contact: {
|
|
59
|
-
name: "Zuplo YAML Test",
|
|
60
|
-
url: "https://zuplo.com/",
|
|
61
|
-
email: "test@example.com",
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
expect(toImportOpenApiSpec.servers).to.deep.equals([
|
|
65
|
-
{
|
|
66
|
-
url: "https://api.zuplo.com",
|
|
67
|
-
description: "Production",
|
|
68
|
-
},
|
|
69
|
-
]);
|
|
70
|
-
expect(toImportOpenApiSpec.tags).to.deep.equals([
|
|
71
|
-
{
|
|
72
|
-
name: "Order",
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
name: "Organization",
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
name: "Site",
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
name: "Supervisor",
|
|
82
|
-
},
|
|
83
|
-
]);
|
|
84
|
-
expect(toImportOpenApiSpec.paths).to.not.be.empty;
|
|
85
|
-
expect(toImportOpenApiSpec.paths["/v1/orders"]).to.not.be.empty;
|
|
86
|
-
expect(toImportOpenApiSpec.paths["/v1/orders/wa/{waaaa}"]).to.not.be.empty;
|
|
87
|
-
expect(toImportOpenApiSpec.paths["/v1/orders/{order}"]).to.not.be.empty;
|
|
88
|
-
expect(toImportOpenApiSpec.paths["/v1/orgs/{organization}"]).to.not.be
|
|
89
|
-
.empty;
|
|
90
|
-
expect(toImportOpenApiSpec.paths["/v1/sites"]).to.deep.equals({
|
|
91
|
-
get: {
|
|
92
|
-
operationId: "get-sites",
|
|
93
|
-
summary: "Get Sites",
|
|
94
|
-
description: "Sites are locations",
|
|
95
|
-
tags: ["Site"],
|
|
96
|
-
responses: {
|
|
97
|
-
"200": {
|
|
98
|
-
description: "OK",
|
|
99
|
-
content: {
|
|
100
|
-
"application/json": {
|
|
101
|
-
schema: {
|
|
102
|
-
type: "array",
|
|
103
|
-
items: {
|
|
104
|
-
$ref: "#/components/schemas/Site",
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
headers: {
|
|
110
|
-
"Cache-Control": {
|
|
111
|
-
required: true,
|
|
112
|
-
schema: {
|
|
113
|
-
type: "string",
|
|
114
|
-
},
|
|
115
|
-
description: "Responses are cacheable following standard HTTP headers.",
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
expect(toImportOpenApiSpec.components).to.not.be.empty;
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
//# sourceMappingURL=import-openapi-utils.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"import-openapi-utils.test.js","sourceRoot":"","sources":["../../src/__tests__/import-openapi-utils.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,OAAO,EACL,0BAA0B,EAC1B,aAAa,EACb,gBAAgB,GACjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,oBAAoB,CAAC;AAE5B,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAE3C,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAC9B,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,WAAW,EACX,aAAa,CACd,CAAC;AAEF,QAA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EAAE,OAAO;oCACb,KAAK,EAAE;wCACL,IAAI,EAAE,2BAA2B;qCAClC;iCACF;6BACF;yBACF;wBACD,OAAO,EAAE;4BACP,eAAe,EAAE;gCACf,QAAQ,EAAE,IAAI;gCACd,MAAM,EAAE;oCACN,IAAI,EAAE,QAAQ;iCACf;gCACD,WAAW,EACT,0DAA0D;6BAC7D;yBACF;qBACF;iBACF;aACF;SACF,CAAC,CAAC;QACH,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { describe, it } from \"node:test\";\nimport { fileURLToPath } from \"node:url\";\nimport { mergeOpenApiDocuments } from \"@zuplo/openapi-tools\";\nimport { expect } from \"chai\";\nimport { ZuploOpenApiDocument } from \"../../../types/dist/open-api.js\";\nimport {\n addOperationIdsAsNecessary,\n BASE_TEMPLATE,\n parseOpenApiFile,\n} from \"../open-api/merge/merge-engine.js\";\nimport {\n baseRoutesFileOnImportTests,\n baseRoutesFileWOOperationIDs,\n} from \"./oas-test-data.js\";\n\nconst __filename = fileURLToPath(import.meta.url); // get the resolved path to the file\nconst __dirname = path.dirname(__filename); // get the name of the directory\n\nconst testAssetsPath = path.join(\n __dirname,\n \"..\",\n \"..\",\n \"src\",\n \"__tests__\",\n \"test-assets\"\n);\n\ndescribe(\"Import open api utils\", async function () {\n it(\"should generate merge changes between two different oas files\", async function () {\n const toImportPath = path.join(testAssetsPath, \"toimport.oas.json\");\n const toImportContent = await fs.readFile(toImportPath, \"utf-8\");\n const toImportOpenApiSpec = await parseOpenApiFile(\n \".json\",\n toImportContent\n );\n\n const originalDocument = (await parseOpenApiFile(\n \".json\",\n JSON.stringify(baseRoutesFileOnImportTests)\n )) as ZuploOpenApiDocument;\n\n const { created, merged, retained } = mergeOpenApiDocuments(\n originalDocument,\n toImportOpenApiSpec,\n \"path-method\"\n );\n\n const expectedMergedResult = new Set().add(\n \"post>/v2/second/{userUid}/nature\"\n );\n const expectedRetainedResult = new Set().add(\n \"post>/v1/second/{userUid}/nature\"\n );\n\n expect(created).to.deep.equals(new Set());\n expect(merged).to.deep.equals(expectedMergedResult);\n expect(retained).to.deep.equals(expectedRetainedResult);\n });\n\n it(\"should generate merge changes between a oas file and the default base template\", async function () {\n const toImportPath = path.join(testAssetsPath, \"toimport.oas.json\");\n const toImportContent = await fs.readFile(toImportPath, \"utf-8\");\n const toImportOpenApiSpec = await parseOpenApiFile(\n \".json\",\n toImportContent\n );\n\n const originalDocument = (await parseOpenApiFile(\n \".json\",\n BASE_TEMPLATE\n )) as ZuploOpenApiDocument;\n\n const { created, merged, retained } = mergeOpenApiDocuments(\n originalDocument,\n toImportOpenApiSpec,\n \"path-method\"\n );\n\n expect(created).to.deep.equals(\n new Set().add(\"post>/v2/second/{userUid}/nature\")\n );\n expect(merged).to.deep.equals(new Set());\n expect(retained).to.deep.equals(new Set());\n });\n\n it(\"should generate missing operation ids\", async function () {\n const oasDocument = await parseOpenApiFile(\n \".json\",\n JSON.stringify(baseRoutesFileWOOperationIDs)\n );\n\n addOperationIdsAsNecessary(oasDocument);\n\n expect(oasDocument.paths).to.not.be.empty;\n // @ts-expect-error\n expect(oasDocument.paths[\"/v2/second/{userUid}/nature\"]?.post?.operationId)\n .to.not.be.empty;\n });\n\n it(\"should not change existing operation ids\", async function () {\n const oasDocument = await parseOpenApiFile(\n \".json\",\n JSON.stringify(baseRoutesFileOnImportTests)\n );\n\n addOperationIdsAsNecessary(oasDocument);\n\n expect(oasDocument.paths).to.not.be.empty;\n expect(\n // @ts-expect-error\n oasDocument.paths[\"/v1/second/{userUid}/nature\"]?.post?.operationId\n ).to.equal(\"12345\");\n expect(\n // @ts-expect-error\n oasDocument.paths[\"/v2/second/{userUid}/nature\"]?.post?.operationId\n ).to.equal(\"67920\");\n });\n\n it(\"should successfully parse a yaml open api file\", async function () {\n const toImportPath = path.join(testAssetsPath, \"toimportv2.yaml\");\n const toImportContent = await fs.readFile(toImportPath, \"utf-8\");\n const toImportOpenApiSpec = await parseOpenApiFile(\n \".yaml\",\n toImportContent\n );\n\n expect(toImportOpenApiSpec).to.not.be.empty;\n expect(toImportOpenApiSpec.info).to.deep.equals({\n title: \"Protect API\",\n description: \"Buy & sell\",\n version: \"0.2.0\",\n contact: {\n name: \"Zuplo YAML Test\",\n url: \"https://zuplo.com/\",\n email: \"test@example.com\",\n },\n });\n expect(toImportOpenApiSpec.servers).to.deep.equals([\n {\n url: \"https://api.zuplo.com\",\n description: \"Production\",\n },\n ]);\n expect(toImportOpenApiSpec.tags).to.deep.equals([\n {\n name: \"Order\",\n },\n {\n name: \"Organization\",\n },\n {\n name: \"Site\",\n },\n {\n name: \"Supervisor\",\n },\n ]);\n\n expect(toImportOpenApiSpec.paths).to.not.be.empty;\n\n //@ts-expect-error\n expect(toImportOpenApiSpec.paths[\"/v1/orders\"]).to.not.be.empty;\n //@ts-expect-error\n expect(toImportOpenApiSpec.paths[\"/v1/orders/wa/{waaaa}\"]).to.not.be.empty;\n //@ts-expect-error\n expect(toImportOpenApiSpec.paths[\"/v1/orders/{order}\"]).to.not.be.empty;\n //@ts-expect-error\n expect(toImportOpenApiSpec.paths[\"/v1/orgs/{organization}\"]).to.not.be\n .empty;\n //@ts-expect-error\n expect(toImportOpenApiSpec.paths[\"/v1/sites\"]).to.deep.equals({\n get: {\n operationId: \"get-sites\",\n summary: \"Get Sites\",\n description: \"Sites are locations\",\n tags: [\"Site\"],\n responses: {\n \"200\": {\n description: \"OK\",\n content: {\n \"application/json\": {\n schema: {\n type: \"array\",\n items: {\n $ref: \"#/components/schemas/Site\",\n },\n },\n },\n },\n headers: {\n \"Cache-Control\": {\n required: true,\n schema: {\n type: \"string\",\n },\n description:\n \"Responses are cacheable following standard HTTP headers.\",\n },\n },\n },\n },\n },\n });\n expect(toImportOpenApiSpec.components).to.not.be.empty;\n });\n});\n"]}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
export declare const baseRoutesFileOnImportTests: {
|
|
2
|
-
info: {
|
|
3
|
-
version: string;
|
|
4
|
-
title: string;
|
|
5
|
-
description: string;
|
|
6
|
-
contact: {
|
|
7
|
-
name: string;
|
|
8
|
-
url: string;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
openapi: string;
|
|
12
|
-
components: {
|
|
13
|
-
parameters: {
|
|
14
|
-
userUid: {
|
|
15
|
-
name: string;
|
|
16
|
-
in: string;
|
|
17
|
-
description: string;
|
|
18
|
-
required: boolean;
|
|
19
|
-
schema: {
|
|
20
|
-
type: string;
|
|
21
|
-
format: string;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
securitySchemes: {
|
|
26
|
-
authorization: {
|
|
27
|
-
type: string;
|
|
28
|
-
description: string;
|
|
29
|
-
scheme: string;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
servers: {
|
|
34
|
-
url: string;
|
|
35
|
-
description: string;
|
|
36
|
-
}[];
|
|
37
|
-
security: {}[];
|
|
38
|
-
tags: never[];
|
|
39
|
-
paths: {
|
|
40
|
-
"/v1/second/{userUid}/nature": {
|
|
41
|
-
post: {
|
|
42
|
-
summary: string;
|
|
43
|
-
operationId: string;
|
|
44
|
-
parameters: {
|
|
45
|
-
$ref: string;
|
|
46
|
-
}[];
|
|
47
|
-
responses: {
|
|
48
|
-
"200": {
|
|
49
|
-
description: string;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
security: {}[];
|
|
53
|
-
servers: {
|
|
54
|
-
url: string;
|
|
55
|
-
description: string;
|
|
56
|
-
}[];
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
"/v2/second/{userUid}/nature": {
|
|
60
|
-
post: {
|
|
61
|
-
operationId: string;
|
|
62
|
-
summary: string;
|
|
63
|
-
parameters: {
|
|
64
|
-
$ref: string;
|
|
65
|
-
}[];
|
|
66
|
-
responses: {
|
|
67
|
-
"200": {
|
|
68
|
-
description: string;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
export declare const baseRoutesFileWOOperationIDs: {
|
|
76
|
-
info: {
|
|
77
|
-
version: string;
|
|
78
|
-
title: string;
|
|
79
|
-
};
|
|
80
|
-
openapi: string;
|
|
81
|
-
components: {};
|
|
82
|
-
servers: never[];
|
|
83
|
-
security: {}[];
|
|
84
|
-
tags: never[];
|
|
85
|
-
paths: {
|
|
86
|
-
"/v2/second/{userUid}/nature": {
|
|
87
|
-
post: {
|
|
88
|
-
summary: string;
|
|
89
|
-
responses: {
|
|
90
|
-
"200": {
|
|
91
|
-
description: string;
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
//# sourceMappingURL=oas-test-data.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oas-test-data.d.ts","sourceRoot":"","sources":["../../src/__tests__/oas-test-data.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyFvC,CAAC;AAEF,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;CAsBxC,CAAC"}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
export const baseRoutesFileOnImportTests = {
|
|
2
|
-
info: {
|
|
3
|
-
version: "v2",
|
|
4
|
-
title: "Zuplo test API V2",
|
|
5
|
-
description: "Test api v2",
|
|
6
|
-
contact: {
|
|
7
|
-
name: "Zuplo test",
|
|
8
|
-
url: "www.zuplo.com",
|
|
9
|
-
},
|
|
10
|
-
},
|
|
11
|
-
openapi: "3.1.0",
|
|
12
|
-
components: {
|
|
13
|
-
parameters: {
|
|
14
|
-
userUid: {
|
|
15
|
-
name: "userUid",
|
|
16
|
-
in: "path",
|
|
17
|
-
description: "Unique UUID of the user.",
|
|
18
|
-
required: true,
|
|
19
|
-
schema: {
|
|
20
|
-
type: "string",
|
|
21
|
-
format: "uuid",
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
securitySchemes: {
|
|
26
|
-
authorization: {
|
|
27
|
-
type: "http",
|
|
28
|
-
description: "Firebase JWT auth token",
|
|
29
|
-
scheme: "bearer",
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
servers: [
|
|
34
|
-
{
|
|
35
|
-
url: "https://api.stage.example.com",
|
|
36
|
-
description: "Stage",
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
url: "https://api.example.com",
|
|
40
|
-
description: "Prod",
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
security: [{}],
|
|
44
|
-
tags: [],
|
|
45
|
-
paths: {
|
|
46
|
-
"/v1/second/{userUid}/nature": {
|
|
47
|
-
post: {
|
|
48
|
-
summary: "Test route",
|
|
49
|
-
operationId: "12345",
|
|
50
|
-
parameters: [
|
|
51
|
-
{
|
|
52
|
-
$ref: "#/components/parameters/userUid",
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
responses: {
|
|
56
|
-
"200": {
|
|
57
|
-
description: "",
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
security: [{}],
|
|
61
|
-
servers: [
|
|
62
|
-
{
|
|
63
|
-
url: "https://api.stage.example.com",
|
|
64
|
-
description: "stage",
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
url: "https://api.example.com",
|
|
68
|
-
description: "production",
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
"/v2/second/{userUid}/nature": {
|
|
74
|
-
post: {
|
|
75
|
-
operationId: "67920",
|
|
76
|
-
summary: "Test route v2",
|
|
77
|
-
parameters: [
|
|
78
|
-
{
|
|
79
|
-
$ref: "#/components/parameters/userUid",
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
responses: {
|
|
83
|
-
"200": {
|
|
84
|
-
description: "",
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
export const baseRoutesFileWOOperationIDs = {
|
|
92
|
-
info: {
|
|
93
|
-
version: "v2",
|
|
94
|
-
title: "Zuplo test API V2",
|
|
95
|
-
},
|
|
96
|
-
openapi: "3.1.0",
|
|
97
|
-
components: {},
|
|
98
|
-
servers: [],
|
|
99
|
-
security: [{}],
|
|
100
|
-
tags: [],
|
|
101
|
-
paths: {
|
|
102
|
-
"/v2/second/{userUid}/nature": {
|
|
103
|
-
post: {
|
|
104
|
-
summary: "Test route v2",
|
|
105
|
-
responses: {
|
|
106
|
-
"200": {
|
|
107
|
-
description: "",
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
//# sourceMappingURL=oas-test-data.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oas-test-data.js","sourceRoot":"","sources":["../../src/__tests__/oas-test-data.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,IAAI,EAAE;QACJ,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EAAE,aAAa;QAC1B,OAAO,EAAE;YACP,IAAI,EAAE,YAAY;YAClB,GAAG,EAAE,eAAe;SACrB;KACF;IACD,OAAO,EAAE,OAAO;IAChB,UAAU,EAAE;QACV,UAAU,EAAE;YACV,OAAO,EAAE;gBACP,IAAI,EAAE,SAAS;gBACf,EAAE,EAAE,MAAM;gBACV,WAAW,EAAE,0BAA0B;gBACvC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mBAAmB;KAC3B;IACD,OAAO,EAAE,OAAO;IAChB,UAAU,EAAE,EAAE;IACd,OAAO,EAAE,EAAE;IACX,QAAQ,EAAE,CAAC,EAAE,CAAC;IACd,IAAI,EAAE,EAAE;IACR,KAAK,EAAE;QACL,6BAA6B,EAAE;YAC7B,IAAI,EAAE;gBACJ,OAAO,EAAE,eAAe;gBACxB,SAAS,EAAE;oBACT,KAAK,EAAE;wBACL,WAAW,EAAE,EAAE;qBAChB;iBACF;aACF;SACF;KACF;CACF,CAAC","sourcesContent":["export const baseRoutesFileOnImportTests = {\n info: {\n version: \"v2\",\n title: \"Zuplo test API V2\",\n description: \"Test api v2\",\n contact: {\n name: \"Zuplo test\",\n url: \"www.zuplo.com\",\n },\n },\n openapi: \"3.1.0\",\n components: {\n parameters: {\n userUid: {\n name: \"userUid\",\n in: \"path\",\n description: \"Unique UUID of the user.\",\n required: true,\n schema: {\n type: \"string\",\n format: \"uuid\",\n },\n },\n },\n securitySchemes: {\n authorization: {\n type: \"http\",\n description: \"Firebase JWT auth token\",\n scheme: \"bearer\",\n },\n },\n },\n servers: [\n {\n url: \"https://api.stage.example.com\",\n description: \"Stage\",\n },\n {\n url: \"https://api.example.com\",\n description: \"Prod\",\n },\n ],\n security: [{}],\n tags: [],\n paths: {\n \"/v1/second/{userUid}/nature\": {\n post: {\n summary: \"Test route\",\n operationId: \"12345\",\n parameters: [\n {\n $ref: \"#/components/parameters/userUid\",\n },\n ],\n responses: {\n \"200\": {\n description: \"\",\n },\n },\n security: [{}],\n servers: [\n {\n url: \"https://api.stage.example.com\",\n description: \"stage\",\n },\n {\n url: \"https://api.example.com\",\n description: \"production\",\n },\n ],\n },\n },\n \"/v2/second/{userUid}/nature\": {\n post: {\n operationId: \"67920\",\n summary: \"Test route v2\",\n parameters: [\n {\n $ref: \"#/components/parameters/userUid\",\n },\n ],\n responses: {\n \"200\": {\n description: \"\",\n },\n },\n },\n },\n },\n};\n\nexport const baseRoutesFileWOOperationIDs = {\n info: {\n version: \"v2\",\n title: \"Zuplo test API V2\",\n },\n openapi: \"3.1.0\",\n components: {},\n servers: [],\n security: [{}],\n tags: [],\n paths: {\n \"/v2/second/{userUid}/nature\": {\n post: {\n summary: \"Test route v2\",\n responses: {\n \"200\": {\n description: \"\",\n },\n },\n },\n },\n },\n};\n"]}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export type FileFormat = "json" | "yaml";
|
|
2
|
-
export declare function detectFormatFromExtension(
|
|
3
|
-
filePath: string
|
|
4
|
-
): FileFormat | null;
|
|
5
|
-
export declare function detectFormatFromContent(content: string): FileFormat;
|
|
6
|
-
export declare function parseContent(content: string, format: FileFormat): any;
|
|
7
|
-
export declare function parseFlexible(
|
|
8
|
-
content: string,
|
|
9
|
-
knownFormat?: FileFormat
|
|
10
|
-
): {
|
|
11
|
-
document: any;
|
|
12
|
-
detectedFormat: FileFormat;
|
|
13
|
-
};
|
|
14
|
-
export declare function serializeContent(
|
|
15
|
-
document: any,
|
|
16
|
-
format: FileFormat
|
|
17
|
-
): string;
|
|
18
|
-
export declare function parseFile(
|
|
19
|
-
content: string,
|
|
20
|
-
filePath: string
|
|
21
|
-
): {
|
|
22
|
-
document: any;
|
|
23
|
-
detectedFormat: FileFormat;
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=file-format.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-format.d.ts","sourceRoot":"","sources":["../../src/common/file-format.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AAMzC,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAS7E;AAMD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAcnE;AAMD,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,GAAG,CAKrE;AAOD,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,UAAU,GAEvB;IAAE,QAAQ,EAAE,GAAG,CAAC;IAAC,cAAc,EAAE,UAAU,CAAA;CAAE,CAuB/C;AAMD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,CAK1E;AAMD,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,GAEf;IAAE,QAAQ,EAAE,GAAG,CAAC;IAAC,cAAc,EAAE,UAAU,CAAA;CAAE,CAa/C"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import yaml from "js-yaml";
|
|
2
|
-
export function detectFormatFromExtension(filePath) {
|
|
3
|
-
const ext = filePath.toLowerCase();
|
|
4
|
-
if (ext.endsWith(".json")) {
|
|
5
|
-
return "json";
|
|
6
|
-
}
|
|
7
|
-
if (ext.endsWith(".yaml") || ext.endsWith(".yml")) {
|
|
8
|
-
return "yaml";
|
|
9
|
-
}
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
export function detectFormatFromContent(content) {
|
|
13
|
-
try {
|
|
14
|
-
JSON.parse(content);
|
|
15
|
-
return "json";
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
try {
|
|
19
|
-
yaml.load(content);
|
|
20
|
-
return "yaml";
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
throw new Error("Failed to parse content as either JSON or YAML");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export function parseContent(content, format) {
|
|
28
|
-
if (format === "json") {
|
|
29
|
-
return JSON.parse(content);
|
|
30
|
-
}
|
|
31
|
-
return yaml.load(content);
|
|
32
|
-
}
|
|
33
|
-
export function parseFlexible(content, knownFormat) {
|
|
34
|
-
if (knownFormat) {
|
|
35
|
-
return {
|
|
36
|
-
document: parseContent(content, knownFormat),
|
|
37
|
-
detectedFormat: knownFormat,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
const document = JSON.parse(content);
|
|
42
|
-
return { document, detectedFormat: "json" };
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
try {
|
|
46
|
-
const document = yaml.load(content);
|
|
47
|
-
return { document, detectedFormat: "yaml" };
|
|
48
|
-
}
|
|
49
|
-
catch (err) {
|
|
50
|
-
throw new Error("Failed to parse content as either JSON or YAML", {
|
|
51
|
-
cause: err,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export function serializeContent(document, format) {
|
|
57
|
-
if (format === "json") {
|
|
58
|
-
return `${JSON.stringify(document, null, 2)}\n`;
|
|
59
|
-
}
|
|
60
|
-
return yaml.dump(document, { lineWidth: -1, noRefs: false });
|
|
61
|
-
}
|
|
62
|
-
export function parseFile(content, filePath) {
|
|
63
|
-
const formatFromExt = detectFormatFromExtension(filePath);
|
|
64
|
-
if (formatFromExt) {
|
|
65
|
-
return {
|
|
66
|
-
document: parseContent(content, formatFromExt),
|
|
67
|
-
detectedFormat: formatFromExt,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
return parseFlexible(content);
|
|
71
|
-
}
|
|
72
|
-
//# sourceMappingURL=file-format.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-format.js","sourceRoot":"","sources":["../../src/common/file-format.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,SAAS,CAAC;AAQ3B,MAAM,UAAU,yBAAyB,CAAC,QAAgB;IACxD,MAAM,GAAG,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IACnC,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,QAAQ,CAA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,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,gDAAgD,EAAE;gBAChE,KAAK,EAAE,GAAG;aACX,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC;AAMD,MAAM,UAAU,gBAAgB,CAAC,QAAa,EAAE,MAAkB;IAChE,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;IAClD,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAC/D,CAAC;AAMD,MAAM,UAAU,SAAS,CACvB,OAAe,EACf,QAAgB;IAGhB,MAAM,aAAa,GAAG,yBAAyB,CAAC,QAAQ,CAAC,CAAC;IAE1D,IAAI,aAAa,EAAE,CAAC;QAElB,OAAO;YACL,QAAQ,EAAE,YAAY,CAAC,OAAO,EAAE,aAAa,CAAC;YAC9C,cAAc,EAAE,aAAa;SAC9B,CAAC;IACJ,CAAC;IAGD,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import yaml from \"js-yaml\";\n\nexport type FileFormat = \"json\" | \"yaml\";\n\n/**\n * Detect file format from extension\n * Returns null if extension is unknown or missing\n */\nexport function detectFormatFromExtension(filePath: string): FileFormat | null {\n const ext = filePath.toLowerCase();\n if (ext.endsWith(\".json\")) {\n return \"json\";\n }\n if (ext.endsWith(\".yaml\") || ext.endsWith(\".yml\")) {\n return \"yaml\";\n }\n return null;\n}\n\n/**\n * Detect format from content by trying to parse as both JSON and YAML\n * Tries JSON first as it's faster to validate\n */\nexport function detectFormatFromContent(content: string): FileFormat {\n // Try JSON first\n try {\n JSON.parse(content);\n return \"json\";\n } catch {\n // Try YAML\n try {\n yaml.load(content);\n return \"yaml\";\n } catch {\n throw new Error(\"Failed to parse content as either JSON or YAML\");\n }\n }\n}\n\n/**\n * Parse content with a known format\n */\n// biome-ignore lint/suspicious/noExplicitAny: Generic document parsing\nexport function parseContent(content: string, format: FileFormat): any {\n if (format === \"json\") {\n return JSON.parse(content);\n }\n return yaml.load(content);\n}\n\n/**\n * Parse content with flexible format detection\n * If format is provided, uses that. Otherwise attempts to detect from content.\n */\n\nexport function parseFlexible(\n content: string,\n knownFormat?: FileFormat\n // biome-ignore lint/suspicious/noExplicitAny: Generic document parsing\n): { document: any; detectedFormat: FileFormat } {\n if (knownFormat) {\n return {\n document: parseContent(content, knownFormat),\n detectedFormat: knownFormat,\n };\n }\n\n // Try JSON first (faster)\n try {\n const document = JSON.parse(content);\n return { document, detectedFormat: \"json\" };\n } catch {\n // Try YAML\n try {\n const document = yaml.load(content);\n return { document, detectedFormat: \"yaml\" };\n } catch (err) {\n throw new Error(\"Failed to parse content as either JSON or YAML\", {\n cause: err,\n });\n }\n }\n}\n\n/**\n * Serialize document to string based on format\n */\n// biome-ignore lint/suspicious/noExplicitAny: Generic document serialization\nexport function serializeContent(document: any, format: FileFormat): string {\n if (format === \"json\") {\n return `${JSON.stringify(document, null, 2)}\\n`;\n }\n return yaml.dump(document, { lineWidth: -1, noRefs: false });\n}\n\n/**\n * Parse file content with automatic format detection from extension\n * Falls back to trying both formats if extension is unknown\n */\nexport function parseFile(\n content: string,\n filePath: string\n // biome-ignore lint/suspicious/noExplicitAny: Generic document parsing\n): { document: any; detectedFormat: FileFormat } {\n const formatFromExt = detectFormatFromExtension(filePath);\n\n if (formatFromExt) {\n // Use the format indicated by extension\n return {\n document: parseContent(content, formatFromExt),\n detectedFormat: formatFromExt,\n };\n }\n\n // No known extension, try both formats\n return parseFlexible(content);\n}\n"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const OPEN_API_FILE_TYPES: readonly string[];
|
|
2
|
-
export declare const HTTP_METHODS: readonly [
|
|
3
|
-
"get",
|
|
4
|
-
"put",
|
|
5
|
-
"post",
|
|
6
|
-
"delete",
|
|
7
|
-
"options",
|
|
8
|
-
"head",
|
|
9
|
-
"patch",
|
|
10
|
-
"trace",
|
|
11
|
-
];
|
|
12
|
-
export type HttpMethod = (typeof HTTP_METHODS)[number];
|
|
13
|
-
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/common/open-api/constants.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAIvC,CAAC;AAKX,eAAO,MAAM,YAAY,gFASf,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/common/open-api/constants.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,mBAAmB,GAAsB;IACpD,OAAO;IACP,MAAM;IACN,OAAO;CACC,CAAC;AAKX,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,KAAK;IACL,KAAK;IACL,MAAM;IACN,QAAQ;IACR,SAAS;IACT,MAAM;IACN,OAAO;IACP,OAAO;CACC,CAAC","sourcesContent":["/**\n * Common constants for OpenAPI operations\n */\n\n/**\n * Supported OpenAPI file extensions\n */\nexport const OPEN_API_FILE_TYPES: readonly string[] = [\n \".json\",\n \".yml\",\n \".yaml\",\n] as const;\n\n/**\n * Standard HTTP methods as defined in OpenAPI specification\n */\nexport const HTTP_METHODS = [\n \"get\",\n \"put\",\n \"post\",\n \"delete\",\n \"options\",\n \"head\",\n \"patch\",\n \"trace\",\n] as const;\n\nexport type HttpMethod = (typeof HTTP_METHODS)[number];\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/open-api/index.ts"],"names":[],"mappings":"AASA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/open-api/index.ts"],"names":[],"mappings":"AASA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC","sourcesContent":["/**\n * Common OpenAPI utilities shared across CLI commands\n *\n * This module provides:\n * - Constants (file types, HTTP methods)\n * - Validation schemas and functions (OpenAPI Overlay specification)\n * - Type definitions\n */\n\nexport * from \"./constants.js\";\nexport * from \"./validation.js\";\n"]}
|