@shopware/api-gen 1.3.2 → 1.4.0

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
@@ -5,8 +5,6 @@ Generate TypeScript schemas from Shopware OpenAPI specification.
5
5
 
6
6
  After generating schemas, you can use them in fully typed [API Client](https://www.npmjs.com/package/@shopware/api-client).
7
7
 
8
- To take a deep dive into the topic visit the [🧑‍🎓 API Client Tutorial](https://api-client-tutorial-composable-frontends.pages.dev) first.
9
-
10
8
  ## Usage
11
9
 
12
10
  <!-- automd:pm-install name="@shopware/api-gen" dev -->
@@ -106,24 +104,55 @@ export type operations = {
106
104
  There is a possiblity to add patches (partial overrides) to the schema. Partial overrides are applied directly to the JSON schema, so the syntax needs to be correct. It can then be used by the backend CI tool to validate and apply these patches directly to the schema to fix inconsistencies.
107
105
 
108
106
  By default CLI is fetching the patches from the api-client repository, but you can provide your own patches file by adding a path to the `api-gen.config.json` file.
109
- Example:
107
+
108
+ ### API-specific configuration (Recommended)
109
+
110
+ You can configure patches and rules separately for Store API and Admin API:
111
+
112
+ ```json
113
+ {
114
+ "$schema": "./node_modules/@shopware/api-gen/api-gen.schema.json",
115
+ "store-api": {
116
+ "patches": [
117
+ "storeApiSchema.overrides.json",
118
+ "./api-types/myStoreApiPatches.json"
119
+ ],
120
+ "rules": ["COMPONENTS_API_ALIAS"]
121
+ },
122
+ "admin-api": {
123
+ "patches": ["adminApiSchema.overrides.json"],
124
+ "rules": ["COMPONENTS_API_ALIAS"]
125
+ }
126
+ }
127
+ ```
128
+
129
+ This allows you to maintain different configurations for each API type.
130
+
131
+ ### Legacy configuration (Deprecated)
132
+
133
+ The root-level `patches` and `rules` properties are deprecated but still supported for backwards compatibility:
110
134
 
111
135
  ```json
112
136
  {
113
- "$schema": "https://raw.githubusercontent.com/shopware/frontends/main/packages/api-gen/api-gen.schema.json",
137
+ "$schema": "./node_modules/@shopware/api-gen/api-gen.schema.json",
114
138
  "patches": ["storeApiTypes.overrides.json"]
115
139
  }
116
140
  ```
117
141
 
118
- or you could use multiple patches and add your own overrides on top:
142
+ > [!WARNING]
143
+ > Root-level `patches` and `rules` are deprecated. Please migrate to the API-specific configuration (`store-api` or `admin-api`).
144
+
145
+ You could also use multiple patches and add your own overrides on top:
119
146
 
120
147
  ```json
121
148
  {
122
- "$schema": "https://raw.githubusercontent.com/shopware/frontends/main/packages/api-gen/api-gen.schema.json",
123
- "patches": [
124
- "https://raw.githubusercontent.com/shopware/frontends/refs/heads/main/packages/api-client/api-types/storeApiSchema.overrides.json",
125
- "./api-types/myOwnPatches.overrides.json"
126
- ]
149
+ "$schema": "./node_modules/@shopware/api-gen/api-gen.schema.json",
150
+ "store-api": {
151
+ "patches": [
152
+ "./node_modules/@shopware/api-client/api-types/storeApiSchema.overrides.json",
153
+ "./api-types/myOwnPatches.overrides.json"
154
+ ]
155
+ }
127
156
  }
128
157
  ```
129
158
 
@@ -245,16 +274,50 @@ this searches for `api-types/storeApiTypes.json` file and validates it. Use [loa
245
274
 
246
275
  Prepare your config file named **api-gen.config.json**:
247
276
 
248
- ```JSON
277
+ ```json
249
278
  {
250
- "$schema": "https://raw.githubusercontent.com/shopware/frontends/main/packages/api-gen/api-gen.schema.json",
251
- "rules": [
252
- "COMPONENTS_API_ALIAS" // you have description on autocompletion what specific rule does, this one for example ensures correctness of the apiAlias field
253
- ],
254
- //"patches": "storeApiTypes.overrides.json" // -> path to your overrides file in api-types folder, default is fetched from api-client repository
279
+ "$schema": "./node_modules/@shopware/api-gen/api-gen.schema.json",
280
+ "store-api": {
281
+ "rules": ["COMPONENTS_API_ALIAS"],
282
+ "patches": ["storeApiSchema.overrides.json"]
283
+ },
284
+ "admin-api": {
285
+ "rules": ["COMPONENTS_API_ALIAS"],
286
+ "patches": ["adminApiSchema.overrides.json"]
287
+ }
255
288
  }
256
289
  ```
257
290
 
291
+ > [!NOTE]
292
+ > The `rules` configuration is API-type specific. When running `validateJson --apiType=store`, only the rules defined in `store-api.rules` will be applied.
293
+
294
+ ### `split` - Experimental
295
+
296
+ Split an OpenAPI schema into multiple files, organized by tags or paths. This is useful for breaking down a large schema into smaller, more manageable parts.
297
+
298
+ The main reason for this is that the complete JSON schema can be too large and complex for API clients like Postman or Insomnia to handle, sometimes
299
+ causing performance issues or import failures due to the file size or circular references. This command helps developers to extract only the parts of
300
+ the schema they need and then import it to the API client of their choice.
301
+
302
+ Example usage:
303
+
304
+ ```bash
305
+ # Display all available tags
306
+ pnpx @shopware/api-gen split <path-to-schema-file> --list tags
307
+
308
+ # Display all available paths
309
+ pnpx @shopware/api-gen split <path-to-schema-file> --list paths
310
+
311
+ # Split schema by tags and show detailed linting errors
312
+ pnpx @shopware/api-gen split <path-to-schema-file> --splitBy=tags --outputDir <output-directory> --verbose-linting
313
+
314
+ # Split schema by a single tag
315
+ pnpx @shopware/api-gen split <path-to-schema-file> --splitBy=tags --outputDir <output-directory> --filterBy "media"
316
+
317
+ # Split schema by a single path
318
+ pnpx @shopware/api-gen split <path-to-schema-file> --splitBy=paths --outputDir <output-directory> --filterBy "/api/_action/media/{mediaId}/upload"
319
+ ```
320
+
258
321
  ### Programmatic usage
259
322
 
260
323
  Each command can also be used programmatically within your own scripts:
@@ -299,16 +362,27 @@ await validateJson({
299
362
  });
300
363
  ```
301
364
 
365
+ #### `split`
366
+
367
+ ```ts
368
+ import { split } from "@shopware/api-gen";
369
+
370
+ await split({
371
+ schemaFile: "path/to/your/schema.json",
372
+ outputDir: "path/to/output/directory",
373
+ splitBy: "tags", // or "paths"
374
+ // filterBy: "TagName" // optional filter
375
+ });
376
+ ```
377
+
302
378
  > [!NOTE]
303
379
  > Make sure that the required environment variables are set for the node process when executing commands programmatically.
304
380
 
305
381
  ## Links
306
382
 
307
- - [🧑‍🎓 Tutorial](https://api-client-tutorial-composable-frontends.pages.dev)
308
-
309
383
  - [📘 Documentation](https://frontends.shopware.com)
310
384
 
311
- - [👥 Community Slack](https://shopwarecommunity.slack.com) (`#composable-frontends` channel)
385
+ - [👥 Community Discord](https://discord.com/channels/1308047705309708348/1405501315160739951) (`#composable-frontend` channel)
312
386
 
313
387
  <!-- AUTO GENERATED CHANGELOG -->
314
388
 
@@ -316,8 +390,35 @@ await validateJson({
316
390
 
317
391
  Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/api-gen/CHANGELOG.md)
318
392
 
319
- ### Latest changes: 1.3.2
393
+ ### Latest changes: 1.4.0
394
+
395
+ ### Minor Changes
396
+
397
+ - [#2181](https://github.com/shopware/frontends/pull/2181) [`ed72205`](https://github.com/shopware/frontends/commit/ed72205853e9fc40db513f8a4d08acf2dd7b1fba) Thanks [@patzick](https://github.com/patzick)! - Add API-specific configuration support for `store-api` and `admin-api` in `api-gen.config.json`. This allows configuring `rules` and `patches` separately for each API type. Root-level `rules` and `patches` are now deprecated but still supported for backwards compatibility.
398
+
399
+ Example:
400
+
401
+ ```json
402
+ {
403
+ "$schema": "./node_modules/@shopware/api-gen/api-gen.schema.json",
404
+ "store-api": {
405
+ "patches": ["storeApiSchema.overrides.json"],
406
+ "rules": ["COMPONENTS_API_ALIAS"]
407
+ },
408
+ "admin-api": {
409
+ "patches": ["adminApiSchema.overrides.json"]
410
+ }
411
+ }
412
+ ```
413
+
414
+ - [#2126](https://github.com/shopware/frontends/pull/2126) [`e595bc1`](https://github.com/shopware/frontends/commit/e595bc1ea6afe01a0065300277a78ef8c1fe5667) Thanks [@mdanilowicz](https://github.com/mdanilowicz)! - Enhanced OpenAPI schema override merging to properly handle conflicts between `$ref` and composition keywords (`oneOf`, `anyOf`, `allOf`, `not`). When merging overrides:
415
+ - Composition keywords now automatically remove conflicting `$ref` properties
416
+ - `$ref` overrides can replace composition keywords entirely
417
+ - Different composition keywords can replace each other (e.g., `allOf` → `oneOf`)
418
+
419
+ This ensures correct schema merging when using composition keywords in override files, preventing invalid OpenAPI schemas with conflicting `$ref` and composition keyword properties.
320
420
 
321
421
  ### Patch Changes
322
422
 
323
- - [#1939](https://github.com/shopware/frontends/pull/1939) [`cb62cfb`](https://github.com/shopware/frontends/commit/cb62cfb541552ce4e0dc8a02a7a8bddb72ef4de1) Thanks [@patzick](https://github.com/patzick)! - Update typescript version to match openapi-typescript version, causing problems with generating proper schema.
423
+ - Updated dependencies [[`70dcf95`](https://github.com/shopware/frontends/commit/70dcf95d4370c63964d877a5cab113a53f93ca19), [`c77daa6`](https://github.com/shopware/frontends/commit/c77daa6a11e96c7f3688b16f7da010b54c7f5e8b)]:
424
+ - @shopware/api-client@1.4.0
@@ -0,0 +1,99 @@
1
+ {
2
+ "type": "object",
3
+ "additionalProperties": false,
4
+ "$defs": {
5
+ "patchSource": {
6
+ "type": "string",
7
+ "anyOf": [
8
+ {
9
+ "format": "url"
10
+ },
11
+ {
12
+ "format": "file-path"
13
+ },
14
+ {
15
+ "const": "storeApiSchema.overrides.json",
16
+ "description": "Clean core Store API Schema patches"
17
+ },
18
+ {
19
+ "const": "storeApiSchema.b2b.overrides.json",
20
+ "description": "B2B module patches"
21
+ },
22
+ {
23
+ "const": "adminApiSchema.overrides.json",
24
+ "description": "Admin API Schema patches"
25
+ }
26
+ ]
27
+ },
28
+ "rulesArray": {
29
+ "type": "array",
30
+ "uniqueItems": true,
31
+ "items": {
32
+ "anyOf": [
33
+ {
34
+ "const": "COMPONENTS_API_ALIAS",
35
+ "description": "Enforce proper apiAlias fields on components"
36
+ }
37
+ ]
38
+ }
39
+ },
40
+ "patchesConfig": {
41
+ "oneOf": [
42
+ {
43
+ "$ref": "#/$defs/patchSource"
44
+ },
45
+ {
46
+ "type": "array",
47
+ "items": {
48
+ "$ref": "#/$defs/patchSource"
49
+ }
50
+ }
51
+ ]
52
+ },
53
+ "apiTypeConfig": {
54
+ "type": "object",
55
+ "additionalProperties": false,
56
+ "properties": {
57
+ "rules": {
58
+ "description": "Validation rules to apply for this API type",
59
+ "allOf": [{ "$ref": "#/$defs/rulesArray" }]
60
+ },
61
+ "patches": {
62
+ "description": "Path to a file or files containing patches to apply to the schema",
63
+ "allOf": [{ "$ref": "#/$defs/patchesConfig" }]
64
+ }
65
+ }
66
+ }
67
+ },
68
+ "properties": {
69
+ "$schema": {
70
+ "type": "string",
71
+ "anyOf": [
72
+ {
73
+ "format": "url"
74
+ },
75
+ {
76
+ "format": "file-path"
77
+ }
78
+ ]
79
+ },
80
+ "store-api": {
81
+ "description": "Configuration specific to Store API type generation",
82
+ "allOf": [{ "$ref": "#/$defs/apiTypeConfig" }]
83
+ },
84
+ "admin-api": {
85
+ "description": "Configuration specific to Admin API type generation",
86
+ "allOf": [{ "$ref": "#/$defs/apiTypeConfig" }]
87
+ },
88
+ "rules": {
89
+ "deprecated": true,
90
+ "description": "DEPRECATED: Use 'store-api.rules' or 'admin-api.rules' instead.",
91
+ "allOf": [{ "$ref": "#/$defs/rulesArray" }]
92
+ },
93
+ "patches": {
94
+ "deprecated": true,
95
+ "description": "DEPRECATED: Use 'store-api.patches' or 'admin-api.patches' instead.",
96
+ "allOf": [{ "$ref": "#/$defs/patchesConfig" }]
97
+ }
98
+ }
99
+ }