@shopware/api-gen 1.0.0 → 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.
Files changed (3) hide show
  1. package/README.md +3 -42
  2. package/dist/cli.mjs +37 -11
  3. package/package.json +4 -4
package/README.md CHANGED
@@ -233,49 +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.0
237
-
238
- ### Major Changes
239
-
240
- - [#871](https://github.com/shopware/frontends/pull/871) [`1566f7a`](https://github.com/shopware/frontends/commit/1566f7a3962c511b5c72e12a4a5db40c4aa5d198) Thanks [@patzick](https://github.com/patzick)! - Read more about new major release: https://github.com/shopware/frontends/discussions/965
241
-
242
- ### Minor Changes
243
-
244
- - [#534](https://github.com/shopware/frontends/pull/534) [`6170dca`](https://github.com/shopware/frontends/commit/6170dca220f4b33c4dcb6fd1c3172ad931a47c75) Thanks [@patzick](https://github.com/patzick)! - `loadSchema` command added by splitting `generate` command
245
-
246
- - [#534](https://github.com/shopware/frontends/pull/534) [`6170dca`](https://github.com/shopware/frontends/commit/6170dca220f4b33c4dcb6fd1c3172ad931a47c75) Thanks [@patzick](https://github.com/patzick)! - Sorting `paths` in the same order by api patchs
247
-
248
- - [#1017](https://github.com/shopware/frontends/pull/1017) [`12c8153`](https://github.com/shopware/frontends/commit/12c8153e2279d48716ba6d67e28a1876318eb094) Thanks [@patzick](https://github.com/patzick)! - New command `validateJson` to check correctness of your OpenAPI json file.
249
-
250
- - [#534](https://github.com/shopware/frontends/pull/534) [`6170dca`](https://github.com/shopware/frontends/commit/6170dca220f4b33c4dcb6fd1c3172ad931a47c75) Thanks [@patzick](https://github.com/patzick)! - Command `generate` has been splitted and doing only transformation from json to d.ts file
251
-
252
- - [#564](https://github.com/shopware/frontends/pull/564) [`93a6048`](https://github.com/shopware/frontends/commit/93a6048ee28c1975750ef6911f303ea095cb9941) Thanks [@patzick](https://github.com/patzick)! - Added `apiType` option in `loadSchema` command. With `SHOPWARE_ADMIN_USERNAME` and `SHOPWARE_ADMIN_PASSWORD` env variables we can now authorize Admin API schema.
253
-
254
- example:
255
-
256
- ```bash
257
- # load schema from store API
258
- pnpx @shopware/api-gen loadSchema --apiType=store --filename=storeApiSchema.json
259
-
260
- # load schema from admin API
261
- pnpx @shopware/api-gen loadSchema --apiType=admin --filename=adminApiSchema.json
262
- ```
263
-
264
- - [#1032](https://github.com/shopware/frontends/pull/1032) [`0b6133e`](https://github.com/shopware/frontends/commit/0b6133e8a9e929e004094800341a0c8e7de103eb) Thanks [@patzick](https://github.com/patzick)! - Possibility to add partial patches to the JSON schema.
265
-
266
- - [#903](https://github.com/shopware/frontends/pull/903) [`18d8528`](https://github.com/shopware/frontends/commit/18d8528886cfdee5bb14b0f4adb10f9b874eddf2) Thanks [@mdanilowicz](https://github.com/mdanilowicz)! - Add Blob type support
267
-
268
- - [#534](https://github.com/shopware/frontends/pull/534) [`6170dca`](https://github.com/shopware/frontends/commit/6170dca220f4b33c4dcb6fd1c3172ad931a47c75) Thanks [@patzick](https://github.com/patzick)! - Schema `operations` is now a generic type to help with overriding types
269
-
270
- - [#1032](https://github.com/shopware/frontends/pull/1032) [`0b6133e`](https://github.com/shopware/frontends/commit/0b6133e8a9e929e004094800341a0c8e7de103eb) Thanks [@patzick](https://github.com/patzick)! - Added support for JSON5 config files. Now you can use comments in your config files and JSON schema.
236
+ ### Latest changes: 1.0.2
271
237
 
272
238
  ### Patch Changes
273
239
 
274
- - [#534](https://github.com/shopware/frontends/pull/534) [`6170dca`](https://github.com/shopware/frontends/commit/6170dca220f4b33c4dcb6fd1c3172ad931a47c75) Thanks [@patzick](https://github.com/patzick)! - Generated `GenericRecord` is more open to avoid type problems
275
-
276
- - [#1032](https://github.com/shopware/frontends/pull/1032) [`0b6133e`](https://github.com/shopware/frontends/commit/0b6133e8a9e929e004094800341a0c8e7de103eb) Thanks [@patzick](https://github.com/patzick)! - Fixed optional body parameters, now it's processed correctly. The body is required by default (if defined).
277
-
278
- - [#928](https://github.com/shopware/frontends/pull/928) [`bada1cd`](https://github.com/shopware/frontends/commit/bada1cd816f5fa73389d401366545d08b0dd5c8b) Thanks [@mdanilowicz](https://github.com/mdanilowicz)! - Skip GenericRecord for the object with additionalProperties
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
279
241
 
280
- - Updated dependencies [[`2343012`](https://github.com/shopware/frontends/commit/2343012ad552b06557e6715055b3abc534fa2fae), [`1566f7a`](https://github.com/shopware/frontends/commit/1566f7a3962c511b5c72e12a4a5db40c4aa5d198), [`782ef4d`](https://github.com/shopware/frontends/commit/782ef4d417dce6e6d60992bd54f876aa4bc5f45d), [`9643e56`](https://github.com/shopware/frontends/commit/9643e56dafba9282b75c12c96b2afb3a4738f86e), [`1583a7a`](https://github.com/shopware/frontends/commit/1583a7ae0d68b72fb362b625e1634e03bad68110), [`97d2859`](https://github.com/shopware/frontends/commit/97d2859e4dcbdc563200f2f64d1a20880b675d87), [`d60d062`](https://github.com/shopware/frontends/commit/d60d0620c7114a2f26bb2faf24241e2cbabc8798), [`c729e70`](https://github.com/shopware/frontends/commit/c729e7014c70d7f71edf5297104065d18e482e04), [`89a97a4`](https://github.com/shopware/frontends/commit/89a97a45ae4a58616e41f63e9884a2a67f0a6ce8), [`864616f`](https://github.com/shopware/frontends/commit/864616f0c9e1cbe11e434b9a04a35ff9520bcb3c)]:
281
- - @shopware/api-client@1.0.0
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(path) {
214063
- const pathToResolve = path || "https://raw.githubusercontent.com/shopware/frontends/main/packages/api-client/api-types/storeApiSchema.overrides.json";
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
- return response.data;
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(configJSON?.patches);
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.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(configJSON.patches);
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.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
- "eslint-config-shopware": "0.0.9",
39
- "tsconfig": "0.0.0"
38
+ "tsconfig": "0.0.0",
39
+ "eslint-config-shopware": "0.0.9"
40
40
  },
41
41
  "dependencies": {
42
42
  "ofetch": "1.3.4",
@@ -44,7 +44,7 @@
44
44
  "prettier": "3.3.2",
45
45
  "ts-morph": "22.0.0",
46
46
  "yargs": "17.7.2",
47
- "@shopware/api-client": "1.0.0"
47
+ "@shopware/api-client": "1.0.1"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "unbuild",