@shopware/api-gen 1.0.1 → 1.0.3

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.
Files changed (3) hide show
  1. package/README.md +6 -3
  2. package/dist/cli.mjs +60 -17
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -233,9 +233,12 @@ 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.1
236
+ ### Latest changes: 1.0.3
237
237
 
238
238
  ### Patch Changes
239
239
 
240
- - Updated dependencies [[`19f2800`](https://github.com/shopware/frontends/commit/19f28003cf937bcb630257cb7cfd2bd131b7cf9d)]:
241
- - @shopware/api-client@1.0.1
240
+ - [#1113](https://github.com/shopware/frontends/pull/1113) [`65212d1`](https://github.com/shopware/frontends/commit/65212d11bb8d0af10f97454a46e7671ff16ebc7a) Thanks [@patzick](https://github.com/patzick)! - Parse Json5 responses when using default overrides
241
+
242
+ - [#1112](https://github.com/shopware/frontends/pull/1112) [`2065d00`](https://github.com/shopware/frontends/commit/2065d00998cd84fb6e2f51d7f793eb178e0865e4) Thanks [@patzick](https://github.com/patzick)! - Fixed adding missing components in overrides. Used when component name is overriden and no component definition is provided for it.
243
+
244
+ - [#1103](https://github.com/shopware/frontends/pull/1103) [`c9a4965`](https://github.com/shopware/frontends/commit/c9a49659e77842a4b098d5b9cc6606f4158893fd) Thanks [@trimethylpentan](https://github.com/trimethylpentan)! - Re-enabled generation for `GenericRecord`s for openAPI objects
package/dist/cli.mjs CHANGED
@@ -7050,7 +7050,7 @@ and limitations under the License.
7050
7050
 
7051
7051
  // src/compiler/corePublic.ts
7052
7052
  var versionMajorMinor = "5.5";
7053
- var version = "5.5.2";
7053
+ var version = "5.5.3";
7054
7054
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
7055
7055
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
7056
7056
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -57484,7 +57484,7 @@ ${lanes.join("\n")}
57484
57484
  }
57485
57485
  if (moduleResolutionKind === 3 /* Node16 */ || moduleResolutionKind === 99 /* NodeNext */) {
57486
57486
  const isSyncImport = currentSourceFile.impliedNodeFormat === 1 /* CommonJS */ && !findAncestor(location, isImportCall) || !!findAncestor(location, isImportEqualsDeclaration);
57487
- const overrideHost = findAncestor(location, (l) => isImportTypeNode(l) || isExportDeclaration(l) || isImportDeclaration(l));
57487
+ const overrideHost = findAncestor(location, (l) => isImportTypeNode(l) || isExportDeclaration(l) || isImportDeclaration(l) || isJSDocImportTag(l));
57488
57488
  if (isSyncImport && sourceFile.impliedNodeFormat === 99 /* ESNext */ && !hasResolutionModeOverride(overrideHost)) {
57489
57489
  if (findAncestor(location, isImportEqualsDeclaration)) {
57490
57490
  error2(errorNode, Diagnostics.Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_with_require_Use_an_ECMAScript_import_instead, moduleReference);
@@ -128207,7 +128207,7 @@ ${lanes.join("\n")}
128207
128207
  }
128208
128208
  function getModeForUsageLocationWorker(file, usage, compilerOptions) {
128209
128209
  var _a;
128210
- if (isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent)) {
128210
+ if (isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent) || isJSDocImportTag(usage.parent)) {
128211
128211
  const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(usage.parent);
128212
128212
  if (isTypeOnly) {
128213
128213
  const override = getResolutionModeOverride(usage.parent.attributes);
@@ -213974,6 +213974,15 @@ ${c$1.cyan(
213974
213974
  });
213975
213975
  }
213976
213976
  });
213977
+ Object.entries(jsonOverrides?.components || {}).forEach((schema) => {
213978
+ if (!openApiSchema.components?.schemas?.[schema[0]]) {
213979
+ const patches = Array.isArray(schema[1]) ? schema[1] : [schema[1]];
213980
+ patches.forEach((patch) => {
213981
+ patchedSchema.components.schemas[schema[0]] = patch;
213982
+ appliedPatches++;
213983
+ });
213984
+ }
213985
+ });
213977
213986
  Object.entries(openApiSchema?.paths || {}).forEach((pathObject) => {
213978
213987
  const pathName = pathObject[0];
213979
213988
  Object.entries(pathObject[1]).forEach((singlePath) => {
@@ -214059,12 +214068,21 @@ async function loadApiGenConfig(params = {}) {
214059
214068
  function isURL(str) {
214060
214069
  return str.startsWith("http");
214061
214070
  }
214062
- async function loadJsonOverrides(path) {
214063
- const pathToResolve = path || "https://raw.githubusercontent.com/shopware/frontends/main/packages/api-client/api-types/storeApiSchema.overrides.json";
214071
+ async function loadJsonOverrides({
214072
+ path,
214073
+ apiType
214074
+ }) {
214075
+ const localPath = `./api-types/${apiType}ApiSchema.overrides.json`;
214076
+ const fallbackPath = existsSync(localPath) ? localPath : `https://raw.githubusercontent.com/shopware/frontends/main/packages/api-client/api-types/${apiType}ApiSchema.overrides.json`;
214077
+ const pathToResolve = path || fallbackPath;
214078
+ console.log("Loading overrides from:", pathToResolve);
214064
214079
  try {
214065
214080
  if (isURL(pathToResolve)) {
214066
- const response = await ofetch(pathToResolve);
214067
- return response.data;
214081
+ const response = await ofetch(pathToResolve, {
214082
+ responseType: "json",
214083
+ parseResponse: lib.parse
214084
+ });
214085
+ return response;
214068
214086
  } else {
214069
214087
  const jsonOverridesFile = await readFileSync(pathToResolve, {
214070
214088
  encoding: "utf-8"
@@ -214167,7 +214185,10 @@ async function generate(args) {
214167
214185
  silent: true
214168
214186
  // we allow to not have the config file in this command
214169
214187
  });
214170
- const jsonOverrides = await loadJsonOverrides(configJSON?.patches);
214188
+ const jsonOverrides = await loadJsonOverrides({
214189
+ path: configJSON?.patches,
214190
+ apiType: args.apiType
214191
+ });
214171
214192
  const {
214172
214193
  patchedSchema,
214173
214194
  todosToFix,
@@ -214193,11 +214214,11 @@ async function generate(args) {
214193
214214
  alphabetize: true,
214194
214215
  supportArrayLength: true,
214195
214216
  commentHeader: `/**
214196
- * This file is auto-generated. Do not make direct changes to the file.
214217
+ * This file is auto-generated. Do not make direct changes to the file.
214197
214218
  * Instead override it in your shopware.d.ts file.
214198
- *
214219
+ *
214199
214220
  * Shopware API version: ${version}
214200
- *
214221
+ *
214201
214222
  */
214202
214223
  `,
214203
214224
  /**
@@ -214245,6 +214266,13 @@ async function generate(args) {
214245
214266
  if (schemaObject.format === "binary") {
214246
214267
  return "Blob";
214247
214268
  }
214269
+ if (
214270
+ // for object types
214271
+ schemaObject.type === "object" && // without properties, items, anyOf, allOf
214272
+ !schemaObject.properties && !schemaObject.items && !schemaObject.anyOf && !schemaObject.allOf && !schemaObject.additionalProperties
214273
+ ) {
214274
+ return "GenericRecord";
214275
+ }
214248
214276
  }
214249
214277
  });
214250
214278
  schema += `
@@ -214342,7 +214370,7 @@ async function generate(args) {
214342
214370
  }
214343
214371
 
214344
214372
  const name = "@shopware/api-gen";
214345
- const version = "1.0.1";
214373
+ const version = "1.0.3";
214346
214374
  const description = "Shopware CLI for API client generation.";
214347
214375
  const author = "Shopware";
214348
214376
  const type = "module";
@@ -214568,6 +214596,12 @@ function splitByCase(str, separators) {
214568
214596
  parts.push(buff);
214569
214597
  return parts;
214570
214598
  }
214599
+ function upperFirst(str) {
214600
+ return str ? str[0].toUpperCase() + str.slice(1) : "";
214601
+ }
214602
+ function pascalCase(str, opts) {
214603
+ return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
214604
+ }
214571
214605
  function kebabCase(str, joiner) {
214572
214606
  return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
214573
214607
  }
@@ -214584,11 +214618,13 @@ const componentsApiAliasRule = (componentName, body) => {
214584
214618
  if (!bodyValue) {
214585
214619
  return null;
214586
214620
  }
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
214621
  const result = equals(properAliasDefinition, bodyValue);
214591
214622
  if (!result) {
214623
+ let additionalMessage = "";
214624
+ const bodyEnumValue = bodyValue?.enum?.[0];
214625
+ if (bodyEnumValue && properAliasDefinition.enum[0] !== bodyEnumValue) {
214626
+ 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.`;
214627
+ }
214592
214628
  return `Component ${c$1.bold(componentName)} has invalid ${c$1.bold("apiAlias")} definition. Diff:
214593
214629
  ${diff(
214594
214630
  properAliasDefinition,
@@ -214597,7 +214633,11 @@ const componentsApiAliasRule = (componentName, body) => {
214597
214633
  aColor: c$1.green,
214598
214634
  bColor: c$1.red
214599
214635
  }
214600
- )}`;
214636
+ )}${additionalMessage.length ? `
214637
+ ${additionalMessage}` : ""}`;
214638
+ }
214639
+ if (!body.required?.includes("apiAlias")) {
214640
+ return `Component ${c$1.bold(componentName)} has invalid ${c$1.bold("apiAlias")} definition. This field should be required.`;
214601
214641
  }
214602
214642
  return null;
214603
214643
  };
@@ -214639,7 +214679,10 @@ async function validateJson(args) {
214639
214679
  process.exit(1);
214640
214680
  }
214641
214681
  const errors = [];
214642
- const jsonOverrides = await loadJsonOverrides(configJSON.patches);
214682
+ const jsonOverrides = await loadJsonOverrides({
214683
+ path: configJSON.patches,
214684
+ apiType: args.apiType
214685
+ });
214643
214686
  Object.entries(fileContentAsJson.components?.schemas || {}).forEach(
214644
214687
  (schema) => {
214645
214688
  rulesToProcess.forEach((ruleName) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware/api-gen",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Shopware CLI for API client generation.",
5
5
  "author": "Shopware",
6
6
  "type": "module",