@keq-request/cli 5.0.0-alpha.18 → 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 +7 -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/dist/index.cjs
CHANGED
|
@@ -114,7 +114,7 @@ var RuntimeConfig = import_typebox2.Type.Object({
|
|
|
114
114
|
])),
|
|
115
115
|
debug: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
|
|
116
116
|
/**
|
|
117
|
-
* Whether to tolerate wrong swagger structure
|
|
117
|
+
* Whether to tolerate wrong openapi/swagger structure
|
|
118
118
|
*/
|
|
119
119
|
tolerant: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
|
|
120
120
|
plugins: import_typebox2.Type.Optional(import_typebox2.Type.Array(import_typebox2.Type.Any(), { default: [] }))
|
|
@@ -580,14 +580,14 @@ var logger = {
|
|
|
580
580
|
var import_openapi_shaking = require("@opendoc/openapi-shaking");
|
|
581
581
|
var ApiDocumentV3_1 = class _ApiDocumentV3_1 {
|
|
582
582
|
module;
|
|
583
|
-
|
|
584
|
-
constructor(
|
|
583
|
+
specification;
|
|
584
|
+
constructor(specification, module2) {
|
|
585
585
|
this.module = module2;
|
|
586
|
-
this.
|
|
586
|
+
this.specification = specification;
|
|
587
587
|
}
|
|
588
588
|
get schemas() {
|
|
589
589
|
const module2 = this.module;
|
|
590
|
-
return Object.entries(this.
|
|
590
|
+
return Object.entries(this.specification.components?.schemas || {}).map(([name, schema]) => new SchemaDefinition({
|
|
591
591
|
id: `#/components/schemas/${name}`,
|
|
592
592
|
name,
|
|
593
593
|
schema,
|
|
@@ -597,7 +597,7 @@ var ApiDocumentV3_1 = class _ApiDocumentV3_1 {
|
|
|
597
597
|
}
|
|
598
598
|
get operations() {
|
|
599
599
|
const module2 = this.module;
|
|
600
|
-
return Object.entries(this.
|
|
600
|
+
return Object.entries(this.specification.paths || {}).flatMap(([pathname, pathItem]) => Object.entries(pathItem || {}).filter(([method]) => SupportedMethods.includes(method.toLowerCase())).map(([method, operation]) => new OperationDefinition({
|
|
601
601
|
method,
|
|
602
602
|
pathname,
|
|
603
603
|
operation,
|
|
@@ -606,18 +606,18 @@ var ApiDocumentV3_1 = class _ApiDocumentV3_1 {
|
|
|
606
606
|
})));
|
|
607
607
|
}
|
|
608
608
|
isEmpty() {
|
|
609
|
-
return R6.isEmpty(this.
|
|
609
|
+
return R6.isEmpty(this.specification.paths);
|
|
610
610
|
}
|
|
611
611
|
dereference($ref) {
|
|
612
612
|
if ($ref.startsWith("#/")) {
|
|
613
613
|
return this.schemas.find((schema) => schema.id === $ref);
|
|
614
614
|
}
|
|
615
|
-
logger.warn(`The $ref(${$ref}) is not defined in ${this.module.name} swagger.`);
|
|
615
|
+
logger.warn(`The $ref(${$ref}) is not defined in ${this.module.name} openapi/swagger.`);
|
|
616
616
|
}
|
|
617
617
|
isRefDefined($ref) {
|
|
618
618
|
if ($ref.startsWith("#/")) {
|
|
619
619
|
const path9 = $ref.replace("#/", "").split("/");
|
|
620
|
-
return R6.path(path9, this.
|
|
620
|
+
return R6.path(path9, this.specification) !== void 0;
|
|
621
621
|
}
|
|
622
622
|
return false;
|
|
623
623
|
}
|
|
@@ -634,7 +634,7 @@ var ApiDocumentV3_1 = class _ApiDocumentV3_1 {
|
|
|
634
634
|
return filter2(operationDefinition);
|
|
635
635
|
};
|
|
636
636
|
const sharkedSwagger = (0, import_openapi_shaking.openapiShakingSync)(
|
|
637
|
-
this.
|
|
637
|
+
this.specification,
|
|
638
638
|
isAccepted,
|
|
639
639
|
{ tolerant: true }
|
|
640
640
|
);
|
|
@@ -657,14 +657,14 @@ var Debugger = class {
|
|
|
657
657
|
constructor(rc) {
|
|
658
658
|
this.rc = rc;
|
|
659
659
|
}
|
|
660
|
-
|
|
660
|
+
writeOpenapi(fullpath, openapi) {
|
|
661
661
|
if (this.rc?.debug) {
|
|
662
|
-
void import_fs_extra3.default.writeJSON(fullpath,
|
|
662
|
+
void import_fs_extra3.default.writeJSON(fullpath, openapi, { spaces: 2 });
|
|
663
663
|
}
|
|
664
664
|
}
|
|
665
665
|
};
|
|
666
666
|
|
|
667
|
-
// src/utils/
|
|
667
|
+
// src/utils/openapi-utils/dereference.ts
|
|
668
668
|
function dereference($ref, swagger) {
|
|
669
669
|
let value;
|
|
670
670
|
for (const key of $ref.split("/")) {
|
|
@@ -678,17 +678,17 @@ function dereference($ref, swagger) {
|
|
|
678
678
|
return value;
|
|
679
679
|
}
|
|
680
680
|
|
|
681
|
-
// src/utils/
|
|
681
|
+
// src/utils/openapi-utils/dereference-operation.ts
|
|
682
682
|
var R9 = __toESM(require("ramda"), 1);
|
|
683
683
|
var import_jsonpointer2 = __toESM(require("jsonpointer"), 1);
|
|
684
684
|
var import_jsonpath_plus4 = require("jsonpath-plus");
|
|
685
685
|
|
|
686
|
-
// src/utils/
|
|
686
|
+
// src/utils/openapi-utils/remove-undefined-ref.ts
|
|
687
687
|
var R8 = __toESM(require("ramda"), 1);
|
|
688
688
|
var import_jsonpointer = __toESM(require("jsonpointer"), 1);
|
|
689
689
|
var import_jsonpath_plus3 = require("jsonpath-plus");
|
|
690
690
|
|
|
691
|
-
// src/utils/
|
|
691
|
+
// src/utils/openapi-utils/is-ref-defined.ts
|
|
692
692
|
var R7 = __toESM(require("ramda"), 1);
|
|
693
693
|
function isRefDefined($ref, swagger) {
|
|
694
694
|
if ($ref.startsWith("#/")) {
|
|
@@ -698,7 +698,7 @@ function isRefDefined($ref, swagger) {
|
|
|
698
698
|
return false;
|
|
699
699
|
}
|
|
700
700
|
|
|
701
|
-
// src/utils/
|
|
701
|
+
// src/utils/openapi-utils/remove-undefined-ref.ts
|
|
702
702
|
function removeUndefinedRef(swagger) {
|
|
703
703
|
const shadow = R8.clone(swagger);
|
|
704
704
|
const matches = (0, import_jsonpath_plus3.JSONPath)({
|
|
@@ -714,7 +714,7 @@ function removeUndefinedRef(swagger) {
|
|
|
714
714
|
return shadow;
|
|
715
715
|
}
|
|
716
716
|
|
|
717
|
-
// src/utils/
|
|
717
|
+
// src/utils/openapi-utils/dereference-operation.ts
|
|
718
718
|
function dereferencePathObject(swagger) {
|
|
719
719
|
const matches = (0, import_jsonpath_plus4.JSONPath)({
|
|
720
720
|
path: "$.paths.*.$ref^",
|
|
@@ -722,7 +722,7 @@ function dereferencePathObject(swagger) {
|
|
|
722
722
|
resultType: "all"
|
|
723
723
|
});
|
|
724
724
|
for (const match of matches) {
|
|
725
|
-
const value =
|
|
725
|
+
const value = OpenapiUtils.dereference(match.value.$ref, swagger);
|
|
726
726
|
import_jsonpointer2.default.set(swagger, match.pointer, value);
|
|
727
727
|
}
|
|
728
728
|
}
|
|
@@ -733,7 +733,7 @@ function dereferenceRequestBody(swagger) {
|
|
|
733
733
|
resultType: "all"
|
|
734
734
|
});
|
|
735
735
|
for (const match of matches) {
|
|
736
|
-
const value =
|
|
736
|
+
const value = OpenapiUtils.dereference(match.value.$ref, swagger);
|
|
737
737
|
import_jsonpointer2.default.set(swagger, match.pointer, value);
|
|
738
738
|
}
|
|
739
739
|
}
|
|
@@ -751,7 +751,7 @@ function dereferenceResponses(swagger) {
|
|
|
751
751
|
})
|
|
752
752
|
];
|
|
753
753
|
for (const match of matches) {
|
|
754
|
-
const value =
|
|
754
|
+
const value = OpenapiUtils.dereference(match.value.$ref, swagger);
|
|
755
755
|
import_jsonpointer2.default.set(swagger, match.pointer, value);
|
|
756
756
|
}
|
|
757
757
|
}
|
|
@@ -762,7 +762,7 @@ function dereferenceParameters(swagger) {
|
|
|
762
762
|
resultType: "all"
|
|
763
763
|
});
|
|
764
764
|
for (const match of matches) {
|
|
765
|
-
const value =
|
|
765
|
+
const value = OpenapiUtils.dereference(match.value.$ref, swagger);
|
|
766
766
|
import_jsonpointer2.default.set(swagger, match.pointer, value);
|
|
767
767
|
}
|
|
768
768
|
}
|
|
@@ -775,7 +775,7 @@ function dereferenceOperation(swagger) {
|
|
|
775
775
|
return removeUndefinedRef(shadow);
|
|
776
776
|
}
|
|
777
777
|
|
|
778
|
-
// src/utils/
|
|
778
|
+
// src/utils/openapi-utils/update-operation-id.ts
|
|
779
779
|
var R10 = __toESM(require("ramda"), 1);
|
|
780
780
|
function updateOperationId(swagger, fn) {
|
|
781
781
|
const shadow = R10.clone(swagger);
|
|
@@ -822,7 +822,7 @@ var JsonSchemaUtils = class {
|
|
|
822
822
|
static isMixed = isMixed;
|
|
823
823
|
};
|
|
824
824
|
|
|
825
|
-
// src/utils/
|
|
825
|
+
// src/utils/openapi-utils/dereference-deep.ts
|
|
826
826
|
function dereferenceDeep($ref, swagger) {
|
|
827
827
|
const stack = [$ref];
|
|
828
828
|
let value;
|
|
@@ -842,8 +842,8 @@ function dereferenceDeep($ref, swagger) {
|
|
|
842
842
|
return value;
|
|
843
843
|
}
|
|
844
844
|
|
|
845
|
-
// src/utils/
|
|
846
|
-
var
|
|
845
|
+
// src/utils/openapi-utils/index.ts
|
|
846
|
+
var OpenapiUtils = class {
|
|
847
847
|
static isRefDefined = isRefDefined;
|
|
848
848
|
static dereference = dereference;
|
|
849
849
|
static dereferenceDeep = dereferenceDeep;
|
|
@@ -855,10 +855,10 @@ var SwaggerUtils = class {
|
|
|
855
855
|
// src/tasks/utils/api-document.ts
|
|
856
856
|
var ApiDocument = class _ApiDocument {
|
|
857
857
|
module;
|
|
858
|
-
|
|
859
|
-
constructor(
|
|
858
|
+
specification;
|
|
859
|
+
constructor(specification, module2) {
|
|
860
860
|
this.module = module2;
|
|
861
|
-
this.
|
|
861
|
+
this.specification = specification;
|
|
862
862
|
}
|
|
863
863
|
static cache = /* @__PURE__ */ new Map();
|
|
864
864
|
static async download(url) {
|
|
@@ -869,14 +869,14 @@ var ApiDocument = class _ApiDocument {
|
|
|
869
869
|
content = await res.text();
|
|
870
870
|
} catch (e) {
|
|
871
871
|
if (e instanceof Error) {
|
|
872
|
-
e.message = `Unable get the swagger file from ${url}: ${e.message}`;
|
|
872
|
+
e.message = `Unable get the openapi/swagger file from ${url}: ${e.message}`;
|
|
873
873
|
}
|
|
874
874
|
throw e;
|
|
875
875
|
}
|
|
876
876
|
try {
|
|
877
877
|
return JSON.parse(content);
|
|
878
878
|
} catch (e) {
|
|
879
|
-
throw new Error(`The swagger file get from url isn't json: ${url}`);
|
|
879
|
+
throw new Error(`The openapi/swagger file get from url isn't json: ${url}`);
|
|
880
880
|
}
|
|
881
881
|
}
|
|
882
882
|
static async read(filePath) {
|
|
@@ -894,17 +894,17 @@ var ApiDocument = class _ApiDocument {
|
|
|
894
894
|
if (this.cache.has(moduleDefinition.address)) {
|
|
895
895
|
return this.cache.get(moduleDefinition.address);
|
|
896
896
|
}
|
|
897
|
-
const
|
|
898
|
-
return new _ApiDocument(
|
|
897
|
+
const openapi = validUrl.isUri(address) ? await this.download(address) : await this.read(address);
|
|
898
|
+
return new _ApiDocument(openapi, moduleDefinition);
|
|
899
899
|
}
|
|
900
900
|
async validate() {
|
|
901
|
-
return await (0, import_openapi_parser.validate)(this.
|
|
901
|
+
return await (0, import_openapi_parser.validate)(this.specification);
|
|
902
902
|
}
|
|
903
903
|
// remove chinese and special symbols
|
|
904
904
|
fix() {
|
|
905
|
-
const
|
|
905
|
+
const openapi = (0, import_swagger_fix.fixSwagger)(this.specification);
|
|
906
906
|
return new _ApiDocument(
|
|
907
|
-
|
|
907
|
+
openapi,
|
|
908
908
|
new ModuleDefinition(
|
|
909
909
|
this.module.name,
|
|
910
910
|
`file://${this.module.name}.fixed.json`
|
|
@@ -914,22 +914,22 @@ var ApiDocument = class _ApiDocument {
|
|
|
914
914
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
915
915
|
async toV3_1(rc) {
|
|
916
916
|
const debug = new Debugger(rc);
|
|
917
|
-
let
|
|
918
|
-
const { specification } = (0, import_openapi_parser.upgrade)(
|
|
919
|
-
|
|
920
|
-
debug.
|
|
921
|
-
|
|
922
|
-
debug.
|
|
917
|
+
let spec = this.specification;
|
|
918
|
+
const { specification } = (0, import_openapi_parser.upgrade)(spec);
|
|
919
|
+
spec = specification;
|
|
920
|
+
debug.writeOpenapi(`.keq/${this.module.name}.3_1.json`, spec);
|
|
921
|
+
spec = OpenapiUtils.dereferenceOperation(spec);
|
|
922
|
+
debug.writeOpenapi(`.keq/${this.module.name}.3_1.sharked.json`, spec);
|
|
923
923
|
if (rc?.operationIdFactory) {
|
|
924
924
|
const operationIdFactory = rc.operationIdFactory;
|
|
925
|
-
|
|
926
|
-
|
|
925
|
+
spec = OpenapiUtils.updateOperationId(
|
|
926
|
+
spec,
|
|
927
927
|
(method, pathname, operation) => operationIdFactory({ method, pathname, operation, module: this.module })
|
|
928
928
|
);
|
|
929
|
-
debug.
|
|
929
|
+
debug.writeOpenapi(`.keq/${this.module.name}.3_1.formatted.json`, spec);
|
|
930
930
|
}
|
|
931
931
|
return new ApiDocumentV3_1(
|
|
932
|
-
|
|
932
|
+
spec,
|
|
933
933
|
new ModuleDefinition(
|
|
934
934
|
this.module.name,
|
|
935
935
|
`file://${this.module.name}.v3_1.json`
|
|
@@ -1015,12 +1015,12 @@ function main3() {
|
|
|
1015
1015
|
task: async (ctx, task2) => {
|
|
1016
1016
|
const { valid, errors } = await document.validate();
|
|
1017
1017
|
if (!valid) {
|
|
1018
|
-
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:
|
|
1018
|
+
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:
|
|
1019
1019
|
${errors?.map((e) => ` - ${e.message}`).join("\n")}`;
|
|
1020
1020
|
task2.output = message;
|
|
1021
1021
|
}
|
|
1022
1022
|
const fixedDocument = document.fix();
|
|
1023
|
-
debug.
|
|
1023
|
+
debug.writeOpenapi(`.keq/${document.module.name}.fixed.json`, fixedDocument.specification);
|
|
1024
1024
|
const v3_1Document = await fixedDocument.toV3_1(rc);
|
|
1025
1025
|
ctx.validated.documents.push(v3_1Document);
|
|
1026
1026
|
}
|
|
@@ -1695,7 +1695,7 @@ function parameterBodies(operationDefinition, alias = R15.identity, typeName) {
|
|
|
1695
1695
|
if (operation.requestBody && !JsonSchemaUtils.isRef(operation.requestBody)) {
|
|
1696
1696
|
const $mediaTypes = Object.entries(operation.requestBody.content || {}).map(([mediaType, mediaTypeObject]) => [mediaType, mediaTypeObject.schema]).map(([mediaType, schemaOrRef]) => {
|
|
1697
1697
|
if (!schemaOrRef) return `${JSON.stringify(mediaType)}: unknown`;
|
|
1698
|
-
const schema = JsonSchemaUtils.isRef(schemaOrRef) ?
|
|
1698
|
+
const schema = JsonSchemaUtils.isRef(schemaOrRef) ? OpenapiUtils.dereferenceDeep(schemaOrRef.$ref, operationDefinition.document.specification) : schemaOrRef;
|
|
1699
1699
|
if (schema.type === "object" || schema.properties) {
|
|
1700
1700
|
return `${JSON.stringify(mediaType)}: ${generateSchema(schemaOrRef, alias)} & { [key: string]: any }`;
|
|
1701
1701
|
}
|
|
@@ -1795,7 +1795,7 @@ function errorToComment(err, mediaType) {
|
|
|
1795
1795
|
function requestBodyFormDataPropertyRenderer(propertyName, propertySchema, mediaType, operationDefinition) {
|
|
1796
1796
|
try {
|
|
1797
1797
|
const $propertyName = JSON.stringify(propertyName);
|
|
1798
|
-
const schema = JsonSchemaUtils.isRef(propertySchema) ?
|
|
1798
|
+
const schema = JsonSchemaUtils.isRef(propertySchema) ? OpenapiUtils.dereferenceDeep(propertySchema.$ref, operationDefinition.document.specification) : propertySchema;
|
|
1799
1799
|
if (schema.type === "string" && schema.format === "binary" || schema.contentMediaType === "application/octet-stream") {
|
|
1800
1800
|
return `if (args && ${$propertyName} in args && args[${$propertyName}]) req.attach(${$propertyName}, args[${$propertyName}])`;
|
|
1801
1801
|
} else if (schema.type === "string" || schema.type === "array" && schema.items && schema.items.type === "string") {
|
|
@@ -1824,7 +1824,7 @@ function requestBodyRenderer(operationDefinition, typeName) {
|
|
|
1824
1824
|
const $requestBody = Object.entries(requestBodyContent).map(([mediaType, mediaTypeObject]) => {
|
|
1825
1825
|
if (!mediaTypeObject.schema) return;
|
|
1826
1826
|
try {
|
|
1827
|
-
const schema = JsonSchemaUtils.isRef(mediaTypeObject.schema) ?
|
|
1827
|
+
const schema = JsonSchemaUtils.isRef(mediaTypeObject.schema) ? OpenapiUtils.dereferenceDeep(mediaTypeObject.schema.$ref, operationDefinition.document.specification) : mediaTypeObject.schema;
|
|
1828
1828
|
if (schema.type !== "object") return;
|
|
1829
1829
|
const properties = schema.properties || {};
|
|
1830
1830
|
return Object.entries(properties).map(([propertyName, propertySchema]) => {
|