@shopware/api-gen 1.0.1 → 1.0.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/README.md +4 -3
- package/dist/cli.mjs +37 -11
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -233,9 +233,10 @@ Prepare your config file named **api-gen.config.json**:
|
|
|
233
233
|
|
|
234
234
|
Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/api-gen/CHANGELOG.md)
|
|
235
235
|
|
|
236
|
-
### Latest changes: 1.0.
|
|
236
|
+
### Latest changes: 1.0.2
|
|
237
237
|
|
|
238
238
|
### Patch Changes
|
|
239
239
|
|
|
240
|
-
-
|
|
241
|
-
|
|
240
|
+
- [#1082](https://github.com/shopware/frontends/pull/1082) [`db42df4`](https://github.com/shopware/frontends/commit/db42df4aef6fcb5113d058fa5821274b58077407) Thanks [@patzick](https://github.com/patzick)! - `COMPONENTS_API_ALIAS` rule - additional message suggesting that the schema component name might be incorrect
|
|
241
|
+
|
|
242
|
+
- [#1082](https://github.com/shopware/frontends/pull/1082) [`db42df4`](https://github.com/shopware/frontends/commit/db42df4aef6fcb5113d058fa5821274b58077407) Thanks [@patzick](https://github.com/patzick)! - Correct api overrides load, depending on the apiType
|
package/dist/cli.mjs
CHANGED
|
@@ -214059,12 +214059,20 @@ async function loadApiGenConfig(params = {}) {
|
|
|
214059
214059
|
function isURL(str) {
|
|
214060
214060
|
return str.startsWith("http");
|
|
214061
214061
|
}
|
|
214062
|
-
async function loadJsonOverrides(
|
|
214063
|
-
|
|
214062
|
+
async function loadJsonOverrides({
|
|
214063
|
+
path,
|
|
214064
|
+
apiType
|
|
214065
|
+
}) {
|
|
214066
|
+
const localPath = `./api-types/${apiType}ApiSchema.overrides.json`;
|
|
214067
|
+
const fallbackPath = existsSync(localPath) ? localPath : `https://raw.githubusercontent.com/shopware/frontends/main/packages/api-client/api-types/${apiType}ApiSchema.overrides.json`;
|
|
214068
|
+
const pathToResolve = path || fallbackPath;
|
|
214069
|
+
console.log("Loading overrides from:", pathToResolve);
|
|
214064
214070
|
try {
|
|
214065
214071
|
if (isURL(pathToResolve)) {
|
|
214066
|
-
const response = await ofetch(pathToResolve
|
|
214067
|
-
|
|
214072
|
+
const response = await ofetch(pathToResolve, {
|
|
214073
|
+
responseType: "json"
|
|
214074
|
+
});
|
|
214075
|
+
return response;
|
|
214068
214076
|
} else {
|
|
214069
214077
|
const jsonOverridesFile = await readFileSync(pathToResolve, {
|
|
214070
214078
|
encoding: "utf-8"
|
|
@@ -214167,7 +214175,10 @@ async function generate(args) {
|
|
|
214167
214175
|
silent: true
|
|
214168
214176
|
// we allow to not have the config file in this command
|
|
214169
214177
|
});
|
|
214170
|
-
const jsonOverrides = await loadJsonOverrides(
|
|
214178
|
+
const jsonOverrides = await loadJsonOverrides({
|
|
214179
|
+
path: configJSON?.patches,
|
|
214180
|
+
apiType: args.apiType
|
|
214181
|
+
});
|
|
214171
214182
|
const {
|
|
214172
214183
|
patchedSchema,
|
|
214173
214184
|
todosToFix,
|
|
@@ -214342,7 +214353,7 @@ async function generate(args) {
|
|
|
214342
214353
|
}
|
|
214343
214354
|
|
|
214344
214355
|
const name = "@shopware/api-gen";
|
|
214345
|
-
const version = "1.0.
|
|
214356
|
+
const version = "1.0.2";
|
|
214346
214357
|
const description = "Shopware CLI for API client generation.";
|
|
214347
214358
|
const author = "Shopware";
|
|
214348
214359
|
const type = "module";
|
|
@@ -214568,6 +214579,12 @@ function splitByCase(str, separators) {
|
|
|
214568
214579
|
parts.push(buff);
|
|
214569
214580
|
return parts;
|
|
214570
214581
|
}
|
|
214582
|
+
function upperFirst(str) {
|
|
214583
|
+
return str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
214584
|
+
}
|
|
214585
|
+
function pascalCase(str, opts) {
|
|
214586
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
|
|
214587
|
+
}
|
|
214571
214588
|
function kebabCase(str, joiner) {
|
|
214572
214589
|
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
|
|
214573
214590
|
}
|
|
@@ -214584,11 +214601,13 @@ const componentsApiAliasRule = (componentName, body) => {
|
|
|
214584
214601
|
if (!bodyValue) {
|
|
214585
214602
|
return null;
|
|
214586
214603
|
}
|
|
214587
|
-
if (body.required && !body.required.includes("apiAlias")) {
|
|
214588
|
-
return `Component ${c$1.bold(componentName)} has invalid ${c$1.bold("apiAlias")} definition. This field should be required.`;
|
|
214589
|
-
}
|
|
214590
214604
|
const result = equals(properAliasDefinition, bodyValue);
|
|
214591
214605
|
if (!result) {
|
|
214606
|
+
let additionalMessage = "";
|
|
214607
|
+
const bodyEnumValue = bodyValue?.enum?.[0];
|
|
214608
|
+
if (bodyEnumValue && properAliasDefinition.enum[0] !== bodyEnumValue) {
|
|
214609
|
+
additionalMessage = `It's also possible, that the schema component name is not correct and apiApias is proper. In that case schema component name should be ${c$1.bold(pascalCase(bodyEnumValue))}. Confirm proper solution with the source code.`;
|
|
214610
|
+
}
|
|
214592
214611
|
return `Component ${c$1.bold(componentName)} has invalid ${c$1.bold("apiAlias")} definition. Diff:
|
|
214593
214612
|
${diff(
|
|
214594
214613
|
properAliasDefinition,
|
|
@@ -214597,7 +214616,11 @@ const componentsApiAliasRule = (componentName, body) => {
|
|
|
214597
214616
|
aColor: c$1.green,
|
|
214598
214617
|
bColor: c$1.red
|
|
214599
214618
|
}
|
|
214600
|
-
)}
|
|
214619
|
+
)}${additionalMessage.length ? `
|
|
214620
|
+
${additionalMessage}` : ""}`;
|
|
214621
|
+
}
|
|
214622
|
+
if (!body.required?.includes("apiAlias")) {
|
|
214623
|
+
return `Component ${c$1.bold(componentName)} has invalid ${c$1.bold("apiAlias")} definition. This field should be required.`;
|
|
214601
214624
|
}
|
|
214602
214625
|
return null;
|
|
214603
214626
|
};
|
|
@@ -214639,7 +214662,10 @@ async function validateJson(args) {
|
|
|
214639
214662
|
process.exit(1);
|
|
214640
214663
|
}
|
|
214641
214664
|
const errors = [];
|
|
214642
|
-
const jsonOverrides = await loadJsonOverrides(
|
|
214665
|
+
const jsonOverrides = await loadJsonOverrides({
|
|
214666
|
+
path: configJSON.patches,
|
|
214667
|
+
apiType: args.apiType
|
|
214668
|
+
});
|
|
214643
214669
|
Object.entries(fileContentAsJson.components?.schemas || {}).forEach(
|
|
214644
214670
|
(schema) => {
|
|
214645
214671
|
rulesToProcess.forEach((ruleName) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopware/api-gen",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Shopware CLI for API client generation.",
|
|
5
5
|
"author": "Shopware",
|
|
6
6
|
"type": "module",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"picocolors": "1.0.1",
|
|
36
36
|
"unbuild": "2.0.0",
|
|
37
37
|
"vitest": "1.6.0",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
38
|
+
"tsconfig": "0.0.0",
|
|
39
|
+
"eslint-config-shopware": "0.0.9"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"ofetch": "1.3.4",
|