@shopware/api-gen 0.0.4 → 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 +45 -36
- package/package.json +7 -7
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
|
@@ -624,10 +624,11 @@ async function generate() {
|
|
|
624
624
|
Authorization: config.OPENAPI_ACCESS_KEY
|
|
625
625
|
}
|
|
626
626
|
}).then((res) => res.json());
|
|
627
|
-
const
|
|
627
|
+
const formatted2 = await format(JSON.stringify(apiJSON), {
|
|
628
628
|
semi: false,
|
|
629
629
|
parser: "json"
|
|
630
|
-
})
|
|
630
|
+
});
|
|
631
|
+
const content2 = formatted2.trim();
|
|
631
632
|
version = apiJSON?.info?.version;
|
|
632
633
|
writeFileSync(SCHEMA_FILENAME(version), content2, {
|
|
633
634
|
encoding: "utf-8"
|
|
@@ -646,10 +647,11 @@ async function generate() {
|
|
|
646
647
|
schemaForPatching = patches[patchName].patch(schemaForPatching);
|
|
647
648
|
});
|
|
648
649
|
patchesToApply.length && console.log("Applied", patchesToApply.length, "patches");
|
|
649
|
-
const
|
|
650
|
+
const formatted = await format(JSON.stringify(schemaForPatching), {
|
|
650
651
|
semi: false,
|
|
651
652
|
parser: "json"
|
|
652
|
-
})
|
|
653
|
+
});
|
|
654
|
+
const content = formatted.trim();
|
|
653
655
|
writeFileSync(SCHEMA_FILENAME(version), content, {
|
|
654
656
|
encoding: "utf-8"
|
|
655
657
|
});
|
|
@@ -694,12 +696,15 @@ async function generate() {
|
|
|
694
696
|
);
|
|
695
697
|
schemaObject.properties.translated = {
|
|
696
698
|
type: "object",
|
|
697
|
-
properties: stringFields.reduce(
|
|
698
|
-
acc
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
699
|
+
properties: stringFields.reduce(
|
|
700
|
+
(acc, key) => {
|
|
701
|
+
acc[key] = {
|
|
702
|
+
type: "string"
|
|
703
|
+
};
|
|
704
|
+
return acc;
|
|
705
|
+
},
|
|
706
|
+
{}
|
|
707
|
+
)
|
|
703
708
|
};
|
|
704
709
|
}
|
|
705
710
|
if (
|
|
@@ -712,38 +717,42 @@ async function generate() {
|
|
|
712
717
|
}
|
|
713
718
|
}
|
|
714
719
|
);
|
|
715
|
-
const operationsMap = Object.keys(paths).reduce(
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
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
|
+
);
|
|
739
747
|
schema += `
|
|
740
748
|
export type operationPaths = ${Object.values(operationsMap).map((el) => `"${el.finalPath}"`).join(" | ")};`;
|
|
741
749
|
schema = schema.replace(/@description /g, "");
|
|
742
|
-
schema = format(schema, {
|
|
750
|
+
schema = await format(schema, {
|
|
743
751
|
// semi: false,
|
|
744
752
|
parser: "typescript"
|
|
745
753
|
// plugins: [tsParser],
|
|
746
|
-
})
|
|
754
|
+
});
|
|
755
|
+
schema = schema.trim();
|
|
747
756
|
if (typeof schema === "string") {
|
|
748
757
|
writeFileSync(TYPES_FILENAME(originalSchema.info.version), schema, {
|
|
749
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": {
|
|
@@ -27,17 +27,17 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
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
37
|
"ofetch": "^1.1.1",
|
|
38
|
-
"openapi-typescript": "^6.
|
|
39
|
-
"prettier": "^
|
|
40
|
-
"semver": "^7.5.
|
|
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": {
|