@keq-request/cli 5.0.0-alpha.17 → 5.0.0-alpha.19
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/CHANGELOG.md +14 -0
- package/dist/cli.cjs +52 -52
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +52 -52
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +51 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +51 -51
- package/dist/index.js.map +1 -1
- package/dist/tasks/utils/api-document.d.ts +2 -2
- package/dist/tasks/utils/api-document.d.ts.map +1 -1
- package/dist/tasks/utils/api-document_v3_1.d.ts +2 -2
- package/dist/tasks/utils/api-document_v3_1.d.ts.map +1 -1
- package/dist/types/build-cli-options.d.ts +1 -1
- package/dist/types/runtime-config.d.ts +1 -1
- package/dist/utils/debugger.d.ts +1 -1
- package/dist/utils/{swagger-utils → openapi-utils}/dereference-deep.d.ts.map +1 -1
- package/dist/utils/{swagger-utils → openapi-utils}/dereference-operation.d.ts.map +1 -1
- package/dist/utils/{swagger-utils → openapi-utils}/dereference.d.ts.map +1 -1
- package/dist/utils/{swagger-utils → openapi-utils}/index.d.ts +1 -1
- package/dist/utils/{swagger-utils → openapi-utils}/index.d.ts.map +1 -1
- package/dist/utils/{swagger-utils → openapi-utils}/is-ref-defined.d.ts.map +1 -1
- package/dist/utils/{swagger-utils → openapi-utils}/remove-undefined-ref.d.ts.map +1 -1
- package/dist/utils/{swagger-utils → openapi-utils}/update-operation-id.d.ts.map +1 -1
- package/package.json +13 -13
- /package/dist/utils/{swagger-utils → openapi-utils}/dereference-deep.d.ts +0 -0
- /package/dist/utils/{swagger-utils → openapi-utils}/dereference-operation.d.ts +0 -0
- /package/dist/utils/{swagger-utils → openapi-utils}/dereference.d.ts +0 -0
- /package/dist/utils/{swagger-utils → openapi-utils}/is-ref-defined.d.ts +0 -0
- /package/dist/utils/{swagger-utils → openapi-utils}/remove-undefined-ref.d.ts +0 -0
- /package/dist/utils/{swagger-utils → openapi-utils}/update-operation-id.d.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
## 5.0.0-alpha.6 (2025-09-17)
|
|
2
2
|
|
|
3
|
+
## 5.0.0-alpha.19
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 30b0848: rename swagger to openapi
|
|
8
|
+
- keq@5.0.0-alpha.19
|
|
9
|
+
|
|
10
|
+
## 5.0.0-alpha.18
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [cbc5d17]
|
|
15
|
+
- keq@5.0.0-alpha.18
|
|
16
|
+
|
|
3
17
|
## 5.0.0-alpha.17
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/cli.cjs
CHANGED
|
@@ -122,7 +122,7 @@ var RuntimeConfig = import_typebox2.Type.Object({
|
|
|
122
122
|
])),
|
|
123
123
|
debug: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
|
|
124
124
|
/**
|
|
125
|
-
* Whether to tolerate wrong swagger structure
|
|
125
|
+
* Whether to tolerate wrong openapi/swagger structure
|
|
126
126
|
*/
|
|
127
127
|
tolerant: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
|
|
128
128
|
plugins: import_typebox2.Type.Optional(import_typebox2.Type.Array(import_typebox2.Type.Any(), { default: [] }))
|
|
@@ -558,14 +558,14 @@ var OperationDefinition = class {
|
|
|
558
558
|
var import_openapi_shaking = require("@opendoc/openapi-shaking");
|
|
559
559
|
var ApiDocumentV3_1 = class _ApiDocumentV3_1 {
|
|
560
560
|
module;
|
|
561
|
-
|
|
562
|
-
constructor(
|
|
561
|
+
specification;
|
|
562
|
+
constructor(specification, module2) {
|
|
563
563
|
this.module = module2;
|
|
564
|
-
this.
|
|
564
|
+
this.specification = specification;
|
|
565
565
|
}
|
|
566
566
|
get schemas() {
|
|
567
567
|
const module2 = this.module;
|
|
568
|
-
return Object.entries(this.
|
|
568
|
+
return Object.entries(this.specification.components?.schemas || {}).map(([name, schema]) => new SchemaDefinition({
|
|
569
569
|
id: `#/components/schemas/${name}`,
|
|
570
570
|
name,
|
|
571
571
|
schema,
|
|
@@ -575,7 +575,7 @@ var ApiDocumentV3_1 = class _ApiDocumentV3_1 {
|
|
|
575
575
|
}
|
|
576
576
|
get operations() {
|
|
577
577
|
const module2 = this.module;
|
|
578
|
-
return Object.entries(this.
|
|
578
|
+
return Object.entries(this.specification.paths || {}).flatMap(([pathname, pathItem]) => Object.entries(pathItem || {}).filter(([method]) => SupportedMethods.includes(method.toLowerCase())).map(([method, operation]) => new OperationDefinition({
|
|
579
579
|
method,
|
|
580
580
|
pathname,
|
|
581
581
|
operation,
|
|
@@ -584,18 +584,18 @@ var ApiDocumentV3_1 = class _ApiDocumentV3_1 {
|
|
|
584
584
|
})));
|
|
585
585
|
}
|
|
586
586
|
isEmpty() {
|
|
587
|
-
return R6.isEmpty(this.
|
|
587
|
+
return R6.isEmpty(this.specification.paths);
|
|
588
588
|
}
|
|
589
589
|
dereference($ref) {
|
|
590
590
|
if ($ref.startsWith("#/")) {
|
|
591
591
|
return this.schemas.find((schema) => schema.id === $ref);
|
|
592
592
|
}
|
|
593
|
-
logger.warn(`The $ref(${$ref}) is not defined in ${this.module.name} swagger.`);
|
|
593
|
+
logger.warn(`The $ref(${$ref}) is not defined in ${this.module.name} openapi/swagger.`);
|
|
594
594
|
}
|
|
595
595
|
isRefDefined($ref) {
|
|
596
596
|
if ($ref.startsWith("#/")) {
|
|
597
597
|
const path9 = $ref.replace("#/", "").split("/");
|
|
598
|
-
return R6.path(path9, this.
|
|
598
|
+
return R6.path(path9, this.specification) !== void 0;
|
|
599
599
|
}
|
|
600
600
|
return false;
|
|
601
601
|
}
|
|
@@ -612,7 +612,7 @@ var ApiDocumentV3_1 = class _ApiDocumentV3_1 {
|
|
|
612
612
|
return filter2(operationDefinition);
|
|
613
613
|
};
|
|
614
614
|
const sharkedSwagger = (0, import_openapi_shaking.openapiShakingSync)(
|
|
615
|
-
this.
|
|
615
|
+
this.specification,
|
|
616
616
|
isAccepted,
|
|
617
617
|
{ tolerant: true }
|
|
618
618
|
);
|
|
@@ -635,14 +635,14 @@ var Debugger = class {
|
|
|
635
635
|
constructor(rc) {
|
|
636
636
|
this.rc = rc;
|
|
637
637
|
}
|
|
638
|
-
|
|
638
|
+
writeOpenapi(fullpath, openapi) {
|
|
639
639
|
if (this.rc?.debug) {
|
|
640
|
-
void import_fs_extra3.default.writeJSON(fullpath,
|
|
640
|
+
void import_fs_extra3.default.writeJSON(fullpath, openapi, { spaces: 2 });
|
|
641
641
|
}
|
|
642
642
|
}
|
|
643
643
|
};
|
|
644
644
|
|
|
645
|
-
// src/utils/
|
|
645
|
+
// src/utils/openapi-utils/dereference.ts
|
|
646
646
|
function dereference($ref, swagger) {
|
|
647
647
|
let value;
|
|
648
648
|
for (const key of $ref.split("/")) {
|
|
@@ -656,17 +656,17 @@ function dereference($ref, swagger) {
|
|
|
656
656
|
return value;
|
|
657
657
|
}
|
|
658
658
|
|
|
659
|
-
// src/utils/
|
|
659
|
+
// src/utils/openapi-utils/dereference-operation.ts
|
|
660
660
|
var R9 = __toESM(require("ramda"), 1);
|
|
661
661
|
var import_jsonpointer2 = __toESM(require("jsonpointer"), 1);
|
|
662
662
|
var import_jsonpath_plus4 = require("jsonpath-plus");
|
|
663
663
|
|
|
664
|
-
// src/utils/
|
|
664
|
+
// src/utils/openapi-utils/remove-undefined-ref.ts
|
|
665
665
|
var R8 = __toESM(require("ramda"), 1);
|
|
666
666
|
var import_jsonpointer = __toESM(require("jsonpointer"), 1);
|
|
667
667
|
var import_jsonpath_plus3 = require("jsonpath-plus");
|
|
668
668
|
|
|
669
|
-
// src/utils/
|
|
669
|
+
// src/utils/openapi-utils/is-ref-defined.ts
|
|
670
670
|
var R7 = __toESM(require("ramda"), 1);
|
|
671
671
|
function isRefDefined($ref, swagger) {
|
|
672
672
|
if ($ref.startsWith("#/")) {
|
|
@@ -676,7 +676,7 @@ function isRefDefined($ref, swagger) {
|
|
|
676
676
|
return false;
|
|
677
677
|
}
|
|
678
678
|
|
|
679
|
-
// src/utils/
|
|
679
|
+
// src/utils/openapi-utils/remove-undefined-ref.ts
|
|
680
680
|
function removeUndefinedRef(swagger) {
|
|
681
681
|
const shadow = R8.clone(swagger);
|
|
682
682
|
const matches = (0, import_jsonpath_plus3.JSONPath)({
|
|
@@ -692,7 +692,7 @@ function removeUndefinedRef(swagger) {
|
|
|
692
692
|
return shadow;
|
|
693
693
|
}
|
|
694
694
|
|
|
695
|
-
// src/utils/
|
|
695
|
+
// src/utils/openapi-utils/dereference-operation.ts
|
|
696
696
|
function dereferencePathObject(swagger) {
|
|
697
697
|
const matches = (0, import_jsonpath_plus4.JSONPath)({
|
|
698
698
|
path: "$.paths.*.$ref^",
|
|
@@ -700,7 +700,7 @@ function dereferencePathObject(swagger) {
|
|
|
700
700
|
resultType: "all"
|
|
701
701
|
});
|
|
702
702
|
for (const match of matches) {
|
|
703
|
-
const value =
|
|
703
|
+
const value = OpenapiUtils.dereference(match.value.$ref, swagger);
|
|
704
704
|
import_jsonpointer2.default.set(swagger, match.pointer, value);
|
|
705
705
|
}
|
|
706
706
|
}
|
|
@@ -711,7 +711,7 @@ function dereferenceRequestBody(swagger) {
|
|
|
711
711
|
resultType: "all"
|
|
712
712
|
});
|
|
713
713
|
for (const match of matches) {
|
|
714
|
-
const value =
|
|
714
|
+
const value = OpenapiUtils.dereference(match.value.$ref, swagger);
|
|
715
715
|
import_jsonpointer2.default.set(swagger, match.pointer, value);
|
|
716
716
|
}
|
|
717
717
|
}
|
|
@@ -729,7 +729,7 @@ function dereferenceResponses(swagger) {
|
|
|
729
729
|
})
|
|
730
730
|
];
|
|
731
731
|
for (const match of matches) {
|
|
732
|
-
const value =
|
|
732
|
+
const value = OpenapiUtils.dereference(match.value.$ref, swagger);
|
|
733
733
|
import_jsonpointer2.default.set(swagger, match.pointer, value);
|
|
734
734
|
}
|
|
735
735
|
}
|
|
@@ -740,7 +740,7 @@ function dereferenceParameters(swagger) {
|
|
|
740
740
|
resultType: "all"
|
|
741
741
|
});
|
|
742
742
|
for (const match of matches) {
|
|
743
|
-
const value =
|
|
743
|
+
const value = OpenapiUtils.dereference(match.value.$ref, swagger);
|
|
744
744
|
import_jsonpointer2.default.set(swagger, match.pointer, value);
|
|
745
745
|
}
|
|
746
746
|
}
|
|
@@ -753,7 +753,7 @@ function dereferenceOperation(swagger) {
|
|
|
753
753
|
return removeUndefinedRef(shadow);
|
|
754
754
|
}
|
|
755
755
|
|
|
756
|
-
// src/utils/
|
|
756
|
+
// src/utils/openapi-utils/update-operation-id.ts
|
|
757
757
|
var R10 = __toESM(require("ramda"), 1);
|
|
758
758
|
function updateOperationId(swagger, fn) {
|
|
759
759
|
const shadow = R10.clone(swagger);
|
|
@@ -800,7 +800,7 @@ var JsonSchemaUtils = class {
|
|
|
800
800
|
static isMixed = isMixed;
|
|
801
801
|
};
|
|
802
802
|
|
|
803
|
-
// src/utils/
|
|
803
|
+
// src/utils/openapi-utils/dereference-deep.ts
|
|
804
804
|
function dereferenceDeep($ref, swagger) {
|
|
805
805
|
const stack = [$ref];
|
|
806
806
|
let value;
|
|
@@ -820,8 +820,8 @@ function dereferenceDeep($ref, swagger) {
|
|
|
820
820
|
return value;
|
|
821
821
|
}
|
|
822
822
|
|
|
823
|
-
// src/utils/
|
|
824
|
-
var
|
|
823
|
+
// src/utils/openapi-utils/index.ts
|
|
824
|
+
var OpenapiUtils = class {
|
|
825
825
|
static isRefDefined = isRefDefined;
|
|
826
826
|
static dereference = dereference;
|
|
827
827
|
static dereferenceDeep = dereferenceDeep;
|
|
@@ -833,10 +833,10 @@ var SwaggerUtils = class {
|
|
|
833
833
|
// src/tasks/utils/api-document.ts
|
|
834
834
|
var ApiDocument = class _ApiDocument {
|
|
835
835
|
module;
|
|
836
|
-
|
|
837
|
-
constructor(
|
|
836
|
+
specification;
|
|
837
|
+
constructor(specification, module2) {
|
|
838
838
|
this.module = module2;
|
|
839
|
-
this.
|
|
839
|
+
this.specification = specification;
|
|
840
840
|
}
|
|
841
841
|
static cache = /* @__PURE__ */ new Map();
|
|
842
842
|
static async download(url) {
|
|
@@ -847,14 +847,14 @@ var ApiDocument = class _ApiDocument {
|
|
|
847
847
|
content = await res.text();
|
|
848
848
|
} catch (e) {
|
|
849
849
|
if (e instanceof Error) {
|
|
850
|
-
e.message = `Unable get the swagger file from ${url}: ${e.message}`;
|
|
850
|
+
e.message = `Unable get the openapi/swagger file from ${url}: ${e.message}`;
|
|
851
851
|
}
|
|
852
852
|
throw e;
|
|
853
853
|
}
|
|
854
854
|
try {
|
|
855
855
|
return JSON.parse(content);
|
|
856
856
|
} catch (e) {
|
|
857
|
-
throw new Error(`The swagger file get from url isn't json: ${url}`);
|
|
857
|
+
throw new Error(`The openapi/swagger file get from url isn't json: ${url}`);
|
|
858
858
|
}
|
|
859
859
|
}
|
|
860
860
|
static async read(filePath) {
|
|
@@ -872,17 +872,17 @@ var ApiDocument = class _ApiDocument {
|
|
|
872
872
|
if (this.cache.has(moduleDefinition.address)) {
|
|
873
873
|
return this.cache.get(moduleDefinition.address);
|
|
874
874
|
}
|
|
875
|
-
const
|
|
876
|
-
return new _ApiDocument(
|
|
875
|
+
const openapi = validUrl.isUri(address) ? await this.download(address) : await this.read(address);
|
|
876
|
+
return new _ApiDocument(openapi, moduleDefinition);
|
|
877
877
|
}
|
|
878
878
|
async validate() {
|
|
879
|
-
return await (0, import_openapi_parser.validate)(this.
|
|
879
|
+
return await (0, import_openapi_parser.validate)(this.specification);
|
|
880
880
|
}
|
|
881
881
|
// remove chinese and special symbols
|
|
882
882
|
fix() {
|
|
883
|
-
const
|
|
883
|
+
const openapi = (0, import_swagger_fix.fixSwagger)(this.specification);
|
|
884
884
|
return new _ApiDocument(
|
|
885
|
-
|
|
885
|
+
openapi,
|
|
886
886
|
new ModuleDefinition(
|
|
887
887
|
this.module.name,
|
|
888
888
|
`file://${this.module.name}.fixed.json`
|
|
@@ -892,22 +892,22 @@ var ApiDocument = class _ApiDocument {
|
|
|
892
892
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
893
893
|
async toV3_1(rc) {
|
|
894
894
|
const debug = new Debugger(rc);
|
|
895
|
-
let
|
|
896
|
-
const { specification } = (0, import_openapi_parser.upgrade)(
|
|
897
|
-
|
|
898
|
-
debug.
|
|
899
|
-
|
|
900
|
-
debug.
|
|
895
|
+
let spec = this.specification;
|
|
896
|
+
const { specification } = (0, import_openapi_parser.upgrade)(spec);
|
|
897
|
+
spec = specification;
|
|
898
|
+
debug.writeOpenapi(`.keq/${this.module.name}.3_1.json`, spec);
|
|
899
|
+
spec = OpenapiUtils.dereferenceOperation(spec);
|
|
900
|
+
debug.writeOpenapi(`.keq/${this.module.name}.3_1.sharked.json`, spec);
|
|
901
901
|
if (rc?.operationIdFactory) {
|
|
902
902
|
const operationIdFactory = rc.operationIdFactory;
|
|
903
|
-
|
|
904
|
-
|
|
903
|
+
spec = OpenapiUtils.updateOperationId(
|
|
904
|
+
spec,
|
|
905
905
|
(method, pathname, operation) => operationIdFactory({ method, pathname, operation, module: this.module })
|
|
906
906
|
);
|
|
907
|
-
debug.
|
|
907
|
+
debug.writeOpenapi(`.keq/${this.module.name}.3_1.formatted.json`, spec);
|
|
908
908
|
}
|
|
909
909
|
return new ApiDocumentV3_1(
|
|
910
|
-
|
|
910
|
+
spec,
|
|
911
911
|
new ModuleDefinition(
|
|
912
912
|
this.module.name,
|
|
913
913
|
`file://${this.module.name}.v3_1.json`
|
|
@@ -993,12 +993,12 @@ function main3() {
|
|
|
993
993
|
task: async (ctx, task2) => {
|
|
994
994
|
const { valid, errors } = await document.validate();
|
|
995
995
|
if (!valid) {
|
|
996
|
-
const message = `${document.module.name} module swagger file does not conform to the openapi@3.1 standard specifications or have grammatical errors, which may cause unexpected errors:
|
|
996
|
+
const message = `${document.module.name} module openapi/swagger file does not conform to the openapi@3.1 standard specifications or have grammatical errors, which may cause unexpected errors:
|
|
997
997
|
${errors?.map((e) => ` - ${e.message}`).join("\n")}`;
|
|
998
998
|
task2.output = message;
|
|
999
999
|
}
|
|
1000
1000
|
const fixedDocument = document.fix();
|
|
1001
|
-
debug.
|
|
1001
|
+
debug.writeOpenapi(`.keq/${document.module.name}.fixed.json`, fixedDocument.specification);
|
|
1002
1002
|
const v3_1Document = await fixedDocument.toV3_1(rc);
|
|
1003
1003
|
ctx.validated.documents.push(v3_1Document);
|
|
1004
1004
|
}
|
|
@@ -1673,7 +1673,7 @@ function parameterBodies(operationDefinition, alias = R15.identity, typeName) {
|
|
|
1673
1673
|
if (operation.requestBody && !JsonSchemaUtils.isRef(operation.requestBody)) {
|
|
1674
1674
|
const $mediaTypes = Object.entries(operation.requestBody.content || {}).map(([mediaType, mediaTypeObject]) => [mediaType, mediaTypeObject.schema]).map(([mediaType, schemaOrRef]) => {
|
|
1675
1675
|
if (!schemaOrRef) return `${JSON.stringify(mediaType)}: unknown`;
|
|
1676
|
-
const schema = JsonSchemaUtils.isRef(schemaOrRef) ?
|
|
1676
|
+
const schema = JsonSchemaUtils.isRef(schemaOrRef) ? OpenapiUtils.dereferenceDeep(schemaOrRef.$ref, operationDefinition.document.specification) : schemaOrRef;
|
|
1677
1677
|
if (schema.type === "object" || schema.properties) {
|
|
1678
1678
|
return `${JSON.stringify(mediaType)}: ${generateSchema(schemaOrRef, alias)} & { [key: string]: any }`;
|
|
1679
1679
|
}
|
|
@@ -1773,7 +1773,7 @@ function errorToComment(err, mediaType) {
|
|
|
1773
1773
|
function requestBodyFormDataPropertyRenderer(propertyName, propertySchema, mediaType, operationDefinition) {
|
|
1774
1774
|
try {
|
|
1775
1775
|
const $propertyName = JSON.stringify(propertyName);
|
|
1776
|
-
const schema = JsonSchemaUtils.isRef(propertySchema) ?
|
|
1776
|
+
const schema = JsonSchemaUtils.isRef(propertySchema) ? OpenapiUtils.dereferenceDeep(propertySchema.$ref, operationDefinition.document.specification) : propertySchema;
|
|
1777
1777
|
if (schema.type === "string" && schema.format === "binary" || schema.contentMediaType === "application/octet-stream") {
|
|
1778
1778
|
return `if (args && ${$propertyName} in args && args[${$propertyName}]) req.attach(${$propertyName}, args[${$propertyName}])`;
|
|
1779
1779
|
} else if (schema.type === "string" || schema.type === "array" && schema.items && schema.items.type === "string") {
|
|
@@ -1802,7 +1802,7 @@ function requestBodyRenderer(operationDefinition, typeName) {
|
|
|
1802
1802
|
const $requestBody = Object.entries(requestBodyContent).map(([mediaType, mediaTypeObject]) => {
|
|
1803
1803
|
if (!mediaTypeObject.schema) return;
|
|
1804
1804
|
try {
|
|
1805
|
-
const schema = JsonSchemaUtils.isRef(mediaTypeObject.schema) ?
|
|
1805
|
+
const schema = JsonSchemaUtils.isRef(mediaTypeObject.schema) ? OpenapiUtils.dereferenceDeep(mediaTypeObject.schema.$ref, operationDefinition.document.specification) : mediaTypeObject.schema;
|
|
1806
1806
|
if (schema.type !== "object") return;
|
|
1807
1807
|
const properties = schema.properties || {};
|
|
1808
1808
|
return Object.entries(properties).map(([propertyName, propertySchema]) => {
|
|
@@ -2334,7 +2334,7 @@ if (import_semver.default.lt(process.version, "18.0.0")) {
|
|
|
2334
2334
|
throw new Error("Node.js version must be greater than 18");
|
|
2335
2335
|
}
|
|
2336
2336
|
var program = new import_commander.Command();
|
|
2337
|
-
program.command("build").option("-c --config <config>", "The keq-cli config file").option("--module <modules...>", "Filter module(s) to generate").option("--debug", "Print debug information").option("--tolerant", "Tolerate wrong swagger structure").option("-i --interactive", "Interactive select the scope of generation").action(async (options) => {
|
|
2337
|
+
program.command("build").option("-c --config <config>", "The keq-cli config file").option("--module <modules...>", "Filter module(s) to generate").option("--debug", "Print debug information").option("--tolerant", "Tolerate wrong swagger/openapi structure").option("-i --interactive", "Interactive select the scope of generation").action(async (options) => {
|
|
2338
2338
|
const compiler = new Compiler({
|
|
2339
2339
|
build: {
|
|
2340
2340
|
shaking: {
|