@shopware/api-gen 0.0.3 → 0.0.5

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 +8 -2
  2. package/dist/cli.mjs +86 -62
  3. package/package.json +10 -10
package/README.md CHANGED
@@ -12,8 +12,14 @@ Documentation specific for this package: [api-gen](https://frontends.shopware.co
12
12
 
13
13
  Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/api-gen/CHANGELOG.md)
14
14
 
15
- ### Latest changes: 0.0.3
15
+ ### Latest changes: 0.0.5
16
16
 
17
17
  ### Patch Changes
18
18
 
19
- - [#292](https://github.com/shopware/frontends/pull/292) [`b68ca7f`](https://github.com/shopware/frontends/commit/b68ca7fbd51d22f4be84a228ca107972e07bfa32) Thanks [@patzick](https://github.com/patzick)! - fixed cli building, prettier is not inlined into bundle
19
+ - [#303](https://github.com/shopware/frontends/pull/303) [`aeb639a`](https://github.com/shopware/frontends/commit/aeb639a3244f812c275145345618e5bc0045be0d) Thanks [@patzick](https://github.com/patzick)! - Improved linting in packages. Types should be more reliable
20
+
21
+ - [#313](https://github.com/shopware/frontends/pull/313) [`0e82ab3`](https://github.com/shopware/frontends/commit/0e82ab395cc88e992d2d64853d27603548c36bb9) Thanks [@patzick](https://github.com/patzick)! - Dependency changes:
22
+
23
+ - Changed dependency _openapi-typescript_ from **^6.2.8** to **^6.3.4**
24
+ - Changed dependency _prettier_ from **^2.8.8** to **^3.0.0**
25
+ - Changed dependency _semver_ from **^7.5.3** to **^7.5.4**
package/dist/cli.mjs CHANGED
@@ -528,8 +528,11 @@ const patches = {
528
528
  */
529
529
  name: "ContextTokenResponse",
530
530
  patch: (schema) => {
531
- var _a;
532
- (_a = schema.components.schemas)["ContextTokenResponse"] ?? (_a["ContextTokenResponse"] = {
531
+ var _a, _b, _c, _d, _e, _f, _g, _h;
532
+ schema.components ?? (schema.components = {});
533
+ (_a = schema.components).schemas ?? (_a.schemas = {});
534
+ schema.paths ?? (schema.paths = {});
535
+ (_b = schema.components.schemas)["ContextTokenResponse"] ?? (_b["ContextTokenResponse"] = {
533
536
  type: "object",
534
537
  properties: {
535
538
  contextToken: {
@@ -538,36 +541,48 @@ const patches = {
538
541
  }
539
542
  }
540
543
  });
541
- schema.paths["/context"].patch.responses["200"] = {
542
- description: "Returns the context token. Use that as your `sw-context-token` header for subsequent requests. Redirect if getRedirectUrl is set.",
543
- content: {
544
- "application/json": {
545
- schema: {
546
- $ref: "#/components/schemas/ContextTokenResponse"
544
+ (_c = schema.paths["/context"]).patch ?? (_c.patch = {});
545
+ if ("responses" in schema.paths["/context"].patch) {
546
+ (_d = schema.paths["/context"].patch).responses ?? (_d.responses = {});
547
+ schema.paths["/context"].patch.responses["200"] = {
548
+ description: "Returns the context token. Use that as your `sw-context-token` header for subsequent requests. Redirect if getRedirectUrl is set.",
549
+ content: {
550
+ "application/json": {
551
+ schema: {
552
+ $ref: "#/components/schemas/ContextTokenResponse"
553
+ }
547
554
  }
548
555
  }
549
- }
550
- };
551
- schema.paths["/account/login"].post.responses["200"] = {
552
- description: "A successful login returns a context token which is associated with the logged in user. Use that as your `sw-context-token` header for subsequent requests.",
553
- content: {
554
- "application/json": {
555
- schema: {
556
- $ref: "#/components/schemas/ContextTokenResponse"
556
+ };
557
+ }
558
+ (_e = schema.paths["/account/login"]).post ?? (_e.post = {});
559
+ if ("responses" in schema.paths["/account/login"].post) {
560
+ (_f = schema.paths["/account/login"].post).responses ?? (_f.responses = {});
561
+ schema.paths["/account/login"].post.responses["200"] = {
562
+ description: "A successful login returns a context token which is associated with the logged in user. Use that as your `sw-context-token` header for subsequent requests.",
563
+ content: {
564
+ "application/json": {
565
+ schema: {
566
+ $ref: "#/components/schemas/ContextTokenResponse"
567
+ }
557
568
  }
558
569
  }
559
- }
560
- };
561
- schema.paths["/account/logout"].post.responses["200"] = {
562
- description: "A successful logout returns a context token for the anonymous user. Use that as your `sw-context-token` header for subsequent requests.",
563
- content: {
564
- "application/json": {
565
- schema: {
566
- $ref: "#/components/schemas/ContextTokenResponse"
570
+ };
571
+ }
572
+ (_g = schema.paths["/account/logout"]).post ?? (_g.post = {});
573
+ if ("responses" in schema.paths["/account/logout"].post) {
574
+ (_h = schema.paths["/account/logout"].post).responses ?? (_h.responses = {});
575
+ schema.paths["/account/logout"].post.responses["200"] = {
576
+ description: "A successful logout returns a context token for the anonymous user. Use that as your `sw-context-token` header for subsequent requests.",
577
+ content: {
578
+ "application/json": {
579
+ schema: {
580
+ $ref: "#/components/schemas/ContextTokenResponse"
581
+ }
567
582
  }
568
583
  }
569
- }
570
- };
584
+ };
585
+ }
571
586
  return schema;
572
587
  }
573
588
  }
@@ -609,10 +624,11 @@ async function generate() {
609
624
  Authorization: config.OPENAPI_ACCESS_KEY
610
625
  }
611
626
  }).then((res) => res.json());
612
- const content2 = format(JSON.stringify(apiJSON), {
627
+ const formatted2 = await format(JSON.stringify(apiJSON), {
613
628
  semi: false,
614
629
  parser: "json"
615
- }).trim();
630
+ });
631
+ const content2 = formatted2.trim();
616
632
  version = apiJSON?.info?.version;
617
633
  writeFileSync(SCHEMA_FILENAME(version), content2, {
618
634
  encoding: "utf-8"
@@ -631,10 +647,11 @@ async function generate() {
631
647
  schemaForPatching = patches[patchName].patch(schemaForPatching);
632
648
  });
633
649
  patchesToApply.length && console.log("Applied", patchesToApply.length, "patches");
634
- const content = format(JSON.stringify(schemaForPatching), {
650
+ const formatted = await format(JSON.stringify(schemaForPatching), {
635
651
  semi: false,
636
652
  parser: "json"
637
- }).trim();
653
+ });
654
+ const content = formatted.trim();
638
655
  writeFileSync(SCHEMA_FILENAME(version), content, {
639
656
  encoding: "utf-8"
640
657
  });
@@ -679,12 +696,15 @@ async function generate() {
679
696
  );
680
697
  schemaObject.properties.translated = {
681
698
  type: "object",
682
- properties: stringFields.reduce((acc, key) => {
683
- acc[key] = {
684
- type: "string"
685
- };
686
- return acc;
687
- }, {})
699
+ properties: stringFields.reduce(
700
+ (acc, key) => {
701
+ acc[key] = {
702
+ type: "string"
703
+ };
704
+ return acc;
705
+ },
706
+ {}
707
+ )
688
708
  };
689
709
  }
690
710
  if (
@@ -697,38 +717,42 @@ async function generate() {
697
717
  }
698
718
  }
699
719
  );
700
- const operationsMap = Object.keys(paths).reduce((acc, path) => {
701
- const pathObject = paths[path];
702
- const methods = Object.keys(pathObject);
703
- methods.forEach((method) => {
704
- const methodObject = pathObject[method];
705
- const { operationId } = methodObject;
706
- const queryParamNames = methodObject.parameters?.filter((param) => param.in === "query").map((param) => param.name) || [];
707
- const headerParamNames = methodObject.parameters?.filter((param) => param.in === "header").map((param) => param.name) || [];
708
- let finalPath = `${operationId} ${method.toLocaleLowerCase()} ${path}`;
709
- if (queryParamNames.length) {
710
- finalPath += `?${queryParamNames.join(",")}`;
711
- }
712
- if (headerParamNames.length) {
713
- finalPath += ` ${headerParamNames.join(",")}`;
714
- }
715
- acc[operationId] = {
716
- path,
717
- method,
718
- queryParamNames,
719
- finalPath
720
- };
721
- });
722
- return acc;
723
- }, {});
720
+ const operationsMap = Object.keys(paths).reduce(
721
+ (acc, path) => {
722
+ const pathObject = paths[path];
723
+ const methods = Object.keys(pathObject);
724
+ methods.forEach((method) => {
725
+ const methodObject = pathObject[method];
726
+ const { operationId } = methodObject;
727
+ const queryParamNames = methodObject.parameters?.filter((param) => param.in === "query").map((param) => param.name) || [];
728
+ const headerParamNames = methodObject.parameters?.filter((param) => param.in === "header").map((param) => param.name) || [];
729
+ let finalPath = `${operationId} ${method.toLocaleLowerCase()} ${path}`;
730
+ if (queryParamNames.length) {
731
+ finalPath += `?${queryParamNames.join(",")}`;
732
+ }
733
+ if (headerParamNames.length) {
734
+ finalPath += ` ${headerParamNames.join(",")}`;
735
+ }
736
+ acc[operationId] = {
737
+ path,
738
+ method,
739
+ queryParamNames,
740
+ finalPath
741
+ };
742
+ });
743
+ return acc;
744
+ },
745
+ {}
746
+ );
724
747
  schema += `
725
748
  export type operationPaths = ${Object.values(operationsMap).map((el) => `"${el.finalPath}"`).join(" | ")};`;
726
749
  schema = schema.replace(/@description /g, "");
727
- schema = format(schema, {
750
+ schema = await format(schema, {
728
751
  // semi: false,
729
752
  parser: "typescript"
730
753
  // plugins: [tsParser],
731
- }).trim();
754
+ });
755
+ schema = schema.trim();
732
756
  if (typeof schema === "string") {
733
757
  writeFileSync(TYPES_FILENAME(originalSchema.info.version), schema, {
734
758
  encoding: "utf-8"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware/api-gen",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Shopware CLI for API client generation.",
5
5
  "author": "Shopware",
6
6
  "repository": {
@@ -25,26 +25,26 @@
25
25
  "api-gen": "bin/api-gen.mjs"
26
26
  },
27
27
  "devDependencies": {
28
- "@types/prettier": "^2.7.2",
28
+ "@types/prettier": "^2.7.3",
29
29
  "@types/yargs": "^17.0.24",
30
- "@vitest/coverage-c8": "^0.32.2",
30
+ "@vitest/coverage-c8": "^0.33.0",
31
31
  "picocolors": "^1.0.0",
32
- "vitest": "^0.32.2",
33
- "eslint-config-shopware": "0.0.2",
32
+ "vitest": "^0.33.0",
33
+ "eslint-config-shopware": "0.0.4",
34
34
  "tsconfig": "0.0.0"
35
35
  },
36
36
  "dependencies": {
37
- "ofetch": "^1.0.1",
38
- "openapi-typescript": "^6.2.8",
39
- "prettier": "^2.8.8",
40
- "semver": "^7.3.8",
37
+ "ofetch": "^1.1.1",
38
+ "openapi-typescript": "^6.3.4",
39
+ "prettier": "^3.0.0",
40
+ "semver": "^7.5.4",
41
41
  "yargs": "^17.7.2"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "unbuild",
45
45
  "cli": "esno ./src/cli.ts",
46
46
  "dev": "export NODE_ENV=development && unbuild --stub",
47
- "lint": "eslint src/**/*.ts* --fix --max-warnings=0",
47
+ "lint": "eslint src/**/*.ts* --fix --max-warnings=0 && pnpm run typecheck",
48
48
  "typecheck": "tsc --noEmit",
49
49
  "test": "vitest run",
50
50
  "test:bench": "vitest bench",