@moccona/apicodegen 0.0.10 → 0.0.11
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/bin/cli.cjs +4 -4
- package/npm/index.cjs +8 -8
- package/npm/index.cjs.map +1 -1
- package/npm/index.mjs +8 -8
- package/npm/index.mjs.map +1 -1
- package/npm/vite/index.mjs +8 -8
- package/npm/vite/index.mjs.map +1 -1
- package/package.json +1 -1
package/npm/index.mjs
CHANGED
|
@@ -701,7 +701,7 @@ var Generator = class Generator {
|
|
|
701
701
|
static toUrlTemplate(path, parameters, basePath = "") {
|
|
702
702
|
const queryParameters = parameters.filter((p) => p.in === "query");
|
|
703
703
|
if (queryParameters.length > 0) {
|
|
704
|
-
const queryString = queryParameters.map((qp, index) => `${index === 0 ? "?" : "&"}${encodeURIComponent(qp.name)}={${Base.
|
|
704
|
+
const queryString = queryParameters.map((qp, index) => `${index === 0 ? "?" : "&"}${encodeURIComponent(qp.name)}={${Base.normalize(qp.name)}}`).join("");
|
|
705
705
|
path += queryString;
|
|
706
706
|
}
|
|
707
707
|
const pathSegments = path.replaceAll("{", "${").split("$").filter(Boolean);
|
|
@@ -710,7 +710,7 @@ var Generator = class Generator {
|
|
|
710
710
|
const match = /^{(.+)}(.+)?/gm.exec(segment);
|
|
711
711
|
const isLastSegment = index === pathSegments.length - 2;
|
|
712
712
|
if (!match) throw new Error(`Invalid path segment: ${segment}`);
|
|
713
|
-
return factory.createTemplateSpan(factory.createIdentifier(match[1]), !isLastSegment ? factory.createTemplateMiddle(match[2]) : factory.createTemplateTail(match[2] || ""));
|
|
713
|
+
return factory.createTemplateSpan(factory.createIdentifier(Base.normalize(match[1])), !isLastSegment ? factory.createTemplateMiddle(match[2]) : factory.createTemplateTail(match[2] || ""));
|
|
714
714
|
}));
|
|
715
715
|
}
|
|
716
716
|
/**
|
|
@@ -762,7 +762,7 @@ var Generator = class Generator {
|
|
|
762
762
|
static generateParamTags(parameters, requestBody) {
|
|
763
763
|
const tags = [];
|
|
764
764
|
for (const p of parameters) {
|
|
765
|
-
const paramName = Base.
|
|
765
|
+
const paramName = Base.normalize(p.name);
|
|
766
766
|
let paramType = "unknown";
|
|
767
767
|
if (p.schema) paramType = Generator.schemaToTypeString(p.schema);
|
|
768
768
|
const isOptional = p.required === false;
|
|
@@ -846,11 +846,11 @@ var Generator = class Generator {
|
|
|
846
846
|
const refParameters = [];
|
|
847
847
|
for (const parameter of parameters) if (parameter.ref) {
|
|
848
848
|
const refName = Base.ref2name(parameter.ref);
|
|
849
|
-
refParameters.push(factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier(Base.
|
|
849
|
+
refParameters.push(factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier(Base.normalize(refName)), void 0, factory.createTypeReferenceNode(factory.createIdentifier(Base.upperCamelCase(Base.normalize(refName)))), void 0));
|
|
850
850
|
} else {
|
|
851
851
|
const { name, schema, required } = parameter;
|
|
852
|
-
objectElements.push(factory.createBindingElement(void 0, void 0, factory.createIdentifier(Base.
|
|
853
|
-
typeObjectElements.push(factory.createPropertySignature([], factory.createIdentifier(Base.
|
|
852
|
+
objectElements.push(factory.createBindingElement(void 0, void 0, factory.createIdentifier(Base.normalize(name))));
|
|
853
|
+
typeObjectElements.push(factory.createPropertySignature([], factory.createIdentifier(Base.normalize(name)), required ? void 0 : factory.createToken(SyntaxKind.QuestionToken), !schema ? factory.createToken(SyntaxKind.UnknownKeyword) : Generator.toTypeNode(schema)));
|
|
854
854
|
}
|
|
855
855
|
if (objectElements.length > 0) return [factory.createParameterDeclaration(void 0, void 0, factory.createObjectBindingPattern(objectElements), void 0, factory.createTypeLiteralNode(typeObjectElements), void 0), ...refParameters];
|
|
856
856
|
return refParameters;
|
|
@@ -976,7 +976,7 @@ var AxiosAdapter = class extends Adapter {
|
|
|
976
976
|
* @returns - The constructed fetch options object
|
|
977
977
|
*/
|
|
978
978
|
const toLiterlExpression = () => {
|
|
979
|
-
return factory.createObjectLiteralExpression([factory.createPropertyAssignment(factory.createIdentifier(adapter.methodFieldName), factory.createStringLiteral(method.toUpperCase()))].concat(inHeader.length > 0 ? factory.createPropertyAssignment(factory.createIdentifier(adapter.headersFieldName), factory.createObjectLiteralExpression(inHeader.map((p) => factory.createPropertyAssignment(factory.createStringLiteral(p.name), factory.createCallExpression(factory.createIdentifier("encodeURIComponent"), void 0, [factory.createCallExpression(factory.createIdentifier("String"), void 0, [factory.createIdentifier(Base.
|
|
979
|
+
return factory.createObjectLiteralExpression([factory.createPropertyAssignment(factory.createIdentifier(adapter.methodFieldName), factory.createStringLiteral(method.toUpperCase()))].concat(inHeader.length > 0 ? factory.createPropertyAssignment(factory.createIdentifier(adapter.headersFieldName), factory.createObjectLiteralExpression(inHeader.map((p) => factory.createPropertyAssignment(factory.createStringLiteral(p.name), factory.createCallExpression(factory.createIdentifier("encodeURIComponent"), void 0, [factory.createCallExpression(factory.createIdentifier("String"), void 0, [factory.createIdentifier(Base.normalize(p.name))])]))))) : []).concat(shouldUseFormData || inBody.length > 0 || requestBody?.schema ? factory.createPropertyAssignment(factory.createIdentifier(adapter.bodyFieldName), shouldUseFormData ? factory.createIdentifier("fd") : inBody.length > 0 || requestBody?.schema && !Generator.isBinarySchema(requestBody.schema) ? factory.createIdentifier("req") : factory.createIdentifier("req")) : []), true);
|
|
980
980
|
};
|
|
981
981
|
statements.push(factory.createReturnStatement(factory.createCallExpression(factory.createIdentifier(adapter.name), response?.schema ? [Generator.toTypeNode(response.schema)] : void 0, [Generator.toUrlTemplate(uri, parameters), toLiterlExpression()])));
|
|
982
982
|
return statements;
|
|
@@ -1016,7 +1016,7 @@ var FetchAdapter = class extends Adapter {
|
|
|
1016
1016
|
* @returns - The constructed fetch options object
|
|
1017
1017
|
*/
|
|
1018
1018
|
const toLiterlExpression = () => {
|
|
1019
|
-
return factory.createObjectLiteralExpression([factory.createPropertyAssignment(factory.createIdentifier(adapter.methodFieldName), factory.createStringLiteral(method.toUpperCase()))].concat(inHeader.length > 0 ? factory.createPropertyAssignment(factory.createIdentifier(adapter.headersFieldName), factory.createObjectLiteralExpression(inHeader.map((p) => factory.createPropertyAssignment(factory.createStringLiteral(p.name), factory.createCallExpression(factory.createIdentifier("encodeURIComponent"), void 0, [factory.createCallExpression(factory.createIdentifier("String"), void 0, [factory.createIdentifier(Base.
|
|
1019
|
+
return factory.createObjectLiteralExpression([factory.createPropertyAssignment(factory.createIdentifier(adapter.methodFieldName), factory.createStringLiteral(method.toUpperCase()))].concat(inHeader.length > 0 ? factory.createPropertyAssignment(factory.createIdentifier(adapter.headersFieldName), factory.createObjectLiteralExpression(inHeader.map((p) => factory.createPropertyAssignment(factory.createStringLiteral(p.name), factory.createCallExpression(factory.createIdentifier("encodeURIComponent"), void 0, [factory.createCallExpression(factory.createIdentifier("String"), void 0, [factory.createIdentifier(Base.normalize(p.name))])]))))) : []).concat(shouldUseFormData || inBody.length > 0 || requestBody?.schema ? factory.createPropertyAssignment(factory.createIdentifier(adapter.bodyFieldName), shouldUseFormData ? factory.createIdentifier("fd") : inBody.length > 0 || requestBody?.schema && !Generator.isBinarySchema(requestBody.schema) ? factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("JSON"), factory.createIdentifier("stringify")), [], [requestBody ? factory.createIdentifier("req") : factory.createObjectLiteralExpression(inBody.map((b) => factory.createShorthandPropertyAssignment(factory.createIdentifier(b.name))), true)]) : factory.createIdentifier("req")) : []), true);
|
|
1020
1020
|
};
|
|
1021
1021
|
statements.push(factory.createReturnStatement(shouldUseJSONResponse ? factory.createCallExpression(factory.createPropertyAccessExpression(factory.createCallExpression(factory.createIdentifier(adapter.name), void 0, [Generator.toUrlTemplate(uri, parameters), toLiterlExpression()]), factory.createIdentifier("then")), void 0, [factory.createArrowFunction([factory.createModifier(SyntaxKind.AsyncKeyword)], [], [factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("response"))], void 0, factory.createToken(SyntaxKind.EqualsGreaterThanToken), response?.schema ? factory.createAsExpression(factory.createParenthesizedExpression(factory.createAwaitExpression(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("response"), factory.createIdentifier("json")), void 0, []))), response?.schema ? Generator.toTypeNode(response.schema) : factory.createToken(SyntaxKind.UnknownKeyword)) : factory.createParenthesizedExpression(factory.createAwaitExpression(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("response"), factory.createIdentifier("json")), void 0, []))))]) : factory.createCallExpression(factory.createIdentifier(adapter.name), void 0, [Generator.toUrlTemplate(uri, parameters), toLiterlExpression()])));
|
|
1022
1022
|
return statements;
|