apify-schema-tools 2.0.5 → 2.1.1
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/CHANGELOG.md +25 -0
- package/README.md +109 -45
- package/dist/apify-schema-tools.js +8 -0
- package/dist/apify-schema-tools.js.map +1 -1
- package/dist/typescript.d.ts +1 -0
- package/dist/typescript.d.ts.map +1 -1
- package/dist/typescript.js +112 -65
- package/dist/typescript.js.map +1 -1
- package/package.json +1 -1
- package/samples/all-defaults/src/generated/dataset.ts +1 -0
- package/samples/all-defaults/src/generated/input-utils.ts +2 -0
- package/samples/all-defaults/src/generated/input.ts +2 -0
- package/samples/all-defaults/src-schemas/input.json +6 -3
- package/samples/deep-merged-schemas/src/generated/dataset.ts +1 -0
- package/samples/deep-merged-schemas/src/generated/input-utils.ts +2 -0
- package/samples/deep-merged-schemas/src/generated/input.ts +2 -0
- package/samples/deep-merged-schemas/src-schemas/input.json +6 -3
- package/samples/merged-schemas/src/generated/dataset.ts +1 -0
- package/samples/merged-schemas/src/generated/input-utils.ts +2 -0
- package/samples/merged-schemas/src/generated/input.ts +3 -0
- package/samples/merged-schemas/src-schemas/input.json +6 -3
- package/samples/package-json-config/custom-src-schemas/input.json +6 -3
- package/samples/package-json-config/src/custom-generated/dataset.ts +1 -0
- package/samples/package-json-config/src/custom-generated/input-utils.ts +2 -0
- package/samples/package-json-config/src/custom-generated/input.ts +2 -0
- package/src/apify-schema-tools.ts +8 -0
- package/src/typescript.ts +139 -76
- package/test/apify-schema-tools.test.ts +75 -1
- package/test/json-schemas.test.ts +55 -38
- package/test/typescript.test.ts +246 -26
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.1.1
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Fixed conversion when an object has only `additionalProperties` and no `properties`.
|
|
8
|
+
|
|
9
|
+
### Documentation
|
|
10
|
+
|
|
11
|
+
- Fixed commands in README file.
|
|
12
|
+
|
|
13
|
+
## 2.1.0
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- Support for JSON schema's `additionalProperties` field.
|
|
18
|
+
- `additionalProperties` is set to true by default.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- The `init` command will not override existing source schemas anymore.
|
|
23
|
+
|
|
24
|
+
### Documentation
|
|
25
|
+
|
|
26
|
+
- The new features of v2 are now documented in the README file.
|
|
27
|
+
|
|
3
28
|
## 2.0.5
|
|
4
29
|
|
|
5
30
|
### Fixed
|
package/README.md
CHANGED
|
@@ -50,8 +50,75 @@ Let's assume you are starting from a new project created from an
|
|
|
50
50
|
npm i -D apify-schema-tools
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
2. Initialize your project with default settings:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
npx apify-schema-tools init
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
This command will:
|
|
60
|
+
- Create a `src-schemas` folder with `input.json` and `dataset-item.json` files.
|
|
61
|
+
- Create the necessary `.actor` files if they don't exist.
|
|
62
|
+
- Add configuration to your `package.json`.
|
|
63
|
+
- Add a `generate` script to your `package.json`.
|
|
64
|
+
|
|
65
|
+
3. Generate JSON schemas and TypeScript types from the source schemas:
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
npx apify-schema-tools sync
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
4. Now, you will be able to use TypeScript types and utilities in your project:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { Actor } from 'apify';
|
|
75
|
+
|
|
76
|
+
import type { DatasetItem } from './generated/dataset.ts';
|
|
77
|
+
import type { Input } from './generated/input.ts';
|
|
78
|
+
import { getInputWithDefaultValues, type InputWithDefaults } from './generated/input-utils.ts';
|
|
79
|
+
|
|
80
|
+
await Actor.init();
|
|
81
|
+
|
|
82
|
+
const input: InputWithDefaults = getInputWithDefaultValues(await Actor.getInput<Input>());
|
|
83
|
+
|
|
84
|
+
'...'
|
|
85
|
+
|
|
86
|
+
await Actor.pushData<DatasetItem>({
|
|
87
|
+
tile: '...',
|
|
88
|
+
url: '...',
|
|
89
|
+
text: '...',
|
|
90
|
+
timestamp: '...',
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
await Actor.exit();
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Configuration
|
|
97
|
+
|
|
98
|
+
You can configure `apify-schema-tools` in two ways:
|
|
99
|
+
|
|
100
|
+
### Using package.json configuration
|
|
101
|
+
|
|
102
|
+
The `init` command automatically adds configuration to your `package.json`. You can also manually add an `apify-schema-tools` section to customize the behavior:
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"name": "my-actor",
|
|
107
|
+
"version": "1.0.0",
|
|
108
|
+
"apify-schema-tools": {
|
|
109
|
+
"input": ["input", "dataset"],
|
|
110
|
+
"output": ["json-schemas", "ts-types"],
|
|
111
|
+
"srcInput": "src-schemas/input.json",
|
|
112
|
+
"srcDataset": "src-schemas/dataset-item.json",
|
|
113
|
+
"outputTSDir": "src/generated",
|
|
114
|
+
"includeInputUtils": true
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Using command-line arguments
|
|
120
|
+
|
|
121
|
+
You can also pass options directly to the `sync` command. You can check which options are available:
|
|
55
122
|
|
|
56
123
|
```console
|
|
57
124
|
$ npx apify-schema-tools --help
|
|
@@ -69,8 +136,6 @@ optional arguments:
|
|
|
69
136
|
-h, --help show this help message and exit
|
|
70
137
|
```
|
|
71
138
|
|
|
72
|
-
You can also check the options available for a specific command:
|
|
73
|
-
|
|
74
139
|
```console
|
|
75
140
|
$ npx apify-schema-tools sync --help
|
|
76
141
|
usage: apify-schema-tools sync [-h] [-i [{input,dataset} ...]] [-o [{json-schemas,ts-types} ...]] [--src-input SRC_INPUT] [--src-dataset SRC_DATASET] [--add-input ADD_INPUT] [--add-dataset ADD_DATASET] [--input-schema INPUT_SCHEMA] [--dataset-schema DATASET_SCHEMA] [--output-ts-dir OUTPUT_TS_DIR]
|
|
@@ -101,16 +166,17 @@ optional arguments:
|
|
|
101
166
|
include input utilities in the generated TypeScript files: 'input' input and 'ts-types' output are required (default: true)
|
|
102
167
|
```
|
|
103
168
|
|
|
104
|
-
|
|
105
|
-
In this case, we will use the default locations, so the commands will be simpler.
|
|
169
|
+
## Setting up your project manually
|
|
106
170
|
|
|
107
|
-
|
|
171
|
+
If you prefer to set up your project manually instead of using the `init` command, you can follow these steps:
|
|
172
|
+
|
|
173
|
+
1. Create a `src-schemas` folder:
|
|
108
174
|
|
|
109
175
|
```sh
|
|
110
176
|
mkdir src-schemas
|
|
111
177
|
```
|
|
112
178
|
|
|
113
|
-
|
|
179
|
+
2. Create the files `input.json` and `dataset-item.json` inside the `src-schemas`. Here is some example content:
|
|
114
180
|
|
|
115
181
|
```json
|
|
116
182
|
{
|
|
@@ -132,7 +198,8 @@ mkdir src-schemas
|
|
|
132
198
|
}
|
|
133
199
|
}
|
|
134
200
|
},
|
|
135
|
-
"required": ["startUrls"]
|
|
201
|
+
"required": ["startUrls"],
|
|
202
|
+
"additionalProperties": false
|
|
136
203
|
}
|
|
137
204
|
```
|
|
138
205
|
|
|
@@ -167,7 +234,7 @@ mkdir src-schemas
|
|
|
167
234
|
}
|
|
168
235
|
```
|
|
169
236
|
|
|
170
|
-
|
|
237
|
+
3. Create the file `.actor/dataset_schema.json` and enter some empty content:
|
|
171
238
|
|
|
172
239
|
```json
|
|
173
240
|
{
|
|
@@ -177,7 +244,7 @@ mkdir src-schemas
|
|
|
177
244
|
}
|
|
178
245
|
```
|
|
179
246
|
|
|
180
|
-
|
|
247
|
+
4. Link the dataset schema in `.actor/actor.json`:
|
|
181
248
|
|
|
182
249
|
```json
|
|
183
250
|
{
|
|
@@ -191,49 +258,40 @@ mkdir src-schemas
|
|
|
191
258
|
}
|
|
192
259
|
```
|
|
193
260
|
|
|
194
|
-
6. Add the script to `package.json`:
|
|
195
|
-
|
|
196
|
-
```json
|
|
197
|
-
{
|
|
198
|
-
"...": "...",
|
|
199
|
-
"scripts": {
|
|
200
|
-
"...": "...",
|
|
201
|
-
"generate": "apify-schema-tools sync"
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
```
|
|
205
261
|
|
|
206
|
-
|
|
262
|
+
5. Generate JSON schemas and TypeScript types from the source schemas:
|
|
207
263
|
|
|
208
264
|
```sh
|
|
209
|
-
|
|
265
|
+
npx apify-schema-tools sync
|
|
210
266
|
```
|
|
211
267
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
```ts
|
|
215
|
-
import { Actor } from 'apify';
|
|
268
|
+
## Checking if the schemas are in sync with the source schemas
|
|
216
269
|
|
|
217
|
-
|
|
218
|
-
import type { Input } from './generated/input.ts';
|
|
219
|
-
import { getInputWithDefaultValues, type InputWithDefaults } from './generated/input-utils.ts';
|
|
270
|
+
The `check` command allows you to verify that your generated schemas and TypeScript files are up-to-date with your source schemas. This is particularly useful in CI/CD pipelines to ensure that developers haven't forgotten to run the generation after making changes to the source schemas.
|
|
220
271
|
|
|
221
|
-
|
|
272
|
+
```sh
|
|
273
|
+
npx apify-schema-tools check
|
|
274
|
+
```
|
|
222
275
|
|
|
223
|
-
|
|
276
|
+
The `check` command will:
|
|
277
|
+
- Compare the current generated files with what would be generated from the source schemas
|
|
278
|
+
- Exit with code 0 if everything is in sync
|
|
279
|
+
- Exit with code 1 if there are differences, showing you which files are out of sync
|
|
224
280
|
|
|
225
|
-
|
|
281
|
+
You can add this to your CI pipeline to automatically detect when schemas need to be regenerated:
|
|
226
282
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
283
|
+
```json
|
|
284
|
+
{
|
|
285
|
+
"scripts": {
|
|
286
|
+
"generate": "apify-schema-tools sync",
|
|
287
|
+
"check-schemas": "apify-schema-tools check",
|
|
288
|
+
"test": "npm run check-schemas && npm run test:unit"
|
|
289
|
+
}
|
|
290
|
+
}
|
|
235
291
|
```
|
|
236
292
|
|
|
293
|
+
The `check` command accepts the same configuration options as the `sync` command, either through `package.json` configuration or command-line arguments, ensuring it checks the same files that would be generated.
|
|
294
|
+
|
|
237
295
|
## Extra features
|
|
238
296
|
|
|
239
297
|
### Keep only allowed properties in Input schema
|
|
@@ -273,12 +331,14 @@ An example:
|
|
|
273
331
|
{
|
|
274
332
|
"title": "My input schema",
|
|
275
333
|
"description": "My input properties",
|
|
334
|
+
"type": "object",
|
|
276
335
|
"properties": {
|
|
277
336
|
"a": { "type": "string", "position": 3 },
|
|
278
337
|
"b": { "type": "string" }, // will be last, because it has no position
|
|
279
338
|
"c": { "type": "string", "position": 1 }
|
|
280
339
|
},
|
|
281
|
-
"required": ["a"]
|
|
340
|
+
"required": ["a"],
|
|
341
|
+
"additionalProperties": false
|
|
282
342
|
}
|
|
283
343
|
```
|
|
284
344
|
|
|
@@ -286,11 +346,13 @@ An example:
|
|
|
286
346
|
# Additional input schema
|
|
287
347
|
{
|
|
288
348
|
"description": "My input properties, a bit changed", // will override the description
|
|
349
|
+
"type": "object",
|
|
289
350
|
"properties": {
|
|
290
351
|
"c": { "type": "boolean", "position": 5 }, // will override also the position
|
|
291
352
|
"d": { "type": "string", "position": 1 } // will be first
|
|
292
353
|
},
|
|
293
|
-
"required": ["c", "d"] // will be merged to the source required parameters
|
|
354
|
+
"required": ["c", "d"], // will be merged to the source required parameters
|
|
355
|
+
"additionalProperties": false
|
|
294
356
|
}
|
|
295
357
|
```
|
|
296
358
|
|
|
@@ -299,13 +361,15 @@ An example:
|
|
|
299
361
|
{
|
|
300
362
|
"title": "My input schema",
|
|
301
363
|
"description": "My input properties, a bit changed",
|
|
364
|
+
"type": "object",
|
|
302
365
|
"properties": {
|
|
303
366
|
"d": { "type": "string" },
|
|
304
367
|
"a": { "type": "string" },
|
|
305
368
|
"c": { "type": "boolean" },
|
|
306
369
|
"b": { "type": "string" }
|
|
307
370
|
},
|
|
308
|
-
"required": ["a", "c", "d"]
|
|
371
|
+
"required": ["a", "c", "d"],
|
|
372
|
+
"additionalProperties": false
|
|
309
373
|
}
|
|
310
374
|
```
|
|
311
375
|
|
|
@@ -37,6 +37,10 @@ initParser.add_argument("--only-config-file", {
|
|
|
37
37
|
default: false,
|
|
38
38
|
});
|
|
39
39
|
function initializeInputSchema(args) {
|
|
40
|
+
if (existsSync(args.src_input)) {
|
|
41
|
+
console.log(`Input schema already exists at ${args.src_input}, skipping initialization.`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
40
44
|
if (!existsSync(args.input_schema)) {
|
|
41
45
|
throw new Error("The current Actor does not have an input schema.");
|
|
42
46
|
}
|
|
@@ -71,6 +75,10 @@ function initializeDatasetSchema(args) {
|
|
|
71
75
|
}, null, 4));
|
|
72
76
|
console.log(`Dataset schema initialized at ${args.dataset_schema}`);
|
|
73
77
|
}
|
|
78
|
+
if (existsSync(args.src_dataset)) {
|
|
79
|
+
console.log(`Dataset schema already exists at ${args.src_dataset}, skipping initialization.`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
74
82
|
const datasetItemSchema = readJsonSchemaField(args.dataset_schema, DATASET_SCHEMA_FIELD);
|
|
75
83
|
writeJsonSchema(args.src_dataset, datasetItemSchema);
|
|
76
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apify-schema-tools.js","sourceRoot":"","sources":["../src/apify-schema-tools.ts"],"names":[],"mappings":";AAEA,oGAAoG;AAEpG,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,6BAA6B,EAAwB,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/F,OAAO,EACN,i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EAAE,YAAY,CAAC,CAAC,CAAC;QAC1E,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAC9F,MAAM,wBAAwB,GAAG,+BAA+B,CAAC,mBAAmB,CAAC,CAAC;QACtF,MAAM,mBAAmB,GAAG,2BAA2B,CACtD,wBAAwB,EACxB,kBAAkB,EAClB,IAAI,CAAC,mBAAmB,CACxB,CAAC;QACF,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC1B,OAAO,CAAC,KAAK,CACZ,4GAA4G,CAC5G,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC;IACF,CAAC;AACF,CAAC;AAED,SAAS,KAAK,CAAC,IAAe;IAC7B,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IACD,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACpC,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAC9B,CAAC;AAED,WAAW,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAE1C,oBAAoB;AAEpB,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,EAAE,CAAC;AAC3C,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC"}
|
package/dist/typescript.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ interface TypeScriptEnum extends TypeScriptBasicData {
|
|
|
14
14
|
}
|
|
15
15
|
export interface TypeScriptInterface extends TypeScriptBasicData {
|
|
16
16
|
properties: Record<string, TypeScriptSchema>;
|
|
17
|
+
additionalProperties?: TypeScriptSchema;
|
|
17
18
|
}
|
|
18
19
|
export type TypeScriptSchema = TypeScriptBasicType | TypeScriptEnum | TypeScriptInterface;
|
|
19
20
|
export declare function jsonSchemaToTypeScriptInterface(schema: ObjectSchema): TypeScriptInterface;
|
package/dist/typescript.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../src/typescript.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiC,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAuBrF,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAE3E;AAED,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGpE;AAED,UAAU,mBAAmB;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CACjB;AAED,UAAU,mBAAoB,SAAQ,mBAAmB;IACxD,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACxB;AAMD,UAAU,cAAe,SAAQ,mBAAmB;IACnD,IAAI,EAAE,OAAO,EAAE,CAAC;CAChB;AAMD,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB;IAC/D,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../src/typescript.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiC,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAuBrF,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAE3E;AAED,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGpE;AAED,UAAU,mBAAmB;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CACjB;AAED,UAAU,mBAAoB,SAAQ,mBAAmB;IACxD,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACxB;AAMD,UAAU,cAAe,SAAQ,mBAAmB;IACnD,IAAI,EAAE,OAAO,EAAE,CAAC;CAChB;AAMD,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB;IAC/D,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC7C,oBAAoB,CAAC,EAAE,gBAAgB,CAAC;CACxC;AAMD,MAAM,MAAM,gBAAgB,GAAG,mBAAmB,GAAG,cAAc,GAAG,mBAAmB,CAAC;AAyF1F,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,YAAY,GAAG,mBAAmB,CAEzF;AAoCD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,gBAAgB,EAAE,WAAW,SAAI,GAAG,MAAM,CAa3F;AAED,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAI9F;AAID,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAQlE;AAgMD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAe1E;AAoFD,wBAAgB,2BAA2B,CAC1C,CAAC,EAAE,mBAAmB,EACtB,CAAC,EAAE,mBAAmB,EACtB,UAAU,CAAC,EAAE,OAAO,GAClB,OAAO,CAwBT"}
|
package/dist/typescript.js
CHANGED
|
@@ -37,7 +37,15 @@ function createTypeScriptInterface(schema, doc, isArray, isRequired) {
|
|
|
37
37
|
const properties = Object.fromEntries(Object.entries(schema.properties ?? {}).map(([key, value]) => {
|
|
38
38
|
return [key, jsonSchemaToTypeScriptSchema(value, false, requiredProperties.includes(key))];
|
|
39
39
|
}));
|
|
40
|
-
|
|
40
|
+
let additionalProperties;
|
|
41
|
+
if (schema.additionalProperties === true || schema.additionalProperties === undefined) {
|
|
42
|
+
// If additionalProperties is true or undefined, we parse it as an "empty" schema
|
|
43
|
+
additionalProperties = { doc: undefined, isArray: false, isRequired: true, type: "unknown" };
|
|
44
|
+
}
|
|
45
|
+
else if (schema.additionalProperties !== false) {
|
|
46
|
+
additionalProperties = jsonSchemaToTypeScriptSchema(schema.additionalProperties, false, true);
|
|
47
|
+
}
|
|
48
|
+
return { doc, isArray, isRequired, properties, additionalProperties };
|
|
41
49
|
}
|
|
42
50
|
function createTypeScriptArraySchema(schema, doc, isRequired) {
|
|
43
51
|
if (Array.isArray(schema.items)) {
|
|
@@ -86,7 +94,7 @@ export function jsonSchemaToTypeScriptInterface(schema) {
|
|
|
86
94
|
function serializeInterfaceSchema(schema, indentLevel) {
|
|
87
95
|
const indent = "\t".repeat(indentLevel);
|
|
88
96
|
const properties = Object.entries(schema.properties);
|
|
89
|
-
if (properties.length === 0) {
|
|
97
|
+
if (properties.length === 0 && !schema.additionalProperties) {
|
|
90
98
|
return "{}";
|
|
91
99
|
}
|
|
92
100
|
const innerIndentLevel = indentLevel + 1;
|
|
@@ -98,6 +106,9 @@ function serializeInterfaceSchema(schema, indentLevel) {
|
|
|
98
106
|
}
|
|
99
107
|
result += `\n${innerIndent}${key}${value.isRequired ? "" : "?"}: ${serializeTypeScriptSchema(value, innerIndentLevel)};`;
|
|
100
108
|
}
|
|
109
|
+
if (schema.additionalProperties) {
|
|
110
|
+
result += `\n${innerIndent}[key: string]: ${serializeTypeScriptSchema(schema.additionalProperties, innerIndentLevel)};`;
|
|
111
|
+
}
|
|
101
112
|
result += `\n${indent}}`;
|
|
102
113
|
return result;
|
|
103
114
|
}
|
|
@@ -142,29 +153,6 @@ export function removeTypeScriptHeader(fileContent) {
|
|
|
142
153
|
const headerEndIndex = headerMatch.index + headerMatch[0].length;
|
|
143
154
|
return fileContent.slice(headerEndIndex).trim();
|
|
144
155
|
}
|
|
145
|
-
function parseInterfaceProperties(body) {
|
|
146
|
-
const properties = {};
|
|
147
|
-
let i = 0;
|
|
148
|
-
let currentDoc;
|
|
149
|
-
while (i < body.length) {
|
|
150
|
-
i = skipWhitespace(body, i);
|
|
151
|
-
const docResult = tryParseJsDoc(body, i);
|
|
152
|
-
if (docResult) {
|
|
153
|
-
currentDoc = docResult.doc;
|
|
154
|
-
i = docResult.nextIndex;
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
const propResult = tryParseProperty(body, i, currentDoc);
|
|
158
|
-
if (propResult) {
|
|
159
|
-
properties[propResult.propName] = propResult.schema;
|
|
160
|
-
currentDoc = undefined;
|
|
161
|
-
i = propResult.nextIndex;
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
i++;
|
|
165
|
-
}
|
|
166
|
-
return properties;
|
|
167
|
-
}
|
|
168
156
|
const WHITESPACE_REGEX = /\s/;
|
|
169
157
|
function skipWhitespace(body, i) {
|
|
170
158
|
let cursor = i;
|
|
@@ -190,30 +178,47 @@ function tryParseJsDoc(body, i) {
|
|
|
190
178
|
}
|
|
191
179
|
return null;
|
|
192
180
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
let
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
181
|
+
function extractTypeString(body, i) {
|
|
182
|
+
let braceDepth = 0;
|
|
183
|
+
let typeEnd = i;
|
|
184
|
+
while (typeEnd < body.length) {
|
|
185
|
+
const char = body[typeEnd];
|
|
186
|
+
if (char === "{") {
|
|
187
|
+
braceDepth++;
|
|
188
|
+
}
|
|
189
|
+
else if (char === "}") {
|
|
190
|
+
braceDepth--;
|
|
191
|
+
if (braceDepth < 0) {
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else if (char === ";" && braceDepth === 0) {
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
typeEnd++;
|
|
199
199
|
}
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
200
|
+
let typeStr = body.slice(i, typeEnd).trim();
|
|
201
|
+
const isArray = typeStr.endsWith("[]");
|
|
202
|
+
if (isArray) {
|
|
203
|
+
typeStr = typeStr.slice(0, -2).trim();
|
|
204
|
+
}
|
|
205
|
+
return { typeStr, isArray, typeEnd };
|
|
206
|
+
}
|
|
207
|
+
function extractSchemaFromText(text, currentDoc, isRequired, isArray) {
|
|
204
208
|
let schema;
|
|
205
|
-
if (
|
|
206
|
-
const objectBody =
|
|
207
|
-
const nestedProperties = parseInterfaceProperties(objectBody);
|
|
209
|
+
if (text.startsWith("{") && text.endsWith("}")) {
|
|
210
|
+
const objectBody = text.slice(1, -1);
|
|
211
|
+
const { properties: nestedProperties, additionalProperties: additionalNestedProperties } = parseInterfaceProperties(objectBody);
|
|
208
212
|
schema = {
|
|
209
213
|
doc: currentDoc,
|
|
210
214
|
isArray,
|
|
211
215
|
isRequired,
|
|
212
216
|
properties: nestedProperties,
|
|
217
|
+
additionalProperties: additionalNestedProperties,
|
|
213
218
|
};
|
|
214
219
|
}
|
|
215
|
-
else if (
|
|
216
|
-
const unionBody = isArray ?
|
|
220
|
+
else if (text.includes("|")) {
|
|
221
|
+
const unionBody = isArray ? text.slice(1, -1) : text;
|
|
217
222
|
const unionParts = unionBody.split("|").map((part) => part.trim());
|
|
218
223
|
if (unionParts.every((part) => isAllowedType(part))) {
|
|
219
224
|
schema = {
|
|
@@ -234,7 +239,7 @@ function tryParseProperty(body, i, currentDoc) {
|
|
|
234
239
|
};
|
|
235
240
|
}
|
|
236
241
|
catch {
|
|
237
|
-
throw new Error(`Invalid enum format for
|
|
242
|
+
throw new Error(`Invalid enum format for TypeScript text: ${text}`);
|
|
238
243
|
}
|
|
239
244
|
}
|
|
240
245
|
}
|
|
@@ -243,40 +248,68 @@ function tryParseProperty(body, i, currentDoc) {
|
|
|
243
248
|
doc: currentDoc,
|
|
244
249
|
isArray,
|
|
245
250
|
isRequired,
|
|
246
|
-
type:
|
|
251
|
+
type: text,
|
|
247
252
|
};
|
|
248
253
|
}
|
|
254
|
+
return schema;
|
|
255
|
+
}
|
|
256
|
+
const TYPESCRIPT_ADDITIONAL_PROPERTIES_REGEX = /^\s*\[\s*key\s*:\s*string\s*\]\s*:\s*/;
|
|
257
|
+
const TYPESCRIPT_PROPERTY_REGEX = /^(\w+)(\?)?:\s*/;
|
|
258
|
+
function tryParseProperty(body, i, currentDoc) {
|
|
259
|
+
let cursor = i;
|
|
260
|
+
let propName;
|
|
261
|
+
let isRequired;
|
|
262
|
+
const bodySlice = body.slice(cursor);
|
|
263
|
+
const additionalPropertiesMatch = bodySlice.match(TYPESCRIPT_ADDITIONAL_PROPERTIES_REGEX);
|
|
264
|
+
if (additionalPropertiesMatch) {
|
|
265
|
+
cursor += additionalPropertiesMatch[0].length;
|
|
266
|
+
isRequired = true;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
const propMatch = bodySlice.match(TYPESCRIPT_PROPERTY_REGEX);
|
|
270
|
+
if (!propMatch) {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
propName = propMatch[1];
|
|
274
|
+
isRequired = !propMatch[2];
|
|
275
|
+
cursor += propMatch[0].length;
|
|
276
|
+
}
|
|
277
|
+
const { typeStr, isArray, typeEnd } = extractTypeString(body, cursor);
|
|
278
|
+
const schema = extractSchemaFromText(typeStr, currentDoc, isRequired, isArray);
|
|
249
279
|
let nextIndex = typeEnd;
|
|
250
280
|
if (body[nextIndex] === ";") {
|
|
251
281
|
nextIndex++;
|
|
252
282
|
}
|
|
253
283
|
return { propName, schema, nextIndex };
|
|
254
284
|
}
|
|
255
|
-
function
|
|
256
|
-
|
|
257
|
-
let
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
285
|
+
function parseInterfaceProperties(body) {
|
|
286
|
+
const properties = {};
|
|
287
|
+
let additionalProperties;
|
|
288
|
+
let i = 0;
|
|
289
|
+
let currentDoc;
|
|
290
|
+
while (i < body.length) {
|
|
291
|
+
i = skipWhitespace(body, i);
|
|
292
|
+
const docResult = tryParseJsDoc(body, i);
|
|
293
|
+
if (docResult) {
|
|
294
|
+
currentDoc = docResult.doc;
|
|
295
|
+
i = docResult.nextIndex;
|
|
296
|
+
continue;
|
|
262
297
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (
|
|
266
|
-
|
|
298
|
+
const propResult = tryParseProperty(body, i, currentDoc);
|
|
299
|
+
if (propResult) {
|
|
300
|
+
if (propResult.propName) {
|
|
301
|
+
properties[propResult.propName] = propResult.schema;
|
|
267
302
|
}
|
|
303
|
+
else {
|
|
304
|
+
additionalProperties = propResult.schema;
|
|
305
|
+
}
|
|
306
|
+
currentDoc = undefined;
|
|
307
|
+
i = propResult.nextIndex;
|
|
308
|
+
continue;
|
|
268
309
|
}
|
|
269
|
-
|
|
270
|
-
break;
|
|
271
|
-
}
|
|
272
|
-
typeEnd++;
|
|
273
|
-
}
|
|
274
|
-
let typeStr = body.slice(i, typeEnd).trim();
|
|
275
|
-
const isArray = typeStr.endsWith("[]");
|
|
276
|
-
if (isArray) {
|
|
277
|
-
typeStr = typeStr.slice(0, -2).trim();
|
|
310
|
+
i++;
|
|
278
311
|
}
|
|
279
|
-
return {
|
|
312
|
+
return { properties, additionalProperties };
|
|
280
313
|
}
|
|
281
314
|
const TYPESCRIPT_JSDOC_REGEX = /\/\*\*\s*\n\s*\*\s*(.*?)\s*\n\s*\*\//;
|
|
282
315
|
const TYPESCRIPT_INTERFACE_REGEX = /export interface (\w+) \{([\s\S]*)\}$/;
|
|
@@ -290,8 +323,8 @@ export function parseTypeScriptInterface(text) {
|
|
|
290
323
|
throw new Error("Invalid TypeScript interface format");
|
|
291
324
|
}
|
|
292
325
|
const body = interfaceMatch[2];
|
|
293
|
-
const properties = parseInterfaceProperties(body);
|
|
294
|
-
return { doc, isArray: false, isRequired: true, properties };
|
|
326
|
+
const { properties, additionalProperties } = parseInterfaceProperties(body);
|
|
327
|
+
return { doc, isArray: false, isRequired: true, properties, additionalProperties };
|
|
295
328
|
}
|
|
296
329
|
function compareInterfaceProperty(key, propA, propB, ignoreDocs) {
|
|
297
330
|
if (!isTypeScriptInterface(propB)) {
|
|
@@ -347,6 +380,17 @@ function compareProperty(key, propA, propB, ignoreDocs) {
|
|
|
347
380
|
}
|
|
348
381
|
return compareBasicTypeProperty(key, propA, propB);
|
|
349
382
|
}
|
|
383
|
+
function compareAdditionalProperties(a, b, ignoreDocs) {
|
|
384
|
+
if (!(a.additionalProperties || b.additionalProperties)) {
|
|
385
|
+
return true; // Both have no additional properties
|
|
386
|
+
}
|
|
387
|
+
if (!(a.additionalProperties && b.additionalProperties)) {
|
|
388
|
+
console.error(`One interface has additionalProperties defined, but the other does not.
|
|
389
|
+
If you generated an interface from a JSON schema, pay attention that "additionalProperties" is set to an empty schema by default.`);
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
return compareProperty("[key: string]", a.additionalProperties, b.additionalProperties, ignoreDocs);
|
|
393
|
+
}
|
|
350
394
|
export function compareTypescriptInterfaces(a, b, ignoreDocs) {
|
|
351
395
|
if (Object.keys(a.properties).length !== Object.keys(b.properties).length) {
|
|
352
396
|
console.error("Interfaces have different number of properties.");
|
|
@@ -364,6 +408,9 @@ export function compareTypescriptInterfaces(a, b, ignoreDocs) {
|
|
|
364
408
|
}
|
|
365
409
|
}
|
|
366
410
|
}
|
|
411
|
+
if (!compareAdditionalProperties(a, b, ignoreDocs)) {
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
367
414
|
return true;
|
|
368
415
|
}
|
|
369
416
|
//# sourceMappingURL=typescript.js.map
|