@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.
- package/README.md +8 -2
- package/dist/cli.mjs +86 -62
- 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.
|
|
15
|
+
### Latest changes: 0.0.5
|
|
16
16
|
|
|
17
17
|
### Patch Changes
|
|
18
18
|
|
|
19
|
-
- [#
|
|
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
|
-
|
|
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.
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
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.
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
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.
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
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
|
|
627
|
+
const formatted2 = await format(JSON.stringify(apiJSON), {
|
|
613
628
|
semi: false,
|
|
614
629
|
parser: "json"
|
|
615
|
-
})
|
|
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
|
|
650
|
+
const formatted = await format(JSON.stringify(schemaForPatching), {
|
|
635
651
|
semi: false,
|
|
636
652
|
parser: "json"
|
|
637
|
-
})
|
|
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(
|
|
683
|
-
acc
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
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(
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
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
|
-
})
|
|
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
|
+
"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.
|
|
28
|
+
"@types/prettier": "^2.7.3",
|
|
29
29
|
"@types/yargs": "^17.0.24",
|
|
30
|
-
"@vitest/coverage-c8": "^0.
|
|
30
|
+
"@vitest/coverage-c8": "^0.33.0",
|
|
31
31
|
"picocolors": "^1.0.0",
|
|
32
|
-
"vitest": "^0.
|
|
33
|
-
"eslint-config-shopware": "0.0.
|
|
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.
|
|
38
|
-
"openapi-typescript": "^6.
|
|
39
|
-
"prettier": "^
|
|
40
|
-
"semver": "^7.
|
|
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",
|