@shopware/api-gen 1.3.3 → 1.5.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:
110
111
 
111
112
  ```json
112
113
  {
113
- "$schema": "https://raw.githubusercontent.com/shopware/frontends/main/packages/api-gen/api-gen.schema.json",
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:
134
+
135
+ ```json
136
+ {
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
 
@@ -223,11 +252,22 @@ Remember to add `.env` file in order to authenticate with Shopware instance.
223
252
  OPENAPI_JSON_URL="https://your-shop-instance.shopware.store"
224
253
  ## This one needed to fetch store API schema
225
254
  OPENAPI_ACCESS_KEY="YOUR_STORE_API_ACCESS_KEY"
226
- ## These two needed to fetch admin API schema
255
+
256
+ ## Admin API authentication (choose one method):
257
+
258
+ ## Option 1: Password grant (username/password)
227
259
  SHOPWARE_ADMIN_USERNAME="my@username.com"
228
260
  SHOPWARE_ADMIN_PASSWORD="my-password"
261
+
262
+ ## Option 2: Client credentials grant (integration)
263
+ ## Create an integration in Shopware Admin > Settings > System > Integrations
264
+ # SHOPWARE_ADMIN_CLIENT_ID="your-integration-client-id"
265
+ # SHOPWARE_ADMIN_CLIENT_SECRET="your-integration-secret"
229
266
  ```
230
267
 
268
+ > [!NOTE]
269
+ > When `SHOPWARE_ADMIN_CLIENT_SECRET` is set, the client credentials grant will be used automatically. Otherwise, the password grant with username/password is used.
270
+
231
271
  ### `validateJson`
232
272
 
233
273
  This command allow to validate the output JSON file of your instance. You can configure which rules should be applied, we provide you with the schema configuration file, so you can easily modify it.
@@ -245,16 +285,50 @@ this searches for `api-types/storeApiTypes.json` file and validates it. Use [loa
245
285
 
246
286
  Prepare your config file named **api-gen.config.json**:
247
287
 
248
- ```JSON
288
+ ```json
249
289
  {
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
290
+ "$schema": "./node_modules/@shopware/api-gen/api-gen.schema.json",
291
+ "store-api": {
292
+ "rules": ["COMPONENTS_API_ALIAS"],
293
+ "patches": ["storeApiSchema.overrides.json"]
294
+ },
295
+ "admin-api": {
296
+ "rules": ["COMPONENTS_API_ALIAS"],
297
+ "patches": ["adminApiSchema.overrides.json"]
298
+ }
255
299
  }
256
300
  ```
257
301
 
302
+ > [!NOTE]
303
+ > The `rules` configuration is API-type specific. When running `validateJson --apiType=store`, only the rules defined in `store-api.rules` will be applied.
304
+
305
+ ### `split` - Experimental
306
+
307
+ 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.
308
+
309
+ 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
310
+ causing performance issues or import failures due to the file size or circular references. This command helps developers to extract only the parts of
311
+ the schema they need and then import it to the API client of their choice.
312
+
313
+ Example usage:
314
+
315
+ ```bash
316
+ # Display all available tags
317
+ pnpx @shopware/api-gen split <path-to-schema-file> --list tags
318
+
319
+ # Display all available paths
320
+ pnpx @shopware/api-gen split <path-to-schema-file> --list paths
321
+
322
+ # Split schema by tags and show detailed linting errors
323
+ pnpx @shopware/api-gen split <path-to-schema-file> --splitBy=tags --outputDir <output-directory> --verbose-linting
324
+
325
+ # Split schema by a single tag
326
+ pnpx @shopware/api-gen split <path-to-schema-file> --splitBy=tags --outputDir <output-directory> --filterBy "media"
327
+
328
+ # Split schema by a single path
329
+ pnpx @shopware/api-gen split <path-to-schema-file> --splitBy=paths --outputDir <output-directory> --filterBy "/api/_action/media/{mediaId}/upload"
330
+ ```
331
+
258
332
  ### Programmatic usage
259
333
 
260
334
  Each command can also be used programmatically within your own scripts:
@@ -299,16 +373,27 @@ await validateJson({
299
373
  });
300
374
  ```
301
375
 
376
+ #### `split`
377
+
378
+ ```ts
379
+ import { split } from "@shopware/api-gen";
380
+
381
+ await split({
382
+ schemaFile: "path/to/your/schema.json",
383
+ outputDir: "path/to/output/directory",
384
+ splitBy: "tags", // or "paths"
385
+ // filterBy: "TagName" // optional filter
386
+ });
387
+ ```
388
+
302
389
  > [!NOTE]
303
390
  > Make sure that the required environment variables are set for the node process when executing commands programmatically.
304
391
 
305
392
  ## Links
306
393
 
307
- - [🧑‍🎓 Tutorial](https://api-client-tutorial-composable-frontends.pages.dev)
308
-
309
394
  - [📘 Documentation](https://frontends.shopware.com)
310
395
 
311
- - [👥 Community Slack](https://shopwarecommunity.slack.com) (`#composable-frontends` channel)
396
+ - [👥 Community Discord](https://discord.com/channels/1308047705309708348/1405501315160739951) (`#composable-frontend` channel)
312
397
 
313
398
  <!-- AUTO GENERATED CHANGELOG -->
314
399
 
@@ -316,8 +401,13 @@ await validateJson({
316
401
 
317
402
  Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/api-gen/CHANGELOG.md)
318
403
 
319
- ### Latest changes: 1.3.3
404
+ ### Latest changes: 1.5.0
405
+
406
+ ### Minor Changes
407
+
408
+ - [#2262](https://github.com/shopware/frontends/pull/2262) [`7a20ea0`](https://github.com/shopware/frontends/commit/7a20ea0454ee237c772e532a03408477e968a958) Thanks [@mkucmus](https://github.com/mkucmus)! - Added support for `client_credentials` grant type authentication when loading Admin API schema. Set `SHOPWARE_ADMIN_CLIENT_SECRET` and `SHOPWARE_ADMIN_CLIENT_ID`environment variables to use integration credentials instead of username/password.
320
409
 
321
410
  ### Patch Changes
322
411
 
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.
412
+ - Updated dependencies [[`9604f22`](https://github.com/shopware/frontends/commit/9604f22678150d04c3c3156fd8ee2ce440c8c8bf), [`b5f7e2a`](https://github.com/shopware/frontends/commit/b5f7e2a20c9dfdde1690e9006252d847f732bc0a), [`9604f22`](https://github.com/shopware/frontends/commit/9604f22678150d04c3c3156fd8ee2ce440c8c8bf)]:
413
+ - @shopware/api-client@1.5.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
+ }