@shopware/api-gen 1.3.2 → 1.3.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.
package/README.md
CHANGED
|
@@ -316,8 +316,8 @@ await validateJson({
|
|
|
316
316
|
|
|
317
317
|
Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/api-gen/CHANGELOG.md)
|
|
318
318
|
|
|
319
|
-
### Latest changes: 1.3.
|
|
319
|
+
### Latest changes: 1.3.3
|
|
320
320
|
|
|
321
321
|
### Patch Changes
|
|
322
322
|
|
|
323
|
-
- [#
|
|
323
|
+
- [#1942](https://github.com/shopware/frontends/pull/1942) [`a344abb`](https://github.com/shopware/frontends/commit/a344abba579c91c4f775e7be27ed882ca420fdc2) Thanks [@patzick](https://github.com/patzick)! - Allow shared parameters to be available in schema resolver.
|
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import yargs from 'yargs';
|
|
2
2
|
import { hideBin } from 'yargs/helpers';
|
|
3
|
-
import { g as generate, l as loadSchema, v as validateJson } from './shared/api-gen.
|
|
3
|
+
import { g as generate, l as loadSchema, v as validateJson } from './shared/api-gen.BZLmrTCs.mjs';
|
|
4
4
|
import 'node:fs';
|
|
5
5
|
import 'node:path';
|
|
6
6
|
import 'openapi-typescript';
|
|
@@ -15,7 +15,7 @@ import 'crypto';
|
|
|
15
15
|
import '@shopware/api-client';
|
|
16
16
|
|
|
17
17
|
const name = "@shopware/api-gen";
|
|
18
|
-
const version = "1.3.
|
|
18
|
+
const version = "1.3.3";
|
|
19
19
|
const description = "Shopware CLI for API client generation.";
|
|
20
20
|
const author = "Shopware";
|
|
21
21
|
const type = "module";
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { g as generate, l as loadSchema, v as validateJson } from './shared/api-gen.
|
|
1
|
+
export { g as generate, l as loadSchema, v as validateJson } from './shared/api-gen.BZLmrTCs.mjs';
|
|
2
2
|
import 'node:fs';
|
|
3
3
|
import 'node:path';
|
|
4
4
|
import 'openapi-typescript';
|
|
@@ -9953,12 +9953,13 @@ ${error}
|
|
|
9953
9953
|
);
|
|
9954
9954
|
}
|
|
9955
9955
|
|
|
9956
|
-
async function generateFile(filepath, operationsMap, existingTypes, schemasMap, options) {
|
|
9956
|
+
async function generateFile(filepath, operationsMap, existingTypes, schemasMap, parametersMap, options) {
|
|
9957
9957
|
const project = await prepareFileContent({
|
|
9958
9958
|
filepath,
|
|
9959
9959
|
operationsMap,
|
|
9960
9960
|
existingTypes,
|
|
9961
9961
|
componentsMap: schemasMap,
|
|
9962
|
+
parametersMap,
|
|
9962
9963
|
options
|
|
9963
9964
|
});
|
|
9964
9965
|
await project.save();
|
|
@@ -9968,6 +9969,7 @@ async function prepareFileContent({
|
|
|
9968
9969
|
operationsMap,
|
|
9969
9970
|
existingTypes,
|
|
9970
9971
|
componentsMap,
|
|
9972
|
+
parametersMap,
|
|
9971
9973
|
options
|
|
9972
9974
|
}) {
|
|
9973
9975
|
const project = new Project({});
|
|
@@ -9980,6 +9982,7 @@ async function prepareFileContent({
|
|
|
9980
9982
|
const defaultContentType = "application/json";
|
|
9981
9983
|
const defaultAcceptType = "application/json";
|
|
9982
9984
|
const sortedSchemaKeys = Object.keys(componentsMap).sort();
|
|
9985
|
+
const sortedParametersKeys = Object.keys(parametersMap).sort();
|
|
9983
9986
|
const sourceFile = project.createSourceFile(
|
|
9984
9987
|
filepath,
|
|
9985
9988
|
(writer) => {
|
|
@@ -9990,6 +9993,15 @@ async function prepareFileContent({
|
|
|
9990
9993
|
}
|
|
9991
9994
|
writer.write("export type components =").block(() => {
|
|
9992
9995
|
writer.writeLine("schemas: Schemas;");
|
|
9996
|
+
if (sortedParametersKeys.length) {
|
|
9997
|
+
writer.writeLine("parameters:").block(() => {
|
|
9998
|
+
for (const key of sortedParametersKeys) {
|
|
9999
|
+
if (parametersMap[key]) {
|
|
10000
|
+
writer.write(`${key}:`).write(parametersMap[key]);
|
|
10001
|
+
}
|
|
10002
|
+
}
|
|
10003
|
+
});
|
|
10004
|
+
}
|
|
9993
10005
|
});
|
|
9994
10006
|
writer.write("export type Schemas =").block(() => {
|
|
9995
10007
|
for (const key of sortedSchemaKeys) {
|
|
@@ -10164,6 +10176,7 @@ function transformSchemaTypes(schema) {
|
|
|
10164
10176
|
} = createVirtualFiles([{ name: "_openApi.d.ts", content: schema }]);
|
|
10165
10177
|
const overridesMap = {};
|
|
10166
10178
|
const componentsMap = {};
|
|
10179
|
+
const parametersMap = {};
|
|
10167
10180
|
const existingTypes = [];
|
|
10168
10181
|
const skipTypeNames = ["operations", "Schemas", "components"];
|
|
10169
10182
|
function traverseThroughFileNodes(node) {
|
|
@@ -10212,10 +10225,10 @@ function transformSchemaTypes(schema) {
|
|
|
10212
10225
|
if (sourceFile) {
|
|
10213
10226
|
traverseThroughFileNodes(sourceFile);
|
|
10214
10227
|
}
|
|
10215
|
-
return [overridesMap, componentsMap, existingTypes];
|
|
10228
|
+
return [overridesMap, componentsMap, existingTypes, parametersMap];
|
|
10216
10229
|
}
|
|
10217
10230
|
|
|
10218
|
-
async function processAstSchemaAndOverrides([opMap, opComponents, opExistingTypes], overridingSchema, type, options) {
|
|
10231
|
+
async function processAstSchemaAndOverrides([opMap, opComponents, opExistingTypes, opParameters], overridingSchema, type, options) {
|
|
10219
10232
|
const {
|
|
10220
10233
|
sourceFiles: [sourceFile, overridesSourceFile]
|
|
10221
10234
|
} = createVirtualFiles([
|
|
@@ -10238,12 +10251,14 @@ async function processAstSchemaAndOverrides([opMap, opComponents, opExistingType
|
|
|
10238
10251
|
);
|
|
10239
10252
|
const componentsMap = defu(oComponetsMap, opComponents);
|
|
10240
10253
|
const existingTypes = opExistingTypes;
|
|
10254
|
+
const parametersMap = opParameters;
|
|
10241
10255
|
const filePath = join("api-types", `${type}ApiTypes.d.ts`);
|
|
10242
10256
|
await generateFile(
|
|
10243
10257
|
filePath,
|
|
10244
10258
|
operationsMap,
|
|
10245
10259
|
existingTypes,
|
|
10246
10260
|
componentsMap,
|
|
10261
|
+
parametersMap,
|
|
10247
10262
|
options
|
|
10248
10263
|
);
|
|
10249
10264
|
}
|
|
@@ -10256,6 +10271,7 @@ function transformOpenApiTypes(schema) {
|
|
|
10256
10271
|
} = createVirtualFiles([{ name: "_openApi.d.ts", content: schema }]);
|
|
10257
10272
|
const operationsMap = {};
|
|
10258
10273
|
const componentsMap = {};
|
|
10274
|
+
const parametersMap = {};
|
|
10259
10275
|
const existingTypes = [];
|
|
10260
10276
|
function traverseThroughFileNodes(node) {
|
|
10261
10277
|
if (node.kind === ts.SyntaxKind.TypeAliasDeclaration) {
|
|
@@ -10471,6 +10487,26 @@ function transformOpenApiTypes(schema) {
|
|
|
10471
10487
|
}
|
|
10472
10488
|
}
|
|
10473
10489
|
}
|
|
10490
|
+
const allParameters = getDeepProperty({
|
|
10491
|
+
type,
|
|
10492
|
+
names: ["parameters"],
|
|
10493
|
+
node,
|
|
10494
|
+
typeChecker
|
|
10495
|
+
});
|
|
10496
|
+
if (allParameters) {
|
|
10497
|
+
const parameterNames = getTypePropertyNames(allParameters);
|
|
10498
|
+
for (const parameterName of parameterNames) {
|
|
10499
|
+
const parameterCode = getDeepPropertyCode({
|
|
10500
|
+
type: allParameters,
|
|
10501
|
+
names: [parameterName],
|
|
10502
|
+
node,
|
|
10503
|
+
typeChecker
|
|
10504
|
+
});
|
|
10505
|
+
if (parameterCode) {
|
|
10506
|
+
parametersMap[parameterName] = parameterCode;
|
|
10507
|
+
}
|
|
10508
|
+
}
|
|
10509
|
+
}
|
|
10474
10510
|
}
|
|
10475
10511
|
const doNotMoveTypes = [
|
|
10476
10512
|
"$defs",
|
|
@@ -10490,7 +10526,7 @@ function transformOpenApiTypes(schema) {
|
|
|
10490
10526
|
if (sourceFile) {
|
|
10491
10527
|
traverseThroughFileNodes(sourceFile);
|
|
10492
10528
|
}
|
|
10493
|
-
return [operationsMap, componentsMap, existingTypes];
|
|
10529
|
+
return [operationsMap, componentsMap, existingTypes, parametersMap];
|
|
10494
10530
|
}
|
|
10495
10531
|
|
|
10496
10532
|
async function generate(args) {
|