ts-openapi-codegen 2.0.0-beta.1 → 2.0.0-beta.2
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 +71 -55
- package/README.rus.md +71 -54
- package/dist/cli/index.js +2 -1
- package/dist/common/Consts.d.ts.map +1 -1
- package/dist/common/Consts.js +2 -1
- package/dist/common/TRawOptions.d.ts +2 -1
- package/dist/common/TRawOptions.d.ts.map +1 -1
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.d.ts.map +1 -1
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.js +8 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllVersionedSchemas.d.ts.map +1 -1
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllVersionedSchemas.js +7 -1
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV1.d.ts.map +1 -0
- package/dist/common/VersionedSchema/{UnifiedOptionsVersioned → AllVersionedSchemas}/UnifiedOptionsSchemaV1.js +2 -2
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV2.d.ts +7 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV2.d.ts.map +1 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV2.js +42 -0
- package/dist/common/VersionedSchema/CommonSchemas.d.ts +1 -0
- package/dist/common/VersionedSchema/CommonSchemas.d.ts.map +1 -1
- package/dist/common/VersionedSchema/CommonSchemas.js +8 -1
- package/dist/common/defaultOptions.d.ts.map +1 -1
- package/dist/common/defaultOptions.js +2 -1
- package/dist/common/utils/__tests__/convertArrayToObject.test.js +5 -6
- package/dist/common/utils/convertArrayToObject.d.ts.map +1 -1
- package/dist/common/utils/convertArrayToObject.js +1 -2
- package/dist/core/OpenApiClient.d.ts.map +1 -1
- package/dist/core/OpenApiClient.js +6 -4
- package/dist/core/WriteClient.d.ts +3 -12
- package/dist/core/WriteClient.d.ts.map +1 -1
- package/dist/core/WriteClient.js +20 -22
- package/dist/core/__tests__/WriteClient.test.js +6 -1
- package/dist/core/types/enums/ValidationLibrary.enum.d.ts +8 -0
- package/dist/core/types/enums/ValidationLibrary.enum.d.ts.map +1 -0
- package/dist/core/types/enums/ValidationLibrary.enum.js +11 -0
- package/dist/core/utils/__mocks__/templates.d.ts.map +1 -1
- package/dist/core/utils/__mocks__/templates.js +4 -0
- package/dist/core/utils/__tests__/writeClientSchemas.test.js +2 -0
- package/dist/core/utils/precompileTemplates.js +6 -0
- package/dist/core/utils/registerHandlebarHelpers.d.ts.map +1 -1
- package/dist/core/utils/registerHandlebarHelpers.js +74 -0
- package/dist/core/utils/registerHandlebarTemplates.d.ts +6 -0
- package/dist/core/utils/registerHandlebarTemplates.d.ts.map +1 -1
- package/dist/core/utils/registerHandlebarTemplates.js +84 -0
- package/dist/core/utils/writeClientSchemas.d.ts +2 -0
- package/dist/core/utils/writeClientSchemas.d.ts.map +1 -1
- package/dist/core/utils/writeClientSchemas.js +14 -2
- package/dist/templatesCompiled/client/joi/exportSchema.d.ts +11 -0
- package/dist/templatesCompiled/client/joi/exportSchema.d.ts.map +1 -0
- package/dist/templatesCompiled/client/joi/exportSchema.js +71 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchema.d.ts +22 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchema.d.ts.map +1 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchema.js +129 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaArray.d.ts +16 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaArray.d.ts.map +1 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaArray.js +84 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaComposition.d.ts +18 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaComposition.d.ts.map +1 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaComposition.js +96 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaDictionary.d.ts +14 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaDictionary.d.ts.map +1 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaDictionary.js +72 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaEnum.d.ts +14 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaEnum.d.ts.map +1 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaEnum.js +74 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaGeneric.d.ts +35 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaGeneric.d.ts.map +1 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaGeneric.js +201 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaInterface.d.ts +14 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaInterface.d.ts.map +1 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaInterface.js +50 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaReference.d.ts +9 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaReference.d.ts.map +1 -0
- package/dist/templatesCompiled/client/joi/partials/joiSchemaReference.js +25 -0
- package/dist/templatesCompiled/client/jsonschema/exportSchema.d.ts +11 -0
- package/dist/templatesCompiled/client/jsonschema/exportSchema.d.ts.map +1 -0
- package/dist/templatesCompiled/client/jsonschema/exportSchema.js +69 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchema.d.ts +22 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchema.d.ts.map +1 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchema.js +129 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaArray.d.ts +16 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaArray.d.ts.map +1 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaArray.js +74 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaComposition.d.ts +16 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaComposition.d.ts.map +1 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaComposition.js +84 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaDictionary.d.ts +13 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaDictionary.d.ts.map +1 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaDictionary.js +56 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaEnum.d.ts +12 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaEnum.d.ts.map +1 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaEnum.js +49 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaGeneric.d.ts +29 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaGeneric.d.ts.map +1 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaGeneric.js +175 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaInterface.d.ts +15 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaInterface.d.ts.map +1 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaInterface.js +63 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaReference.d.ts +9 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaReference.d.ts.map +1 -0
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaReference.js +25 -0
- package/dist/templatesCompiled/client/yup/exportSchema.d.ts +11 -0
- package/dist/templatesCompiled/client/yup/exportSchema.d.ts.map +1 -0
- package/dist/templatesCompiled/client/yup/exportSchema.js +73 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchema.d.ts +22 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchema.d.ts.map +1 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchema.js +129 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaArray.d.ts +16 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaArray.d.ts.map +1 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaArray.js +84 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaComposition.d.ts +18 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaComposition.d.ts.map +1 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaComposition.js +96 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaDictionary.d.ts +14 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaDictionary.d.ts.map +1 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaDictionary.js +72 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaEnum.d.ts +14 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaEnum.d.ts.map +1 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaEnum.js +74 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaGeneric.d.ts +34 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaGeneric.d.ts.map +1 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaGeneric.js +201 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaInterface.d.ts +14 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaInterface.d.ts.map +1 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaInterface.js +50 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaReference.d.ts +9 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaReference.d.ts.map +1 -0
- package/dist/templatesCompiled/client/yup/partials/yupSchemaReference.js +25 -0
- package/dist/templatesCompiled/client/zod/exportSchema.d.ts +11 -0
- package/dist/templatesCompiled/client/zod/exportSchema.d.ts.map +1 -0
- package/dist/templatesCompiled/client/zod/exportSchema.js +67 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchema.d.ts +22 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchema.d.ts.map +1 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchema.js +129 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaArray.d.ts +14 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaArray.d.ts.map +1 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaArray.js +65 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaComposition.d.ts +15 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaComposition.d.ts.map +1 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaComposition.js +70 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaDictionary.d.ts +12 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaDictionary.d.ts.map +1 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaDictionary.js +53 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaEnum.d.ts +15 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaEnum.d.ts.map +1 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaEnum.js +86 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaGeneric.d.ts +34 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaGeneric.d.ts.map +1 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaGeneric.js +193 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaInterface.d.ts +14 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaInterface.d.ts.map +1 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaInterface.js +50 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaReference.d.ts +9 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaReference.d.ts.map +1 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaReference.js +25 -0
- package/package.json +12 -3
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsMigrationPlan.d.ts +0 -3
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsMigrationPlan.d.ts.map +0 -1
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsMigrationPlan.js +0 -28
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsSchemaV1.d.ts.map +0 -1
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsVersionedSchemas.d.ts +0 -3
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsVersionedSchemas.d.ts.map +0 -1
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsVersionedSchemas.js +0 -10
- /package/dist/common/VersionedSchema/{UnifiedOptionsVersioned → AllVersionedSchemas}/UnifiedOptionsSchemaV1.d.ts +0 -0
package/README.md
CHANGED
|
@@ -64,7 +64,6 @@ openapi generate --input ./spec.json --output ./dist
|
|
|
64
64
|
| `--useOptions` | - | boolean | `false` | Use options instead of arguments |
|
|
65
65
|
| `--useUnionTypes` | - | boolean | `false` | Use union types instead of enums |
|
|
66
66
|
| `--excludeCoreServiceFiles` | - | boolean | `false` | Exclude generation of core and service files |
|
|
67
|
-
| `--includeSchemasFiles` | - | boolean | `false` | Enable generation of model validation schemas |
|
|
68
67
|
| `--request` | - | string | - | Path to custom request file |
|
|
69
68
|
| `--interfacePrefix` | - | string | `I` | Prefix for interface models |
|
|
70
69
|
| `--enumPrefix` | - | string | `E` | Prefix for enum models |
|
|
@@ -74,6 +73,7 @@ openapi generate --input ./spec.json --output ./dist
|
|
|
74
73
|
| `--useSeparatedIndexes` | - | boolean | `false` | Use separate index files for core, models, schemas, and services |
|
|
75
74
|
| `--logLevel` | `-l` | string | `error` | Logging level: `info`, `warn`, or `error` |
|
|
76
75
|
| `--logTarget` | `-t` | string | `console` | Logging target: `console` or `file` |
|
|
76
|
+
| `--validationLibrary` | - | string | `none` | Validation library for schema generation: `none`, `zod`, `joi`, `yup`, or `jsonschema` |
|
|
77
77
|
|
|
78
78
|
**Examples:**
|
|
79
79
|
```bash
|
|
@@ -93,7 +93,6 @@ openapi generate \
|
|
|
93
93
|
--httpClient fetch \
|
|
94
94
|
--useOptions \
|
|
95
95
|
--useUnionTypes \
|
|
96
|
-
--includeSchemasFiles \
|
|
97
96
|
--logLevel info
|
|
98
97
|
```
|
|
99
98
|
|
|
@@ -143,7 +142,6 @@ Instead of passing all options via CLI, you can use a configuration file. Create
|
|
|
143
142
|
"useOptions": false,
|
|
144
143
|
"useUnionTypes": false,
|
|
145
144
|
"excludeCoreServiceFiles": false,
|
|
146
|
-
"includeSchemasFiles": false,
|
|
147
145
|
"interfacePrefix": "I",
|
|
148
146
|
"enumPrefix": "E",
|
|
149
147
|
"typePrefix": "T",
|
|
@@ -160,7 +158,6 @@ Instead of passing all options via CLI, you can use a configuration file. Create
|
|
|
160
158
|
"output": "./dist",
|
|
161
159
|
"client": "fetch",
|
|
162
160
|
"excludeCoreServiceFiles": true,
|
|
163
|
-
"includeSchemasFiles": true,
|
|
164
161
|
"items": [
|
|
165
162
|
{
|
|
166
163
|
"input": "./first.yml"
|
|
@@ -201,7 +198,6 @@ Instead of passing all options via CLI, you can use a configuration file. Create
|
|
|
201
198
|
| `useOptions` | boolean | `false` | Use options instead of arguments |
|
|
202
199
|
| `useUnionTypes` | boolean | `false` | Use union types instead of enums |
|
|
203
200
|
| `excludeCoreServiceFiles` | boolean | `false` | Exclude core and service files generation |
|
|
204
|
-
| `includeSchemasFiles` | boolean | `false` | Enable model validation schemas generation |
|
|
205
201
|
| `request` | string | - | Path to custom request file |
|
|
206
202
|
| `interfacePrefix` | string | `I` | Prefix for interface models |
|
|
207
203
|
| `enumPrefix` | string | `E` | Prefix for enum models |
|
|
@@ -210,6 +206,7 @@ Instead of passing all options via CLI, you can use a configuration file. Create
|
|
|
210
206
|
| `sortByRequired` | boolean | `false` | Extended sorting strategy for arguments |
|
|
211
207
|
| `useSeparatedIndexes` | boolean | `false` | Use separate index files |
|
|
212
208
|
| `items` | array | - | Array of configurations (for multi-options format) |
|
|
209
|
+
| `validationLibrary` | string | `none` | Validation library for schema generation: `none`, `zod`, `joi`, `yup`, or `jsonschema` |
|
|
213
210
|
|
|
214
211
|
**Note:** You can use the `init-openapi-config` command to generate a template configuration file.
|
|
215
212
|
|
|
@@ -369,11 +366,19 @@ const order: Order = {
|
|
|
369
366
|
}
|
|
370
367
|
```
|
|
371
368
|
|
|
372
|
-
###
|
|
369
|
+
### Validation schemas `--validationLibrary`
|
|
373
370
|
By default, the OpenAPI generator only exports interfaces for your models. These interfaces will help you during
|
|
374
|
-
development, but will not be available in JavaScript during runtime. However,
|
|
375
|
-
that can be useful during runtime, for instance: `maxLength` of a string or a `pattern` to match, etc.
|
|
376
|
-
|
|
371
|
+
development, but will not be available in JavaScript during runtime. However, OpenAPI allows you to define properties
|
|
372
|
+
that can be useful during runtime, for instance: `maxLength` of a string or a `pattern` to match, etc.
|
|
373
|
+
|
|
374
|
+
The `--validationLibrary` parameter allows you to generate runtime validation schemas using popular validation libraries:
|
|
375
|
+
- **none** (default) - No validation schemas generated
|
|
376
|
+
- **zod** - Generate Zod validation schemas
|
|
377
|
+
- **joi** - Generate Joi validation schemas
|
|
378
|
+
- **yup** - Generate Yup validation schemas
|
|
379
|
+
- **jsonschema** - Generate JSON Schema validation schemas
|
|
380
|
+
|
|
381
|
+
Let's say we have the following model:
|
|
377
382
|
|
|
378
383
|
```json
|
|
379
384
|
{
|
|
@@ -407,77 +412,88 @@ we have the following model:
|
|
|
407
412
|
}
|
|
408
413
|
```
|
|
409
414
|
|
|
410
|
-
|
|
415
|
+
**With Zod (`--validationLibrary zod`):**
|
|
411
416
|
|
|
412
|
-
```
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
417
|
+
```ts
|
|
418
|
+
import { z } from 'zod';
|
|
419
|
+
|
|
420
|
+
export const MyModelSchema = z.object({
|
|
421
|
+
key: z.string().max(64).regex(/^[a-zA-Z0-9_]*$/),
|
|
422
|
+
name: z.string().max(255),
|
|
423
|
+
enabled: z.boolean().readonly().optional(),
|
|
424
|
+
modified: z.string().datetime().readonly().optional(),
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
export type MyModel = z.infer<typeof MyModelSchema>;
|
|
428
|
+
|
|
429
|
+
export function validateMyModel(data: unknown): MyModel {
|
|
430
|
+
return MyModelSchema.parse(data);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export function safeValidateMyModel(data: unknown): { success: true; data: MyModel } | { success: false; error: z.ZodError } {
|
|
434
|
+
const result = MyModelSchema.safeParse(data);
|
|
435
|
+
if (result.success) {
|
|
436
|
+
return { success: true, data: result.data };
|
|
437
|
+
}
|
|
438
|
+
return { success: false, error: result.error };
|
|
418
439
|
}
|
|
419
440
|
```
|
|
420
441
|
|
|
421
|
-
|
|
422
|
-
if we wanted to create some form where a user could create such a model. In that form you would iterate
|
|
423
|
-
over the properties to render form fields based on their type and validate the input based on the `maxLength`
|
|
424
|
-
or `pattern` property. This requires us to have this information somewhere... For this we can use the
|
|
425
|
-
flag `--includeSchemasFiles` to generate a runtime model next to the normal interface:
|
|
442
|
+
**With Joi (`--validationLibrary joi`):**
|
|
426
443
|
|
|
427
|
-
```
|
|
428
|
-
|
|
444
|
+
```ts
|
|
445
|
+
import Joi from 'joi';
|
|
446
|
+
|
|
447
|
+
export const MyModelSchema = Joi.object({
|
|
448
|
+
key: Joi.string().max(64).pattern(/^[a-zA-Z0-9_]*$/).required(),
|
|
449
|
+
name: Joi.string().max(255).required(),
|
|
450
|
+
enabled: Joi.boolean().readonly(),
|
|
451
|
+
modified: Joi.string().isoDate().readonly(),
|
|
452
|
+
});
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
**With Yup (`--validationLibrary yup`):**
|
|
456
|
+
|
|
457
|
+
```ts
|
|
458
|
+
import * as yup from 'yup';
|
|
459
|
+
|
|
460
|
+
export const MyModelSchema = yup.object({
|
|
461
|
+
key: yup.string().max(64).matches(/^[a-zA-Z0-9_]*$/).required(),
|
|
462
|
+
name: yup.string().max(255).required(),
|
|
463
|
+
enabled: yup.boolean().readonly(),
|
|
464
|
+
modified: yup.string().datetime().readonly(),
|
|
465
|
+
});
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
**With JSON Schema (`--validationLibrary jsonschema`):**
|
|
469
|
+
|
|
470
|
+
```ts
|
|
471
|
+
export const MyModelSchema = {
|
|
472
|
+
type: 'object',
|
|
473
|
+
required: ['key', 'name'],
|
|
429
474
|
properties: {
|
|
430
475
|
key: {
|
|
431
476
|
type: 'string',
|
|
432
|
-
isRequired: true,
|
|
433
477
|
maxLength: 64,
|
|
434
478
|
pattern: '^[a-zA-Z0-9_]*$',
|
|
435
479
|
},
|
|
436
480
|
name: {
|
|
437
481
|
type: 'string',
|
|
438
|
-
isRequired: true,
|
|
439
482
|
maxLength: 255,
|
|
440
483
|
},
|
|
441
484
|
enabled: {
|
|
442
485
|
type: 'boolean',
|
|
443
|
-
|
|
486
|
+
readOnly: true,
|
|
444
487
|
},
|
|
445
488
|
modified: {
|
|
446
489
|
type: 'string',
|
|
447
|
-
isReadOnly: true,
|
|
448
490
|
format: 'date-time',
|
|
491
|
+
readOnly: true,
|
|
449
492
|
},
|
|
450
493
|
},
|
|
451
494
|
};
|
|
452
495
|
```
|
|
453
|
-
|
|
454
|
-
These runtime object are prefixed with a `$` character and expose all the interesting attributes of a model
|
|
455
|
-
and its properties. We can now use this object to generate the form:
|
|
456
|
-
|
|
457
|
-
```typescript jsx
|
|
458
|
-
import { $MyModel } from './generated';
|
|
459
|
-
|
|
460
|
-
// Some pseudo code to iterate over the properties and return a form field
|
|
461
|
-
// the form field could be some abstract component that renders the correct
|
|
462
|
-
// field type and validation rules based on the given input.
|
|
463
|
-
const formFields = Object.entries($MyModel.properties).map(([key, value]) => (
|
|
464
|
-
<FormField
|
|
465
|
-
name={key}
|
|
466
|
-
type={value.type}
|
|
467
|
-
format={value.format}
|
|
468
|
-
maxLength={value.maxLength}
|
|
469
|
-
pattern={value.pattern}
|
|
470
|
-
isReadOnly={value.isReadOnly}
|
|
471
|
-
/>
|
|
472
|
-
));
|
|
473
|
-
|
|
474
|
-
const MyForm = () => (
|
|
475
|
-
<form>
|
|
476
|
-
{formFields}
|
|
477
|
-
</form>
|
|
478
|
-
);
|
|
479
|
-
|
|
480
|
-
```
|
|
496
|
+
These validation schemas can be used for form generation, input validation, and runtime type checking in your application.
|
|
481
497
|
|
|
482
498
|
### Cancelable promise `--useCancelableRequest`
|
|
483
499
|
By default, the OpenAPI generator generates services for accessing the API that use non-cancellable requests. Therefore, we have added the ability to switch the generator to generate canceled API requests. To do this, use the flag `--useCancelableRequest`.
|
package/README.rus.md
CHANGED
|
@@ -63,7 +63,6 @@ openapi generate --input ./spec.json --output ./dist
|
|
|
63
63
|
| `--useOptions` | - | boolean | `false` | Использовать опции вместо аргументов |
|
|
64
64
|
| `--useUnionTypes` | - | boolean | `false` | Использовать union типы вместо enums |
|
|
65
65
|
| `--excludeCoreServiceFiles` | - | boolean | `false` | Исключить генерацию core и сервисных файлов |
|
|
66
|
-
| `--includeSchemasFiles` | - | boolean | `false` | Включить генерацию схем валидации моделей |
|
|
67
66
|
| `--request` | - | string | - | Путь к пользовательскому файлу запросов |
|
|
68
67
|
| `--interfacePrefix` | - | string | `I` | Префикс для интерфейсов моделей |
|
|
69
68
|
| `--enumPrefix` | - | string | `E` | Префикс для enum моделей |
|
|
@@ -73,6 +72,7 @@ openapi generate --input ./spec.json --output ./dist
|
|
|
73
72
|
| `--useSeparatedIndexes` | - | boolean | `false` | Использовать отдельные index файлы для core, models, schemas и services |
|
|
74
73
|
| `--logLevel` | `-l` | string | `error` | Уровень логирования: `info`, `warn`, или `error` |
|
|
75
74
|
| `--logTarget` | `-t` | string | `console` | Цель логирования: `console` или `file` |
|
|
75
|
+
| `--validationLibrary` | - | string | `none` | Библиотека валидации для генерации схем: `none`, `zod`, `joi`, `yup`, или `jsonschema` |
|
|
76
76
|
|
|
77
77
|
**Примеры:**
|
|
78
78
|
```bash
|
|
@@ -92,7 +92,6 @@ openapi generate \
|
|
|
92
92
|
--httpClient fetch \
|
|
93
93
|
--useOptions \
|
|
94
94
|
--useUnionTypes \
|
|
95
|
-
--includeSchemasFiles \
|
|
96
95
|
--logLevel info
|
|
97
96
|
```
|
|
98
97
|
|
|
@@ -142,7 +141,6 @@ openapi init-openapi-config --openapi-config ./my-config.json
|
|
|
142
141
|
"useOptions": false,
|
|
143
142
|
"useUnionTypes": false,
|
|
144
143
|
"excludeCoreServiceFiles": false,
|
|
145
|
-
"includeSchemasFiles": false,
|
|
146
144
|
"interfacePrefix": "I",
|
|
147
145
|
"enumPrefix": "E",
|
|
148
146
|
"typePrefix": "T",
|
|
@@ -159,7 +157,6 @@ openapi init-openapi-config --openapi-config ./my-config.json
|
|
|
159
157
|
"output": "./dist",
|
|
160
158
|
"client": "fetch",
|
|
161
159
|
"excludeCoreServiceFiles": true,
|
|
162
|
-
"includeSchemasFiles": true,
|
|
163
160
|
"items": [
|
|
164
161
|
{
|
|
165
162
|
"input": "./first.yml"
|
|
@@ -200,7 +197,6 @@ openapi init-openapi-config --openapi-config ./my-config.json
|
|
|
200
197
|
| `useOptions` | boolean | `false` | Использовать опции вместо аргументов |
|
|
201
198
|
| `useUnionTypes` | boolean | `false` | Использовать union типы вместо enums |
|
|
202
199
|
| `excludeCoreServiceFiles` | boolean | `false` | Исключить генерацию core и сервисных файлов |
|
|
203
|
-
| `includeSchemasFiles` | boolean | `false` | Включить генерацию схем валидации моделей |
|
|
204
200
|
| `request` | string | - | Путь к пользовательскому файлу запросов |
|
|
205
201
|
| `interfacePrefix` | string | `I` | Префикс для интерфейсов моделей |
|
|
206
202
|
| `enumPrefix` | string | `E` | Префикс для enum моделей |
|
|
@@ -209,6 +205,7 @@ openapi init-openapi-config --openapi-config ./my-config.json
|
|
|
209
205
|
| `sortByRequired` | boolean | `false` | Расширенная стратегия сортировки для аргументов |
|
|
210
206
|
| `useSeparatedIndexes` | boolean | `false` | Использовать отдельные index файлы |
|
|
211
207
|
| `items` | array | - | Массив конфигураций (для формата multi-options) |
|
|
208
|
+
| `validationLibrary` | string | `none` | Библиотека валидации для генерации схем: `none`, `zod`, `joi`, `yup`, или `jsonschema` |
|
|
212
209
|
|
|
213
210
|
**Примечание:** Вы можете использовать команду `init-openapi-config` для генерации шаблона файла конфигурации.
|
|
214
211
|
|
|
@@ -368,11 +365,19 @@ const order: Order = {
|
|
|
368
365
|
}
|
|
369
366
|
```
|
|
370
367
|
|
|
371
|
-
###
|
|
368
|
+
### Схемы проверки `--validationLibrary`
|
|
372
369
|
По умолчанию генератор OpenAPI экспортирует только интерфейсы для ваших моделей. Эти интерфейсы помогут вам во время
|
|
373
|
-
разработки, но не будут доступны в JavaScript во время выполнения. Однако
|
|
374
|
-
которые могут быть полезны во время выполнения, например: `maxLength` строки или `pattern` для сопоставления и т.д.
|
|
375
|
-
|
|
370
|
+
разработки, но не будут доступны в JavaScript во время выполнения. Однако OpenAPI позволяет определять свойства,
|
|
371
|
+
которые могут быть полезны во время выполнения, например: `maxLength` строки или `pattern` для сопоставления и т.д.
|
|
372
|
+
|
|
373
|
+
Параметр `--validationLibrary` позволяет генерировать схемы валидации времени выполнения с использованием популярных библиотек валидации:
|
|
374
|
+
- **none** (по умолчанию) - Схемы валидации не генерируются
|
|
375
|
+
- **zod** - Генерация схем валидации Zod
|
|
376
|
+
- **joi** - Генерация схем валидации Joi
|
|
377
|
+
- **yup** - Генерация схем валидации Yup
|
|
378
|
+
- **jsonschema** - Генерация схем валидации JSON Schema
|
|
379
|
+
|
|
380
|
+
Допустим, у нас есть следующая модель:
|
|
376
381
|
|
|
377
382
|
```json
|
|
378
383
|
{
|
|
@@ -406,77 +411,89 @@ const order: Order = {
|
|
|
406
411
|
}
|
|
407
412
|
```
|
|
408
413
|
|
|
409
|
-
|
|
414
|
+
**С Zod (`--validationLibrary zod`):**
|
|
410
415
|
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
416
|
+
```ts
|
|
417
|
+
import { z } from 'zod';
|
|
418
|
+
|
|
419
|
+
export const MyModelSchema = z.object({
|
|
420
|
+
key: z.string().max(64).regex(/^[a-zA-Z0-9_]*$/),
|
|
421
|
+
name: z.string().max(255),
|
|
422
|
+
enabled: z.boolean().readonly().optional(),
|
|
423
|
+
modified: z.string().datetime().readonly().optional(),
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
export type MyModel = z.infer<typeof MyModelSchema>;
|
|
427
|
+
|
|
428
|
+
export function validateMyModel(data: unknown): MyModel {
|
|
429
|
+
return MyModelSchema.parse(data);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export function safeValidateMyModel(data: unknown): { success: true; data: MyModel } | { success: false; error: z.ZodError } {
|
|
433
|
+
const result = MyModelSchema.safeParse(data);
|
|
434
|
+
if (result.success) {
|
|
435
|
+
return { success: true, data: result.data };
|
|
436
|
+
}
|
|
437
|
+
return { success: false, error: result.error };
|
|
417
438
|
}
|
|
418
439
|
```
|
|
419
440
|
|
|
420
|
-
|
|
421
|
-
если мы хотим создать форму, где пользователь может создать такую модель. В этой форме вы будете итерироваться
|
|
422
|
-
по свойствам для рендеринга полей формы на основе их типа и валидации ввода на основе свойства `maxLength`
|
|
423
|
-
или `pattern`. Для этого нам нужно где-то хранить эту информацию... Для этого мы можем использовать
|
|
424
|
-
флаг `--includeSchemasFiles` для генерации runtime модели рядом с обычным интерфейсом:
|
|
441
|
+
**С Joi (`--validationLibrary joi`):**
|
|
425
442
|
|
|
426
|
-
```
|
|
427
|
-
|
|
443
|
+
```ts
|
|
444
|
+
import Joi from 'joi';
|
|
445
|
+
|
|
446
|
+
export const MyModelSchema = Joi.object({
|
|
447
|
+
key: Joi.string().max(64).pattern(/^[a-zA-Z0-9_]*$/).required(),
|
|
448
|
+
name: Joi.string().max(255).required(),
|
|
449
|
+
enabled: Joi.boolean().readonly(),
|
|
450
|
+
modified: Joi.string().isoDate().readonly(),
|
|
451
|
+
});
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
**С Yup (`--validationLibrary yup`):**
|
|
455
|
+
|
|
456
|
+
```ts
|
|
457
|
+
import * as yup from 'yup';
|
|
458
|
+
|
|
459
|
+
export const MyModelSchema = yup.object({
|
|
460
|
+
key: yup.string().max(64).matches(/^[a-zA-Z0-9_]*$/).required(),
|
|
461
|
+
name: yup.string().max(255).required(),
|
|
462
|
+
enabled: yup.boolean().readonly(),
|
|
463
|
+
modified: yup.string().datetime().readonly(),
|
|
464
|
+
});
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
**С JSON Schema (`--validationLibrary jsonschema`):**
|
|
468
|
+
|
|
469
|
+
```ts
|
|
470
|
+
export const MyModelSchema = {
|
|
471
|
+
type: 'object',
|
|
472
|
+
required: ['key', 'name'],
|
|
428
473
|
properties: {
|
|
429
474
|
key: {
|
|
430
475
|
type: 'string',
|
|
431
|
-
isRequired: true,
|
|
432
476
|
maxLength: 64,
|
|
433
477
|
pattern: '^[a-zA-Z0-9_]*$',
|
|
434
478
|
},
|
|
435
479
|
name: {
|
|
436
480
|
type: 'string',
|
|
437
|
-
isRequired: true,
|
|
438
481
|
maxLength: 255,
|
|
439
482
|
},
|
|
440
483
|
enabled: {
|
|
441
484
|
type: 'boolean',
|
|
442
|
-
|
|
485
|
+
readOnly: true,
|
|
443
486
|
},
|
|
444
487
|
modified: {
|
|
445
488
|
type: 'string',
|
|
446
|
-
isReadOnly: true,
|
|
447
489
|
format: 'date-time',
|
|
490
|
+
readOnly: true,
|
|
448
491
|
},
|
|
449
492
|
},
|
|
450
493
|
};
|
|
451
494
|
```
|
|
452
495
|
|
|
453
|
-
Эти
|
|
454
|
-
и её свойств. Теперь мы можем использовать этот объект для генерации формы:
|
|
455
|
-
|
|
456
|
-
```typescript jsx
|
|
457
|
-
import { $MyModel } from './generated';
|
|
458
|
-
|
|
459
|
-
// Псевдокод для итерации по свойствам и возврата поля формы
|
|
460
|
-
// поле формы может быть абстрактным компонентом, который рендерит правильный
|
|
461
|
-
// тип поля и правила валидации на основе заданного ввода.
|
|
462
|
-
const formFields = Object.entries($MyModel.properties).map(([key, value]) => (
|
|
463
|
-
<FormField
|
|
464
|
-
name={key}
|
|
465
|
-
type={value.type}
|
|
466
|
-
format={value.format}
|
|
467
|
-
maxLength={value.maxLength}
|
|
468
|
-
pattern={value.pattern}
|
|
469
|
-
isReadOnly={value.isReadOnly}
|
|
470
|
-
/>
|
|
471
|
-
));
|
|
472
|
-
|
|
473
|
-
const MyForm = () => (
|
|
474
|
-
<form>
|
|
475
|
-
{formFields}
|
|
476
|
-
</form>
|
|
477
|
-
);
|
|
478
|
-
|
|
479
|
-
```
|
|
496
|
+
Эти схемы валидации могут быть использованы для генерации форм, валидации ввода и проверки типов во время выполнения в вашем приложении.
|
|
480
497
|
|
|
481
498
|
### Отменяемый promise `--useCancelableRequest`
|
|
482
499
|
По умолчанию генератор OpenAPI генерирует сервисы для доступа к API, которые используют неотменяемые запросы. Поэтому мы добавили возможность переключить генератор на генерацию отменяемых API запросов. Для этого используйте флаг `--useCancelableRequest`.
|
package/dist/cli/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const Enums_1 = require("../common/Enums");
|
|
|
11
11
|
const UpdateNotifier_1 = require("../common/UpdateNotifier");
|
|
12
12
|
const pathHelpers_1 = require("../common/utils/pathHelpers");
|
|
13
13
|
const HttpClient_enum_1 = require("../core/types/enums/HttpClient.enum");
|
|
14
|
+
const ValidationLibrary_enum_1 = require("../core/types/enums/ValidationLibrary.enum");
|
|
14
15
|
const checkConfig_1 = require("./checkAndUpdateConfig/checkConfig");
|
|
15
16
|
const updateConfig_1 = require("./checkAndUpdateConfig/updateConfig");
|
|
16
17
|
const runGenerateOpenApi_1 = require("./generate/runGenerateOpenApi");
|
|
@@ -46,7 +47,6 @@ program
|
|
|
46
47
|
.option('--useOptions', 'Use options instead of arguments (default: false)')
|
|
47
48
|
.option('--useUnionTypes', 'Use union types instead of enums (default: false)')
|
|
48
49
|
.option('--excludeCoreServiceFiles', 'The generation of the core and services is excluded (default: false)')
|
|
49
|
-
.option('--includeSchemasFiles', 'The generation of model validation schemes is enabled (default: false)')
|
|
50
50
|
.option('--request <value>', 'Path to custom request file')
|
|
51
51
|
.option('--interfacePrefix <value>', 'Prefix for interface model(default: "I")', 'I')
|
|
52
52
|
.option('--enumPrefix <value>', 'Prefix for enum model(default: "E")', 'E')
|
|
@@ -56,6 +56,7 @@ program
|
|
|
56
56
|
.addOption(new commander_1.Option('-t, --logTarget <target>', 'Target of logging').choices([...Object.values(Enums_1.ELogOutput)]).default(Enums_1.ELogOutput.CONSOLE))
|
|
57
57
|
.option('-s, --sortByRequired', 'Property sorting strategy: simplified or extended')
|
|
58
58
|
.option('--useSeparatedIndexes', 'Use separate index files for the core, models, schemas, and services.')
|
|
59
|
+
.addOption(new commander_1.Option('--validationLibrary <value>', 'Validation library to use for schema validation').choices([...Object.values(ValidationLibrary_enum_1.ValidationLibrary)]).default(ValidationLibrary_enum_1.ValidationLibrary.NONE))
|
|
59
60
|
.hook('preAction', async () => {
|
|
60
61
|
await updateNotifier.checkAndNotify();
|
|
61
62
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Consts.d.ts","sourceRoot":"","sources":["../../src/common/Consts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Consts.d.ts","sourceRoot":"","sources":["../../src/common/Consts.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,eAAO,MAAM,+BAA+B,wBAAwB,CAAC;AAErE,eAAO,MAAM,6BAA6B,EAAE,kBAqB3C,CAAC;AAEF,eAAO,MAAM,UAAU,QAIrB,CAAC"}
|
package/dist/common/Consts.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.APP_LOGGER = exports.COMMON_DEFAULT_OPTIONS_VALUES = exports.DEFAULT_OPENAPI_CONFIG_FILENAME = void 0;
|
|
4
4
|
const HttpClient_enum_1 = require("../core/types/enums/HttpClient.enum");
|
|
5
|
+
const ValidationLibrary_enum_1 = require("../core/types/enums/ValidationLibrary.enum");
|
|
5
6
|
const Enums_1 = require("./Enums");
|
|
6
7
|
const Logger_1 = require("./Logger");
|
|
7
8
|
exports.DEFAULT_OPENAPI_CONFIG_FILENAME = 'openapi.config.json';
|
|
@@ -16,7 +17,6 @@ exports.COMMON_DEFAULT_OPTIONS_VALUES = {
|
|
|
16
17
|
useOptions: false,
|
|
17
18
|
useUnionTypes: false,
|
|
18
19
|
excludeCoreServiceFiles: false,
|
|
19
|
-
includeSchemasFiles: false,
|
|
20
20
|
request: '',
|
|
21
21
|
interfacePrefix: 'I',
|
|
22
22
|
enumPrefix: 'E',
|
|
@@ -26,6 +26,7 @@ exports.COMMON_DEFAULT_OPTIONS_VALUES = {
|
|
|
26
26
|
logTarget: Enums_1.ELogOutput.CONSOLE,
|
|
27
27
|
sortByRequired: false,
|
|
28
28
|
useSeparatedIndexes: false,
|
|
29
|
+
validationLibrary: ValidationLibrary_enum_1.ValidationLibrary.NONE
|
|
29
30
|
};
|
|
30
31
|
exports.APP_LOGGER = new Logger_1.Logger({
|
|
31
32
|
level: Enums_1.ELogLevel.INFO,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HttpClient } from '../core/types/enums/HttpClient.enum';
|
|
2
|
+
import { ValidationLibrary } from '../core/types/enums/ValidationLibrary.enum';
|
|
2
3
|
import { ELogLevel, ELogOutput } from './Enums';
|
|
3
4
|
type TItemConfig = {
|
|
4
5
|
input: string;
|
|
@@ -21,7 +22,6 @@ export type TRawOptions = {
|
|
|
21
22
|
useOptions?: boolean;
|
|
22
23
|
useUnionTypes?: boolean;
|
|
23
24
|
excludeCoreServiceFiles?: boolean;
|
|
24
|
-
includeSchemasFiles?: boolean;
|
|
25
25
|
request?: string;
|
|
26
26
|
interfacePrefix?: string;
|
|
27
27
|
enumPrefix?: string;
|
|
@@ -31,6 +31,7 @@ export type TRawOptions = {
|
|
|
31
31
|
logTarget?: ELogOutput;
|
|
32
32
|
sortByRequired?: boolean;
|
|
33
33
|
useSeparatedIndexes?: boolean;
|
|
34
|
+
validationLibrary?: ValidationLibrary;
|
|
34
35
|
};
|
|
35
36
|
export type TFlatOptions = Omit<TRawOptions, 'items'>;
|
|
36
37
|
export type TStrictFlatOptions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TRawOptions.d.ts","sourceRoot":"","sources":["../../src/common/TRawOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEhD,KAAK,WAAW,GAAG;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACtB,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,
|
|
1
|
+
{"version":3,"file":"TRawOptions.d.ts","sourceRoot":"","sources":["../../src/common/TRawOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEhD,KAAK,WAAW,GAAG;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACtB,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;CACxC,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAEtD,MAAM,MAAM,kBAAkB,GAAG;KAC5B,CAAC,IAAI,MAAM,YAAY,CAAC,CAAC,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CAC5D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AllMigrationPlans.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AllMigrationPlans.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAc/C;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAmB5F,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.allMigrationPlans = void 0;
|
|
4
|
+
const ValidationLibrary_enum_1 = require("../../../core/types/enums/ValidationLibrary.enum");
|
|
4
5
|
const MultiOptionsMigrationPlan_1 = require("../MultiOptionsVersioned/MultiOptionsMigrationPlan");
|
|
5
6
|
const OptionsMigrationPlans_1 = require("../OptionsVersioned/OptionsMigrationPlans");
|
|
6
7
|
const createTrivialMigration_1 = require("../Utils/createTrivialMigration");
|
|
@@ -28,4 +29,11 @@ exports.allMigrationPlans = [
|
|
|
28
29
|
...addVersionPrefixToMigrationPlans(MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan, 'MULTI_OPTIONS'),
|
|
29
30
|
// Migration from MULTI_OPTIONS v5 to UNIFIED v1
|
|
30
31
|
(0, createTrivialMigration_1.createTrivialMigration)('MULTI_OPTIONS_v5', 'UNIFIED_v1', 'Migrate from MULTI_OPTIONS to UNIFIED schema'),
|
|
32
|
+
{
|
|
33
|
+
fromVersion: 'UNIFIED_v1',
|
|
34
|
+
toVersion: 'UNIFIED_v2',
|
|
35
|
+
migrate: ({ includeSchemasFiles, ...otherProps }) => {
|
|
36
|
+
return { ...otherProps, validationLibrary: !includeSchemasFiles ? ValidationLibrary_enum_1.ValidationLibrary.NONE : undefined };
|
|
37
|
+
},
|
|
38
|
+
},
|
|
31
39
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AllVersionedSchemas.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/AllVersionedSchemas/AllVersionedSchemas.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"AllVersionedSchemas.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/AllVersionedSchemas/AllVersionedSchemas.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAiB3C;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAkBrE,CAAC"}
|
|
@@ -4,7 +4,8 @@ exports.allVersionedSchemas = void 0;
|
|
|
4
4
|
const Enums_1 = require("../Enums");
|
|
5
5
|
const MultiOptionsVersionedSchemas_1 = require("../MultiOptionsVersioned/MultiOptionsVersionedSchemas");
|
|
6
6
|
const OptionsVersionedSchemas_1 = require("../OptionsVersioned/OptionsVersionedSchemas");
|
|
7
|
-
const UnifiedOptionsSchemaV1_1 = require("
|
|
7
|
+
const UnifiedOptionsSchemaV1_1 = require("./UnifiedOptionsSchemaV1");
|
|
8
|
+
const UnifiedOptionsSchemaV2_1 = require("./UnifiedOptionsSchemaV2");
|
|
8
9
|
/**
|
|
9
10
|
* Adds a prefix to all version strings in a versioned schema array.
|
|
10
11
|
*/
|
|
@@ -30,4 +31,9 @@ exports.allVersionedSchemas = [
|
|
|
30
31
|
schema: UnifiedOptionsSchemaV1_1.unifiedOptionsSchemaV1,
|
|
31
32
|
type: Enums_1.EVersionedSchemaType.UNIFIED_OPTIONS,
|
|
32
33
|
},
|
|
34
|
+
{
|
|
35
|
+
version: 'UNIFIED_v2',
|
|
36
|
+
schema: UnifiedOptionsSchemaV2_1.unifiedOptionsSchemaV2,
|
|
37
|
+
type: Enums_1.EVersionedSchemaType.UNIFIED_OPTIONS,
|
|
38
|
+
}
|
|
33
39
|
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnifiedOptionsSchemaV1.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV1.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAqBtB;;;GAGG;AACH,eAAO,MAAM,sBAAsB,uBA6BZ,CAAC"}
|
|
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.unifiedOptionsSchemaV1 = void 0;
|
|
7
7
|
const joi_1 = __importDefault(require("joi"));
|
|
8
|
-
const
|
|
8
|
+
const HttpClient_enum_1 = require("../../../core/types/enums/HttpClient.enum");
|
|
9
9
|
const CommonSchemas_1 = require("../CommonSchemas");
|
|
10
10
|
const mergeObjectSchemas_1 = require("../Utils/mergeObjectSchemas");
|
|
11
11
|
const itemSchema = (0, mergeObjectSchemas_1.mergeObjectSchemas)(joi_1.default.object({
|
|
12
12
|
input: joi_1.default.string().required().description('Путь, URL или строка OpenAPI спецификации'),
|
|
13
|
-
httpClient: joi_1.default.string().valid(...Object.values(
|
|
13
|
+
httpClient: joi_1.default.string().valid(...Object.values(HttpClient_enum_1.HttpClient)).optional(),
|
|
14
14
|
}), CommonSchemas_1.outputPathsSchema, CommonSchemas_1.additionalParametersSchemaV2, CommonSchemas_1.experimentalParametersSchemaV2);
|
|
15
15
|
/**
|
|
16
16
|
* Unified options schema that supports both single and multi-item configurations.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Joi from 'joi';
|
|
2
|
+
/**
|
|
3
|
+
* Unified options schema that supports both single and multi-item configurations.
|
|
4
|
+
* Use either 'items' array for multiple specs OR 'input'/'output' for single spec.
|
|
5
|
+
*/
|
|
6
|
+
export declare const unifiedOptionsSchemaV2: Joi.ObjectSchema<any>;
|
|
7
|
+
//# sourceMappingURL=UnifiedOptionsSchemaV2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnifiedOptionsSchemaV2.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV2.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAqBtB;;;GAGG;AACH,eAAO,MAAM,sBAAsB,uBA6BZ,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.unifiedOptionsSchemaV2 = void 0;
|
|
7
|
+
const joi_1 = __importDefault(require("joi"));
|
|
8
|
+
const HttpClient_enum_1 = require("../../../core/types/enums/HttpClient.enum");
|
|
9
|
+
const CommonSchemas_1 = require("../CommonSchemas");
|
|
10
|
+
const mergeObjectSchemas_1 = require("../Utils/mergeObjectSchemas");
|
|
11
|
+
const itemSchema = (0, mergeObjectSchemas_1.mergeObjectSchemas)(joi_1.default.object({
|
|
12
|
+
input: joi_1.default.string().required().description('Путь, URL или строка OpenAPI спецификации'),
|
|
13
|
+
httpClient: joi_1.default.string().valid(...Object.values(HttpClient_enum_1.HttpClient)).optional(),
|
|
14
|
+
}), CommonSchemas_1.outputPathsSchema, CommonSchemas_1.additionalParametersSchemaV2, CommonSchemas_1.experimentalParametersSchemaV2);
|
|
15
|
+
/**
|
|
16
|
+
* Unified options schema that supports both single and multi-item configurations.
|
|
17
|
+
* Use either 'items' array for multiple specs OR 'input'/'output' for single spec.
|
|
18
|
+
*/
|
|
19
|
+
exports.unifiedOptionsSchemaV2 = (0, mergeObjectSchemas_1.mergeObjectSchemas)(joi_1.default.object({
|
|
20
|
+
// Multi-item configuration
|
|
21
|
+
items: joi_1.default.array()
|
|
22
|
+
.items(itemSchema)
|
|
23
|
+
.min(1)
|
|
24
|
+
.optional()
|
|
25
|
+
.description('Массив спецификаций для генерации'),
|
|
26
|
+
// Single-item configuration (mutually exclusive with items)
|
|
27
|
+
input: joi_1.default.string()
|
|
28
|
+
.when('items', {
|
|
29
|
+
is: joi_1.default.exist(),
|
|
30
|
+
then: joi_1.default.forbidden(),
|
|
31
|
+
otherwise: joi_1.default.required(),
|
|
32
|
+
})
|
|
33
|
+
.description('Путь, URL или строка OpenAPI спецификации'),
|
|
34
|
+
output: joi_1.default.string()
|
|
35
|
+
.when('items', {
|
|
36
|
+
is: joi_1.default.exist(),
|
|
37
|
+
then: joi_1.default.forbidden(),
|
|
38
|
+
otherwise: joi_1.default.required(),
|
|
39
|
+
})
|
|
40
|
+
.description('Выходная директория'),
|
|
41
|
+
}), CommonSchemas_1.outputPathsSchema, // outputCore, outputServices, etc. for single-item mode
|
|
42
|
+
CommonSchemas_1.specialParametersSchemasV3, CommonSchemas_1.additionalParametersSchemaV2, CommonSchemas_1.experimentalParametersSchemaV2).xor('items', 'input');
|
|
@@ -11,6 +11,7 @@ export declare const specialParametersSchemas: Joi.ObjectSchema<any>;
|
|
|
11
11
|
* The scheme of the "accessibility" parameter set.
|
|
12
12
|
*/
|
|
13
13
|
export declare const specialParametersSchemasV2: Joi.ObjectSchema<any>;
|
|
14
|
+
export declare const specialParametersSchemasV3: Joi.ObjectSchema<any>;
|
|
14
15
|
/**
|
|
15
16
|
* The scheme of additional parameters.
|
|
16
17
|
*/
|