@tsed/schema 8.33.0 → 8.35.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/lib/esm/compat.js +8 -0
- package/lib/esm/components/index.js +37 -27
- package/lib/esm/components/{default → mappers/default}/anyMapper.js +5 -5
- package/lib/esm/components/{default → mappers/default}/classMapper.js +5 -5
- package/lib/esm/components/{default → mappers/default}/discriminatorMappingMapper.js +3 -3
- package/lib/esm/components/{default → mappers/default}/enumsMapper.js +2 -2
- package/lib/esm/components/{default → mappers/default}/genericsMapper.js +7 -6
- package/lib/esm/components/{default → mappers/default}/inheritedClassMapper.js +3 -3
- package/lib/esm/components/{default → mappers/default}/lazyRefMapper.js +3 -3
- package/lib/esm/components/{default → mappers/default}/mapMapper.js +2 -2
- package/lib/esm/components/{default → mappers/default}/nextMapper.js +16 -16
- package/lib/esm/components/{default → mappers/default}/nullableMapper.js +3 -3
- package/lib/esm/components/{default → mappers/default}/objectMapper.js +4 -4
- package/lib/esm/components/mappers/default/ofMapper.js +9 -0
- package/lib/esm/components/{default → mappers/default}/requiredMapper.js +3 -3
- package/lib/esm/components/{default → mappers/default}/schemaMapper.js +11 -6
- package/lib/esm/components/mappers/open-spec/discriminatorMappingMapper.js +8 -0
- package/lib/esm/components/mappers/open-spec/enumsMapper.js +12 -0
- package/lib/esm/components/{open-spec → mappers/open-spec}/generate.js +3 -4
- package/lib/esm/components/{open-spec → mappers/open-spec}/nullableMapper.js +3 -4
- package/lib/esm/components/{open-spec → mappers/open-spec}/operationInFilesMapper.js +2 -2
- package/lib/esm/components/{open-spec → mappers/open-spec}/operationInParameterMapper.js +3 -3
- package/lib/esm/components/mappers/open-spec/operationInParametersMapper.js +5 -0
- package/lib/esm/components/{open-spec → mappers/open-spec}/operationInQueryMapper.js +3 -3
- package/lib/esm/components/{open-spec → mappers/open-spec}/operationMapper.js +4 -4
- package/lib/esm/components/{open-spec → mappers/open-spec}/operationMediaMapper.js +2 -2
- package/lib/esm/components/{open-spec → mappers/open-spec}/operationRequestBodyMapper.js +4 -4
- package/lib/esm/components/{open-spec → mappers/open-spec}/operationResponseMapper.js +2 -2
- package/lib/esm/components/{open-spec → mappers/open-spec}/pathsMapper.js +10 -10
- package/lib/esm/{domain → components/stores}/JsonClassStore.js +8 -13
- package/lib/esm/{domain → components/stores}/JsonMethodStore.js +33 -28
- package/lib/esm/{domain → components/stores}/JsonParameterStore.js +14 -18
- package/lib/esm/{domain → components/stores}/JsonPropertyStore.js +15 -18
- package/lib/esm/components/types/arrayType.js +15 -0
- package/lib/esm/components/types/classType.js +8 -0
- package/lib/esm/components/types/genericType.js +8 -0
- package/lib/esm/components/types/mapType.js +15 -0
- package/lib/esm/components/types/primitiveType.js +21 -0
- package/lib/esm/components/types/setType.js +12 -0
- package/lib/esm/decorators/class/discriminatorValue.js +1 -1
- package/lib/esm/decorators/collections/collectionOf.js +2 -2
- package/lib/esm/decorators/collections/maxItems.js +1 -1
- package/lib/esm/decorators/collections/maxProperties.js +1 -1
- package/lib/esm/decorators/collections/minItems.js +1 -1
- package/lib/esm/decorators/collections/minProperties.js +1 -1
- package/lib/esm/decorators/collections/uniqueItems.js +1 -1
- package/lib/esm/decorators/common/defaultMsg.js +1 -1
- package/lib/esm/decorators/common/discriminatorKey.js +1 -1
- package/lib/esm/decorators/common/enum.js +1 -1
- package/lib/esm/decorators/common/exclusiveMaximum.js +1 -1
- package/lib/esm/decorators/common/exclusiveMinimum.js +1 -1
- package/lib/esm/decorators/common/format.js +1 -1
- package/lib/esm/decorators/common/jsonEntityFn.js +2 -2
- package/lib/esm/decorators/common/maxLength.js +1 -1
- package/lib/esm/decorators/common/maximum.js +1 -1
- package/lib/esm/decorators/common/minLength.js +1 -1
- package/lib/esm/decorators/common/minimum.js +1 -1
- package/lib/esm/decorators/common/multipleOf.js +1 -1
- package/lib/esm/decorators/common/name.js +1 -1
- package/lib/esm/decorators/common/nullable.js +2 -2
- package/lib/esm/decorators/common/pattern.js +1 -1
- package/lib/esm/decorators/common/required.js +1 -1
- package/lib/esm/decorators/common/requiredGroups.js +1 -1
- package/lib/esm/decorators/common/typeError.js +1 -1
- package/lib/esm/decorators/config/jsonEntityComponent.js +3 -2
- package/lib/esm/decorators/generics/genericOf.js +2 -2
- package/lib/esm/decorators/generics/generics.js +2 -3
- package/lib/esm/decorators/operations/consumes.js +1 -1
- package/lib/esm/decorators/operations/deprecated.js +1 -1
- package/lib/esm/decorators/operations/header.js +1 -1
- package/lib/esm/decorators/operations/in.js +5 -6
- package/lib/esm/decorators/operations/inFile.js +2 -2
- package/lib/esm/decorators/operations/operation.js +1 -1
- package/lib/esm/decorators/operations/produces.js +1 -1
- package/lib/esm/decorators/operations/publish.js +1 -1
- package/lib/esm/decorators/operations/returns.js +4 -4
- package/lib/esm/decorators/operations/route.js +1 -1
- package/lib/esm/decorators/operations/security.js +1 -1
- package/lib/esm/decorators/operations/subscribe.js +1 -1
- package/lib/esm/decorators/operations/tags.js +1 -1
- package/lib/esm/domain/DecoratorContext.js +2 -2
- package/lib/esm/domain/JsonEntityStore.js +7 -41
- package/lib/esm/domain/JsonLazyRef.js +1 -1
- package/lib/esm/domain/JsonMap.js +1 -1
- package/lib/esm/domain/JsonOperation.js +1 -1
- package/lib/esm/domain/JsonParameter.js +3 -3
- package/lib/esm/domain/JsonRequestBody.js +1 -1
- package/lib/esm/domain/JsonResponse.js +2 -2
- package/lib/esm/domain/JsonSchema.js +94 -131
- package/lib/esm/domain/index.js +26 -0
- package/lib/esm/{utils/getJsonSchema.js → fn/compile.js} +20 -7
- package/lib/esm/fn/enums.js +1 -1
- package/lib/esm/fn/from.js +32 -9
- package/lib/esm/fn/generic.js +9 -0
- package/lib/esm/fn/index.js +25 -4
- package/lib/esm/fn/lazyRef.js +3 -3
- package/lib/esm/fn/oas/compileSpec.js +9 -0
- package/lib/esm/{utils → fn/oas}/generateSpec.js +2 -2
- package/lib/esm/{utils → fn/oas}/getSpec.js +4 -4
- package/lib/esm/{utils → fn/oas}/getSpecType.js +1 -1
- package/lib/esm/{utils → fn/oas}/mapOpenSpec.js +1 -1
- package/lib/esm/hooks/alterOneOf.js +1 -1
- package/lib/esm/index.js +59 -48
- package/lib/esm/registries/JsonEntitiesContainer.js +38 -0
- package/lib/esm/registries/JsonSchemaMapperContainer.js +10 -1
- package/lib/esm/registries/JsonTypesContainer.js +18 -0
- package/lib/esm/utils/generics.js +15 -2
- package/lib/esm/utils/getInheritedStores.js +1 -1
- package/lib/esm/utils/getJsonType.js +2 -2
- package/lib/esm/utils/getOperationsRoutes.js +3 -3
- package/lib/esm/utils/getOperationsStores.js +4 -4
- package/lib/esm/utils/getPropertiesStores.js +2 -2
- package/lib/esm/utils/ref.js +2 -2
- package/lib/types/compat.d.ts +17 -0
- package/lib/types/components/index.d.ts +37 -27
- package/lib/types/components/{default → mappers/default}/anyMapper.d.ts +1 -1
- package/lib/types/components/mappers/default/classMapper.d.ts +3 -0
- package/lib/types/components/{default → mappers/default}/discriminatorMappingMapper.d.ts +2 -2
- package/lib/types/components/mappers/default/enumsMapper.d.ts +3 -0
- package/lib/types/components/{default → mappers/default}/genericsMapper.d.ts +2 -2
- package/lib/types/components/{default → mappers/default}/inheritedClassMapper.d.ts +1 -1
- package/lib/types/components/mappers/default/lazyRefMapper.d.ts +3 -0
- package/lib/types/components/{default → mappers/default}/mapMapper.d.ts +1 -1
- package/lib/types/components/{default → mappers/default}/nextMapper.d.ts +2 -2
- package/lib/types/components/{default → mappers/default}/nullableMapper.d.ts +1 -1
- package/lib/types/components/{default → mappers/default}/objectMapper.d.ts +1 -1
- package/lib/types/components/mappers/default/ofMapper.d.ts +3 -0
- package/lib/types/components/mappers/default/requiredMapper.d.ts +3 -0
- package/lib/types/components/mappers/default/schemaMapper.d.ts +3 -0
- package/lib/types/components/mappers/open-spec/enumsMapper.d.ts +3 -0
- package/lib/types/components/mappers/open-spec/generate.d.ts +1 -0
- package/lib/types/components/mappers/open-spec/nullableMapper.d.ts +3 -0
- package/lib/types/components/{open-spec → mappers/open-spec}/operationInParameterMapper.d.ts +3 -3
- package/lib/types/components/mappers/open-spec/operationInParametersMapper.d.ts +3 -0
- package/lib/types/components/mappers/open-spec/operationMapper.d.ts +3 -0
- package/lib/types/components/mappers/open-spec/operationMediaMapper.d.ts +3 -0
- package/lib/types/components/mappers/open-spec/operationRequestBodyMapper.d.ts +3 -0
- package/lib/types/components/mappers/open-spec/operationResponseMapper.d.ts +3 -0
- package/lib/types/components/{open-spec → mappers/open-spec}/pathsMapper.d.ts +1 -1
- package/lib/types/{domain → components/stores}/JsonClassStore.d.ts +4 -4
- package/lib/types/{domain → components/stores}/JsonMethodStore.d.ts +33 -19
- package/lib/types/{domain → components/stores}/JsonParameterStore.d.ts +9 -5
- package/lib/types/{domain → components/stores}/JsonPropertyStore.d.ts +7 -4
- package/lib/types/components/types/arrayType.d.ts +2 -0
- package/lib/types/components/types/classType.d.ts +2 -0
- package/lib/types/components/types/genericType.d.ts +2 -0
- package/lib/types/components/types/mapType.d.ts +2 -0
- package/lib/types/components/types/primitiveType.d.ts +2 -0
- package/lib/types/components/types/setType.d.ts +2 -0
- package/lib/types/decorators/common/any.d.ts +1 -1
- package/lib/types/decorators/common/examples.d.ts +1 -1
- package/lib/types/decorators/common/format.d.ts +1 -1
- package/lib/types/decorators/common/ignore.d.ts +1 -1
- package/lib/types/decorators/common/jsonEntityFn.d.ts +1 -1
- package/lib/types/decorators/config/jsonEntityComponent.d.ts +2 -1
- package/lib/types/decorators/generics/genericOf.d.ts +1 -1
- package/lib/types/decorators/operations/header.d.ts +1 -1
- package/lib/types/decorators/operations/in.d.ts +1 -2
- package/lib/types/decorators/operations/location.d.ts +1 -1
- package/lib/types/decorators/operations/redirect.d.ts +1 -1
- package/lib/types/decorators/operations/returns.d.ts +3 -3
- package/lib/types/decorators/operations/status.d.ts +1 -1
- package/lib/types/domain/Generics.d.ts +6 -0
- package/lib/types/domain/JsonEntityStore.d.ts +8 -19
- package/lib/types/domain/JsonLazyRef.d.ts +1 -1
- package/lib/types/domain/JsonMap.d.ts +1 -1
- package/lib/types/domain/JsonMedia.d.ts +1 -1
- package/lib/types/domain/JsonOperation.d.ts +2 -2
- package/lib/types/domain/JsonOperationRoute.d.ts +3 -3
- package/lib/types/domain/JsonParameter.d.ts +3 -3
- package/lib/types/domain/JsonRequestBody.d.ts +1 -1
- package/lib/types/domain/JsonResponse.d.ts +1 -1
- package/lib/types/domain/JsonSchema.d.ts +28 -22
- package/lib/types/{interfaces → domain}/JsonSchemaOptions.d.ts +14 -6
- package/lib/types/domain/__fixtures__/inspectOperationsPaths.d.ts +1 -1
- package/lib/types/domain/index.d.ts +26 -0
- package/lib/types/domain/types.d.ts +1 -1
- package/lib/types/fn/any.d.ts +1 -1
- package/lib/types/fn/boolean.d.ts +1 -1
- package/lib/types/{utils → fn}/compile.d.ts +10 -3
- package/lib/types/fn/date.d.ts +3 -3
- package/lib/types/fn/email.d.ts +1 -1
- package/lib/types/fn/from.d.ts +31 -3
- package/lib/types/fn/generic.d.ts +10 -0
- package/lib/types/fn/index.d.ts +24 -3
- package/lib/types/fn/integer.d.ts +1 -1
- package/lib/types/fn/lazyRef.d.ts +1 -1
- package/lib/types/fn/number.d.ts +1 -1
- package/lib/types/fn/oas/compileSpec.d.ts +6 -0
- package/lib/types/{utils → fn/oas}/getSpec.d.ts +1 -1
- package/lib/types/{utils → fn/oas}/getSpecType.d.ts +1 -1
- package/lib/types/{utils → fn/oas}/transformToOS2.d.ts +1 -1
- package/lib/types/fn/object.d.ts +1 -1
- package/lib/types/fn/string.d.ts +1 -1
- package/lib/types/fn/uri.d.ts +1 -1
- package/lib/types/fn/url.d.ts +1 -1
- package/lib/types/hooks/alterOneOf.d.ts +1 -1
- package/lib/types/hooks/alterRequiredGroups.d.ts +1 -1
- package/lib/types/index.d.ts +59 -48
- package/lib/types/{utils/getJsonEntityStore.d.ts → registries/JsonEntitiesContainer.d.ts} +5 -10
- package/lib/types/registries/JsonSchemaMapperContainer.d.ts +7 -1
- package/lib/types/registries/JsonTypesContainer.d.ts +15 -0
- package/lib/types/registries/{enumRegistries.d.ts → enumRegistry.d.ts} +1 -1
- package/lib/types/utils/generics.d.ts +13 -5
- package/lib/types/utils/getInheritedStores.d.ts +1 -1
- package/lib/types/utils/getOperationsRoutes.d.ts +3 -3
- package/lib/types/utils/getOperationsStores.d.ts +1 -1
- package/lib/types/utils/getPropertiesStores.d.ts +1 -1
- package/lib/types/utils/mapHeaders.d.ts +1 -1
- package/lib/types/utils/operationIdFormatter.d.ts +1 -1
- package/lib/types/utils/ref.d.ts +1 -1
- package/lib/types/utils/removeHiddenOperation.d.ts +1 -1
- package/lib/types/utils/toJsonMapCollection.d.ts +1 -1
- package/package.json +19 -19
- package/vitest.setup.ts +6 -0
- package/lib/esm/components/default/ofMapper.js +0 -9
- package/lib/esm/components/open-spec/discriminatorMappingMapper.js +0 -6
- package/lib/esm/components/open-spec/enumsMapper.js +0 -14
- package/lib/esm/components/open-spec/operationInParametersMapper.js +0 -5
- package/lib/esm/utils/compile.js +0 -13
- package/lib/esm/utils/getJsonEntityStore.js +0 -13
- package/lib/types/components/default/classMapper.d.ts +0 -3
- package/lib/types/components/default/enumsMapper.d.ts +0 -3
- package/lib/types/components/default/lazyRefMapper.d.ts +0 -3
- package/lib/types/components/default/ofMapper.d.ts +0 -3
- package/lib/types/components/default/requiredMapper.d.ts +0 -3
- package/lib/types/components/default/schemaMapper.d.ts +0 -3
- package/lib/types/components/open-spec/enumsMapper.d.ts +0 -3
- package/lib/types/components/open-spec/nullableMapper.d.ts +0 -3
- package/lib/types/components/open-spec/operationInParametersMapper.d.ts +0 -3
- package/lib/types/components/open-spec/operationMapper.d.ts +0 -3
- package/lib/types/components/open-spec/operationMediaMapper.d.ts +0 -3
- package/lib/types/components/open-spec/operationRequestBodyMapper.d.ts +0 -3
- package/lib/types/components/open-spec/operationResponseMapper.d.ts +0 -3
- package/lib/types/utils/getJsonSchema.d.ts +0 -6
- package/lib/esm/{interfaces/IgnoreCallback.js → domain/Generics.js} +0 -0
- package/lib/esm/{interfaces/JsonHookContext.js → domain/IgnoreCallback.js} +0 -0
- package/lib/esm/{interfaces/JsonOpenSpec.js → domain/JsonHookContext.js} +0 -0
- package/lib/esm/{interfaces/JsonSchemaOptions.js → domain/JsonOpenSpec.js} +0 -0
- package/lib/{types/components/open-spec/discriminatorMappingMapper.d.ts → esm/domain/JsonSchemaOptions.js} +0 -0
- package/lib/esm/{utils → fn/oas}/mapOpenSpec2.js +0 -0
- package/lib/esm/{utils → fn/oas}/mapOpenSpec3.js +0 -0
- package/lib/esm/{utils → fn/oas}/mapOpenSpecInfo.js +0 -0
- package/lib/esm/{utils → fn/oas}/mergeSpec.js +0 -0
- package/lib/esm/{utils → fn/oas}/transformToOS2.js +0 -0
- package/lib/esm/registries/{enumRegistries.js → enumRegistry.js} +0 -0
- package/lib/types/components/{open-spec/generate.d.ts → mappers/open-spec/discriminatorMappingMapper.d.ts} +0 -0
- package/lib/types/components/{open-spec → mappers/open-spec}/operationInFilesMapper.d.ts +0 -0
- package/lib/types/components/{open-spec → mappers/open-spec}/operationInQueryMapper.d.ts +0 -0
- package/lib/types/{interfaces → domain}/IgnoreCallback.d.ts +0 -0
- package/lib/types/{interfaces → domain}/JsonHookContext.d.ts +0 -0
- package/lib/types/{interfaces → domain}/JsonOpenSpec.d.ts +0 -0
- package/lib/types/{utils → fn/oas}/generateSpec.d.ts +1 -1
- /package/lib/types/{utils → fn/oas}/mapOpenSpec.d.ts +0 -0
- /package/lib/types/{utils → fn/oas}/mapOpenSpec2.d.ts +0 -0
- /package/lib/types/{utils → fn/oas}/mapOpenSpec3.d.ts +0 -0
- /package/lib/types/{utils → fn/oas}/mapOpenSpecInfo.d.ts +0 -0
- /package/lib/types/{utils → fn/oas}/mergeSpec.d.ts +0 -0
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { ancestorOf, ancestorsOf, classOf, isArray, isClass, isFunction, isObject, isPlainObject, isPrimitiveClass, nameOf, uniq } from "@tsed/core";
|
|
1
|
+
import { ancestorOf, ancestorsOf, classOf, isArray, isClass, isFunction, isObject, isPlainObject, isPrimitiveClass, isTemporal, nameOf, uniq } from "@tsed/core";
|
|
2
|
+
import { Discriminator } from "./JsonDiscriminator.js";
|
|
2
3
|
import { Hooks } from "@tsed/hooks";
|
|
3
4
|
import { VendorKeys } from "../constants/VendorKeys.js";
|
|
4
|
-
import { enumsRegistry } from "../registries/
|
|
5
|
+
import { enumsRegistry } from "../registries/enumRegistry.js";
|
|
5
6
|
import { execMapper } from "../registries/JsonSchemaMapperContainer.js";
|
|
6
7
|
import { getComputedType } from "../utils/getComputedType.js";
|
|
8
|
+
import { getJsonEntityStore } from "../registries/JsonEntitiesContainer.js";
|
|
7
9
|
import { getJsonType } from "../utils/getJsonType.js";
|
|
10
|
+
import { getTypeResolver } from "../registries/JsonTypesContainer.js";
|
|
8
11
|
import { matchGroups } from "../utils/matchGroups.js";
|
|
9
12
|
import { serializeEnumValues } from "../utils/serializeEnumValues.js";
|
|
10
13
|
import { toJsonRegex } from "../utils/toJsonRegex.js";
|
|
11
|
-
import { Discriminator } from "./JsonDiscriminator.js";
|
|
12
|
-
import { JsonEntityStore } from "./JsonEntityStore.js";
|
|
13
14
|
function isEnum(type) {
|
|
14
15
|
return isObject(type) && !("toJSON" in type);
|
|
15
16
|
}
|
|
@@ -45,7 +46,7 @@ function isEnum(type) {
|
|
|
45
46
|
* email: string;
|
|
46
47
|
* }
|
|
47
48
|
*
|
|
48
|
-
* const userSchema =
|
|
49
|
+
* const userSchema = s.from(User);
|
|
49
50
|
*
|
|
50
51
|
* // Generate JSON Schema output
|
|
51
52
|
* const jsonSchema = userSchema.toJSON();
|
|
@@ -178,8 +179,8 @@ export class JsonSchema extends Map {
|
|
|
178
179
|
*/
|
|
179
180
|
get discriminatorAncestor() {
|
|
180
181
|
const ancestors = ancestorsOf(this.#target);
|
|
181
|
-
const ancestor = ancestors.find((ancestor) =>
|
|
182
|
-
return ancestor &&
|
|
182
|
+
const ancestor = ancestors.find((ancestor) => getJsonEntityStore(ancestor).schema.isDiscriminator);
|
|
183
|
+
return ancestor && getJsonEntityStore(ancestor).schema;
|
|
183
184
|
}
|
|
184
185
|
/**
|
|
185
186
|
* Get the computed TypeScript class or type for this schema.
|
|
@@ -269,33 +270,38 @@ export class JsonSchema extends Map {
|
|
|
269
270
|
*
|
|
270
271
|
* ```typescript
|
|
271
272
|
* // From a class
|
|
272
|
-
* const schema1 =
|
|
273
|
+
* const schema1 = s.from(User);
|
|
273
274
|
*
|
|
274
275
|
* // From a primitive
|
|
275
|
-
* const schema2 =
|
|
276
|
+
* const schema2 = s.from(String);
|
|
276
277
|
*
|
|
277
278
|
* // From a schema object
|
|
278
|
-
* const schema3 =
|
|
279
|
+
* const schema3 = s.string().minLength(1);
|
|
279
280
|
*
|
|
280
281
|
* // From existing schema (no-op)
|
|
281
|
-
* const schema4 =
|
|
282
|
+
* const schema4 = s.from(schema1);
|
|
282
283
|
* ```
|
|
283
284
|
*
|
|
284
285
|
* @param item - The input to convert to a JsonSchema
|
|
285
286
|
* @returns A JsonSchema instance representing the input
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
287
|
+
* @deprecated
|
|
288
|
+
*/
|
|
289
|
+
// static from(item: Partial<JsonSchemaObject> | Type<any> | JsonSchema | undefined) {
|
|
290
|
+
// // console.trace("JsonSchema.from", item)
|
|
291
|
+
// if (item instanceof JsonSchema) {
|
|
292
|
+
// return item;
|
|
293
|
+
// }
|
|
294
|
+
//
|
|
295
|
+
// if (item && classOf(item) !== Object && isClass(item)) {
|
|
296
|
+
// return getJsonEntityStore(item).schema;
|
|
297
|
+
// }
|
|
298
|
+
//
|
|
299
|
+
// if (isPrimitiveClass(item) || item === Date || isTemporal(item) || item === null) {
|
|
300
|
+
// return new JsonSchema({type: item as Type});
|
|
301
|
+
// }
|
|
302
|
+
//
|
|
303
|
+
// return new JsonSchema(item as Partial<JsonSchemaObject>);
|
|
304
|
+
// }
|
|
299
305
|
static add(property, method) {
|
|
300
306
|
Object.defineProperty(JsonSchema.prototype, property, {
|
|
301
307
|
value: method,
|
|
@@ -437,24 +443,14 @@ export class JsonSchema extends Map {
|
|
|
437
443
|
this.vendorKey(VendorKeys.GENERIC_LABEL, genericLabel);
|
|
438
444
|
return this;
|
|
439
445
|
}
|
|
440
|
-
/**
|
|
441
|
-
* Specify the concrete types for generic parameters.
|
|
442
|
-
*
|
|
443
|
-
* When using a generic class, this method assigns the actual types that should
|
|
444
|
-
* replace the generic parameters for this specific instance.
|
|
445
|
-
*
|
|
446
|
-
* ### Usage
|
|
447
|
-
*
|
|
448
|
-
* ```typescript
|
|
449
|
-
* // For Paginated<User>
|
|
450
|
-
* schema.genericOf([User]);
|
|
451
|
-
* ```
|
|
452
|
-
*
|
|
453
|
-
* @param generics - Arrays of generic type values to apply
|
|
454
|
-
* @returns This schema instance for method chaining
|
|
455
|
-
*/
|
|
456
446
|
genericOf(...generics) {
|
|
457
|
-
|
|
447
|
+
if (!generics.length) {
|
|
448
|
+
return this;
|
|
449
|
+
}
|
|
450
|
+
const isGenericsMap = generics.length === 1 && isPlainObject(generics[0]) && Object.values(generics[0]).every(isArray);
|
|
451
|
+
const mapped = isGenericsMap
|
|
452
|
+
? generics[0]
|
|
453
|
+
: this.mapGenerics(this.#itemSchema || this.toSchema(this.getTarget()), generics.map((generic) => (Array.isArray(generic) ? generic : [generic])));
|
|
458
454
|
this.vendorKey(VendorKeys.GENERIC_OF, mapped);
|
|
459
455
|
return this;
|
|
460
456
|
}
|
|
@@ -486,7 +482,7 @@ export class JsonSchema extends Map {
|
|
|
486
482
|
* @returns The item schema instance
|
|
487
483
|
*/
|
|
488
484
|
itemSchema(obj = {}) {
|
|
489
|
-
this.#itemSchema = this.#itemSchema || this.
|
|
485
|
+
this.#itemSchema = this.#itemSchema || this.toSchema(obj);
|
|
490
486
|
if (isPlainObject(obj)) {
|
|
491
487
|
this.#itemSchema.assign(obj);
|
|
492
488
|
}
|
|
@@ -714,7 +710,7 @@ export class JsonSchema extends Map {
|
|
|
714
710
|
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.10
|
|
715
711
|
*/
|
|
716
712
|
additionalItems(additionalItems) {
|
|
717
|
-
super.set("additionalItems", this.
|
|
713
|
+
super.set("additionalItems", this.toSchema(additionalItems));
|
|
718
714
|
return this;
|
|
719
715
|
}
|
|
720
716
|
/**
|
|
@@ -722,7 +718,7 @@ export class JsonSchema extends Map {
|
|
|
722
718
|
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.14
|
|
723
719
|
*/
|
|
724
720
|
contains(contains) {
|
|
725
|
-
super.set("contains", this.
|
|
721
|
+
super.set("contains", this.toSchema(contains));
|
|
726
722
|
return this;
|
|
727
723
|
}
|
|
728
724
|
/**
|
|
@@ -749,8 +745,15 @@ export class JsonSchema extends Map {
|
|
|
749
745
|
* Set the items' schema for array/set collections
|
|
750
746
|
* @param items The schema for array/set items
|
|
751
747
|
*/
|
|
752
|
-
items(items) {
|
|
753
|
-
|
|
748
|
+
items(items, init = false) {
|
|
749
|
+
if (init) {
|
|
750
|
+
if (!this.has("items")) {
|
|
751
|
+
super.set("items", this.itemSchema(items));
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
else {
|
|
755
|
+
super.set("items", (this.#itemSchema = this.toSchema(items)));
|
|
756
|
+
}
|
|
754
757
|
return this;
|
|
755
758
|
}
|
|
756
759
|
$comment(comment) {
|
|
@@ -956,8 +959,15 @@ export class JsonSchema extends Map {
|
|
|
956
959
|
* The default value is an empty schema that allows any value for additional properties.
|
|
957
960
|
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.20
|
|
958
961
|
*/
|
|
959
|
-
additionalProperties(additionalProperties) {
|
|
960
|
-
|
|
962
|
+
additionalProperties(additionalProperties, init = false) {
|
|
963
|
+
if (init) {
|
|
964
|
+
if (!this.has("additionalProperties")) {
|
|
965
|
+
super.set("additionalProperties", this.itemSchema(additionalProperties));
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
else {
|
|
969
|
+
super.set("additionalProperties", this.toSchema(additionalProperties));
|
|
970
|
+
}
|
|
961
971
|
return this;
|
|
962
972
|
}
|
|
963
973
|
/**
|
|
@@ -990,7 +1000,7 @@ export class JsonSchema extends Map {
|
|
|
990
1000
|
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.22
|
|
991
1001
|
*/
|
|
992
1002
|
propertyNames(propertyNames) {
|
|
993
|
-
super.set("propertyNames", this.
|
|
1003
|
+
super.set("propertyNames", this.toSchema(propertyNames));
|
|
994
1004
|
return this;
|
|
995
1005
|
}
|
|
996
1006
|
enum(enumValue, ...enumValues) {
|
|
@@ -1048,7 +1058,7 @@ export class JsonSchema extends Map {
|
|
|
1048
1058
|
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.29
|
|
1049
1059
|
*/
|
|
1050
1060
|
not(not) {
|
|
1051
|
-
super.set("not", this.
|
|
1061
|
+
super.set("not", this.toSchema(not));
|
|
1052
1062
|
return this;
|
|
1053
1063
|
}
|
|
1054
1064
|
/**
|
|
@@ -1151,70 +1161,14 @@ export class JsonSchema extends Map {
|
|
|
1151
1161
|
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.25
|
|
1152
1162
|
*/
|
|
1153
1163
|
type(type) {
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
}
|
|
1163
|
-
break;
|
|
1164
|
-
case "array":
|
|
1165
|
-
case Array:
|
|
1166
|
-
super.set("type", getJsonType(type));
|
|
1167
|
-
this.target(type);
|
|
1168
|
-
this.#isCollection = true;
|
|
1169
|
-
if (!this.has("items")) {
|
|
1170
|
-
super.set("items", this.itemSchema({}));
|
|
1171
|
-
}
|
|
1172
|
-
break;
|
|
1173
|
-
case "set":
|
|
1174
|
-
case Set:
|
|
1175
|
-
super.set("type", getJsonType(type));
|
|
1176
|
-
this.target(type);
|
|
1177
|
-
this.#isCollection = true;
|
|
1178
|
-
this.uniqueItems(true);
|
|
1179
|
-
if (!this.has("items")) {
|
|
1180
|
-
super.set("items", this.itemSchema({}));
|
|
1181
|
-
}
|
|
1182
|
-
break;
|
|
1183
|
-
case "integer":
|
|
1184
|
-
this.integer();
|
|
1185
|
-
break;
|
|
1186
|
-
case "number":
|
|
1187
|
-
case "string":
|
|
1188
|
-
case "boolean":
|
|
1189
|
-
case "object":
|
|
1190
|
-
case Object:
|
|
1191
|
-
case Date:
|
|
1192
|
-
case Boolean:
|
|
1193
|
-
case Number:
|
|
1194
|
-
case String:
|
|
1195
|
-
super.set("type", getJsonType(type));
|
|
1196
|
-
this.target(type);
|
|
1197
|
-
if (!this.has("properties")) {
|
|
1198
|
-
super.set("properties", {});
|
|
1199
|
-
}
|
|
1200
|
-
break;
|
|
1201
|
-
default:
|
|
1202
|
-
if (isClass(type) || isFunction(type)) {
|
|
1203
|
-
super.set("type", undefined);
|
|
1204
|
-
this.target(type);
|
|
1205
|
-
if (!this.has("properties")) {
|
|
1206
|
-
super.set("properties", {});
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
else {
|
|
1210
|
-
const jsonType = getJsonType(type);
|
|
1211
|
-
if (jsonType === "generic") {
|
|
1212
|
-
this.genericLabel(type);
|
|
1213
|
-
}
|
|
1214
|
-
else {
|
|
1215
|
-
super.set("type", jsonType);
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1164
|
+
const resolver = getTypeResolver(type);
|
|
1165
|
+
if (resolver) {
|
|
1166
|
+
const jsonType = resolver.jsonType?.(type);
|
|
1167
|
+
jsonType && super.set("type", jsonType);
|
|
1168
|
+
resolver?.init?.(this, type);
|
|
1169
|
+
}
|
|
1170
|
+
else {
|
|
1171
|
+
super.set("type", getJsonType(type));
|
|
1218
1172
|
}
|
|
1219
1173
|
return this;
|
|
1220
1174
|
}
|
|
@@ -1309,8 +1263,8 @@ export class JsonSchema extends Map {
|
|
|
1309
1263
|
}
|
|
1310
1264
|
return this;
|
|
1311
1265
|
}
|
|
1312
|
-
set(key, value) {
|
|
1313
|
-
if (key in this) {
|
|
1266
|
+
set(key, value, force = false) {
|
|
1267
|
+
if (key in this && !force) {
|
|
1314
1268
|
isFunction(this[key]) && this[key](value);
|
|
1315
1269
|
}
|
|
1316
1270
|
else {
|
|
@@ -1357,7 +1311,7 @@ export class JsonSchema extends Map {
|
|
|
1357
1311
|
const labels = this.get(VendorKeys.GENERIC_LABELS);
|
|
1358
1312
|
if (this.isClass && !labels) {
|
|
1359
1313
|
const ancestor = ancestorOf(this.class);
|
|
1360
|
-
return ancestor === Object ? undefined :
|
|
1314
|
+
return ancestor === Object ? undefined : getJsonEntityStore(ancestor).schema.getGenericLabels();
|
|
1361
1315
|
}
|
|
1362
1316
|
return this.get(VendorKeys.GENERIC_LABELS);
|
|
1363
1317
|
}
|
|
@@ -1371,7 +1325,7 @@ export class JsonSchema extends Map {
|
|
|
1371
1325
|
*/
|
|
1372
1326
|
getRefSchema() {
|
|
1373
1327
|
if (!this.isLocalSchema && this.isClass) {
|
|
1374
|
-
const refSchema =
|
|
1328
|
+
const refSchema = getJsonEntityStore(this.class).schema;
|
|
1375
1329
|
if (refSchema !== this) {
|
|
1376
1330
|
return refSchema;
|
|
1377
1331
|
}
|
|
@@ -1388,9 +1342,10 @@ export class JsonSchema extends Map {
|
|
|
1388
1342
|
if (target === "object") {
|
|
1389
1343
|
this.#target = Object;
|
|
1390
1344
|
}
|
|
1391
|
-
else {
|
|
1345
|
+
else if (typeof target !== "string") {
|
|
1392
1346
|
this.#target = target;
|
|
1393
1347
|
}
|
|
1348
|
+
return this;
|
|
1394
1349
|
}
|
|
1395
1350
|
isRequiredValue(property, value) {
|
|
1396
1351
|
if (this.isRequired(property) && [undefined, null, ""].includes(value)) {
|
|
@@ -1401,6 +1356,14 @@ export class JsonSchema extends Map {
|
|
|
1401
1356
|
}
|
|
1402
1357
|
return false;
|
|
1403
1358
|
}
|
|
1359
|
+
toCollection() {
|
|
1360
|
+
this.#isCollection = true;
|
|
1361
|
+
return this;
|
|
1362
|
+
}
|
|
1363
|
+
unsetType() {
|
|
1364
|
+
super.set("type", undefined);
|
|
1365
|
+
return this;
|
|
1366
|
+
}
|
|
1404
1367
|
setManyOf(keyword, value) {
|
|
1405
1368
|
let resolved = value
|
|
1406
1369
|
.filter((o) => {
|
|
@@ -1410,7 +1373,7 @@ export class JsonSchema extends Map {
|
|
|
1410
1373
|
}
|
|
1411
1374
|
return true;
|
|
1412
1375
|
})
|
|
1413
|
-
.map((item) => this.
|
|
1376
|
+
.map((item) => this.toSchema(item));
|
|
1414
1377
|
if (resolved.length === 1 && !(value[0] instanceof JsonSchema) && !this.isNullable) {
|
|
1415
1378
|
if (!resolved[0].hasDiscriminator) {
|
|
1416
1379
|
return this.type(value[0]);
|
|
@@ -1419,7 +1382,7 @@ export class JsonSchema extends Map {
|
|
|
1419
1382
|
if (!children.length) {
|
|
1420
1383
|
return this.type(value[0]);
|
|
1421
1384
|
}
|
|
1422
|
-
resolved = children.map((item) => this.
|
|
1385
|
+
resolved = children.map((item) => this.toSchema(item));
|
|
1423
1386
|
}
|
|
1424
1387
|
super.set(keyword, resolved);
|
|
1425
1388
|
const jsonSchema = resolved[0];
|
|
@@ -1439,21 +1402,21 @@ export class JsonSchema extends Map {
|
|
|
1439
1402
|
this.#discriminator = discriminator;
|
|
1440
1403
|
}
|
|
1441
1404
|
}
|
|
1442
|
-
|
|
1405
|
+
toSchema(item) {
|
|
1443
1406
|
if (isArray(item)) {
|
|
1444
|
-
return item.map((item) => this.
|
|
1407
|
+
return item.map((item) => this.toSchema(item));
|
|
1445
1408
|
}
|
|
1446
1409
|
if (item && (item.isStore || item.$isJsonDocument || item.isLazyRef)) {
|
|
1447
1410
|
return item;
|
|
1448
1411
|
}
|
|
1449
1412
|
if (item && classOf(item) !== Object && isClass(item)) {
|
|
1450
|
-
return
|
|
1413
|
+
return getJsonEntityStore(item).schema;
|
|
1451
1414
|
}
|
|
1452
1415
|
if (isObject(item)) {
|
|
1453
|
-
return JsonSchema
|
|
1416
|
+
return new JsonSchema(item);
|
|
1454
1417
|
}
|
|
1455
|
-
if (isPrimitiveClass(item) || item === Date || item === null) {
|
|
1456
|
-
return JsonSchema
|
|
1418
|
+
if (isPrimitiveClass(item) || item === Date || isTemporal(item) || item === null) {
|
|
1419
|
+
return new JsonSchema({ type: item });
|
|
1457
1420
|
}
|
|
1458
1421
|
return item;
|
|
1459
1422
|
}
|
|
@@ -1481,14 +1444,14 @@ export class JsonSchema extends Map {
|
|
|
1481
1444
|
const label = genericLabels[index];
|
|
1482
1445
|
if (label) {
|
|
1483
1446
|
if (isEnum(type)) {
|
|
1484
|
-
mapping[label] = [JsonSchema
|
|
1447
|
+
mapping[label] = [new JsonSchema({ type: "string", enum: Object.values(type) })];
|
|
1485
1448
|
}
|
|
1486
1449
|
else if (nextTypes.length) {
|
|
1487
|
-
const nextSchema = this.
|
|
1450
|
+
const nextSchema = this.toSchema(type);
|
|
1488
1451
|
mapping[label] = [nextSchema, this.mapGenerics(nextSchema, nextTypes)];
|
|
1489
1452
|
}
|
|
1490
1453
|
else {
|
|
1491
|
-
mapping[label] = [this.
|
|
1454
|
+
mapping[label] = [this.toSchema(type)];
|
|
1492
1455
|
}
|
|
1493
1456
|
}
|
|
1494
1457
|
return mapping;
|
|
@@ -1500,7 +1463,7 @@ export class JsonSchema extends Map {
|
|
|
1500
1463
|
return properties;
|
|
1501
1464
|
}
|
|
1502
1465
|
return Object.entries(properties).reduce((properties, [key, schema]) => {
|
|
1503
|
-
properties[toJsonRegex(key)] = this.
|
|
1466
|
+
properties[toJsonRegex(key)] = this.toSchema(schema);
|
|
1504
1467
|
if (schema instanceof JsonSchema) {
|
|
1505
1468
|
schema.propertyKey(toJsonRegex(key));
|
|
1506
1469
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by @tsed/barrels.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./DecoratorContext.js";
|
|
5
|
+
export * from "./Generics.js";
|
|
6
|
+
export * from "./IgnoreCallback.js";
|
|
7
|
+
export * from "./JsonAliasMap.js";
|
|
8
|
+
export * from "./JsonDiscriminator.js";
|
|
9
|
+
export * from "./JsonEntityStore.js";
|
|
10
|
+
export * from "./JsonFormatTypes.js";
|
|
11
|
+
export * from "./JsonHookContext.js";
|
|
12
|
+
export * from "./JsonLazyRef.js";
|
|
13
|
+
export * from "./JsonMap.js";
|
|
14
|
+
export * from "./JsonMedia.js";
|
|
15
|
+
export * from "./JsonOpenSpec.js";
|
|
16
|
+
export * from "./JsonOperation.js";
|
|
17
|
+
export * from "./JsonOperationPathsMap.js";
|
|
18
|
+
export * from "./JsonOperationRoute.js";
|
|
19
|
+
export * from "./JsonParameter.js";
|
|
20
|
+
export * from "./JsonParameterTypes.js";
|
|
21
|
+
export * from "./JsonRequestBody.js";
|
|
22
|
+
export * from "./JsonResponse.js";
|
|
23
|
+
export * from "./JsonSchema.js";
|
|
24
|
+
export * from "./JsonSchemaOptions.js";
|
|
25
|
+
export * from "./SpecTypes.js";
|
|
26
|
+
export * from "./types.js";
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import "../components/index.js";
|
|
2
|
-
import { getValue, isClass, isPlainObject, nameOf } from "@tsed/core";
|
|
3
|
-
import {
|
|
4
|
-
import { JsonSchema } from "../domain/JsonSchema.js";
|
|
5
|
-
import { SpecTypes } from "../domain/SpecTypes.js";
|
|
2
|
+
import { DecoratorTypes, getValue, isClass, isPlainObject, nameOf } from "@tsed/core";
|
|
3
|
+
import { JsonSchema, SpecTypes } from "../domain/index.js";
|
|
6
4
|
import { execMapper } from "../registries/JsonSchemaMapperContainer.js";
|
|
7
|
-
import { getJsonEntityStore } from "
|
|
5
|
+
import { getJsonEntityStore } from "../registries/JsonEntitiesContainer.js";
|
|
8
6
|
/**
|
|
9
7
|
* @ignore
|
|
10
8
|
*/
|
|
@@ -34,7 +32,7 @@ function get(model, options) {
|
|
|
34
32
|
}
|
|
35
33
|
const entity = getJsonEntityStore(model);
|
|
36
34
|
let mapper = "schema";
|
|
37
|
-
if (entity
|
|
35
|
+
if (entity.is(DecoratorTypes.PARAM)) {
|
|
38
36
|
options = {
|
|
39
37
|
...options,
|
|
40
38
|
root: true,
|
|
@@ -50,7 +48,16 @@ function get(model, options) {
|
|
|
50
48
|
}
|
|
51
49
|
return cache.get(key);
|
|
52
50
|
}
|
|
53
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Compile a class, parameter store, or `JsonSchema` into a plain JSON schema object.
|
|
53
|
+
*
|
|
54
|
+
* This is an alias of `getJsonSchema(...)`.
|
|
55
|
+
*
|
|
56
|
+
* @param model Class, parameter store, or `JsonSchema` to compile.
|
|
57
|
+
* @param options JSON schema generation options.
|
|
58
|
+
* @returns Compiled JSON schema object.
|
|
59
|
+
*/
|
|
60
|
+
export function compile(model, options = {}) {
|
|
54
61
|
const specType = options.specType || SpecTypes.JSON;
|
|
55
62
|
options = {
|
|
56
63
|
endpoint: true,
|
|
@@ -64,3 +71,9 @@ export function getJsonSchema(model, options = {}) {
|
|
|
64
71
|
};
|
|
65
72
|
return get(model, options);
|
|
66
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated Use s.compile() instead
|
|
76
|
+
* @param model
|
|
77
|
+
* @param options
|
|
78
|
+
*/
|
|
79
|
+
export const getJsonSchema = compile;
|
package/lib/esm/fn/enums.js
CHANGED
package/lib/esm/fn/from.js
CHANGED
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
import { isClass } from "@tsed/core";
|
|
2
2
|
import { JsonSchema } from "../domain/JsonSchema.js";
|
|
3
|
-
import { getJsonEntityStore } from "../
|
|
3
|
+
import { getJsonEntityStore } from "../registries/JsonEntitiesContainer.js";
|
|
4
4
|
export function from(type = Object) {
|
|
5
5
|
if (isClass(type)) {
|
|
6
6
|
const { schema } = getJsonEntityStore(type);
|
|
7
|
-
schema.
|
|
8
|
-
Object.entries(obj).forEach(([propertyKey, propSchema]) => {
|
|
9
|
-
getJsonEntityStore(type.prototype, propertyKey).schema.assign(propSchema);
|
|
10
|
-
});
|
|
11
|
-
return this;
|
|
12
|
-
};
|
|
13
|
-
return schema;
|
|
7
|
+
return schema.clone();
|
|
14
8
|
}
|
|
15
|
-
return JsonSchema
|
|
9
|
+
return new JsonSchema({ type });
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Get the shared schema instance attached to a class.
|
|
13
|
+
*
|
|
14
|
+
* Contrary to @@from@@, `get()` returns the schema stored in the class metadata.
|
|
15
|
+
* Mutating the returned instance updates the class-level schema definition and
|
|
16
|
+
* therefore affects every consumer of that class schema.
|
|
17
|
+
*
|
|
18
|
+
* This helper is intended for low-level or internal patching scenarios where the
|
|
19
|
+
* source schema must be updated in place.
|
|
20
|
+
*
|
|
21
|
+
* ```typescript
|
|
22
|
+
* get(UserModel).properties({
|
|
23
|
+
* name: string()
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param type The class owning the shared schema metadata.
|
|
28
|
+
* @returns The shared `JsonSchema` instance for the class.
|
|
29
|
+
*/
|
|
30
|
+
export function get(type) {
|
|
31
|
+
const { schema } = getJsonEntityStore(type);
|
|
32
|
+
schema.properties = function properties(obj) {
|
|
33
|
+
Object.entries(obj).forEach(([propertyKey, propSchema]) => {
|
|
34
|
+
getJsonEntityStore(type.prototype, propertyKey).schema.assign(propSchema);
|
|
35
|
+
});
|
|
36
|
+
return this;
|
|
37
|
+
};
|
|
38
|
+
return schema;
|
|
16
39
|
}
|
package/lib/esm/fn/index.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
import { array, map, record, set } from "./collection.js";
|
|
2
|
+
import { date, datetime, time } from "./date.js";
|
|
3
|
+
import { from, get } from "./from.js";
|
|
4
|
+
import { getJsonEntityStore, getJsonMethodStore } from "../registries/JsonEntitiesContainer.js";
|
|
1
5
|
import { allOf } from "./allOf.js";
|
|
2
6
|
import { any } from "./any.js";
|
|
3
7
|
import { anyOf } from "./anyOf.js";
|
|
4
8
|
import { boolean } from "./boolean.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
9
|
+
import { compile } from "./compile.js";
|
|
10
|
+
import { compileSpec } from "./oas/compileSpec.js";
|
|
7
11
|
import { email } from "./email.js";
|
|
8
12
|
import { enums } from "./enums.js";
|
|
9
|
-
import {
|
|
13
|
+
import { generic } from "./generic.js";
|
|
10
14
|
import { integer } from "./integer.js";
|
|
11
15
|
import { lazyRef } from "./lazyRef.js";
|
|
16
|
+
import { mergeSchema } from "../utils/mergeSchema.js";
|
|
17
|
+
import { mergeSpec } from "./oas/mergeSpec.js";
|
|
12
18
|
import { number } from "./number.js";
|
|
13
19
|
import { object } from "./object.js";
|
|
14
20
|
import { oneOf } from "./oneOf.js";
|
|
@@ -43,5 +49,20 @@ export const s = {
|
|
|
43
49
|
$ref: ref,
|
|
44
50
|
string,
|
|
45
51
|
uri,
|
|
46
|
-
url
|
|
52
|
+
url,
|
|
53
|
+
generic,
|
|
54
|
+
get,
|
|
55
|
+
store: Object.assign(getJsonEntityStore, {
|
|
56
|
+
get: getJsonEntityStore,
|
|
57
|
+
method: getJsonMethodStore
|
|
58
|
+
}),
|
|
59
|
+
schema: {
|
|
60
|
+
compile,
|
|
61
|
+
merge: mergeSchema
|
|
62
|
+
},
|
|
63
|
+
compile,
|
|
64
|
+
oas: Object.assign(compileSpec, {
|
|
65
|
+
compile: compileSpec,
|
|
66
|
+
merge: mergeSpec
|
|
67
|
+
})
|
|
47
68
|
};
|
package/lib/esm/fn/lazyRef.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { JsonLazyRef } from "../domain/index.js";
|
|
2
|
+
import { getJsonEntityStore } from "../registries/JsonEntitiesContainer.js";
|
|
3
3
|
export function lazyRef(cb) {
|
|
4
4
|
try {
|
|
5
5
|
// solve issue with a self referenced model
|
|
6
6
|
if (cb()) {
|
|
7
7
|
// type is already accessible
|
|
8
|
-
return
|
|
8
|
+
return getJsonEntityStore(cb()).schema;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
catch (er) { }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { generateSpec } from "./generateSpec.js";
|
|
2
|
+
import { getSpec } from "./getSpec.js";
|
|
3
|
+
import { isPlainObject } from "@tsed/core";
|
|
4
|
+
export function compileSpec(modelOrOptions, options) {
|
|
5
|
+
if (!isPlainObject(modelOrOptions) || options) {
|
|
6
|
+
return getSpec(modelOrOptions, options);
|
|
7
|
+
}
|
|
8
|
+
return generateSpec(modelOrOptions);
|
|
9
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getValue } from "@tsed/core";
|
|
2
|
-
import { SpecTypes } from "../domain/SpecTypes.js";
|
|
3
1
|
import { getSpec } from "./getSpec.js";
|
|
2
|
+
import { SpecTypes } from "../../domain/SpecTypes.js";
|
|
4
3
|
import { getSpecTypeFromSpec } from "./getSpecType.js";
|
|
4
|
+
import { getValue } from "@tsed/core";
|
|
5
5
|
import { mapOpenSpec } from "./mapOpenSpec.js";
|
|
6
6
|
import { mergeSpec } from "./mergeSpec.js";
|
|
7
7
|
import { transformToOS2 } from "./transformToOS2.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { cleanObject, isArray } from "@tsed/core";
|
|
2
|
-
import { SpecTypes } from "
|
|
3
|
-
import { execMapper } from "
|
|
4
|
-
import { getJsonEntityStore } from "
|
|
2
|
+
import { SpecTypes } from "../../domain/index.js";
|
|
3
|
+
import { execMapper } from "../../registries/JsonSchemaMapperContainer.js";
|
|
4
|
+
import { getJsonEntityStore } from "../../registries/JsonEntitiesContainer.js";
|
|
5
5
|
import { mergeSpec } from "./mergeSpec.js";
|
|
6
|
-
import { operationIdFormatter } from "
|
|
6
|
+
import { operationIdFormatter } from "../../utils/operationIdFormatter.js";
|
|
7
7
|
/**
|
|
8
8
|
* @ignore
|
|
9
9
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getValue, setValue } from "@tsed/core";
|
|
2
|
-
import { SpecTypes } from "
|
|
2
|
+
import { SpecTypes } from "../../domain/index.js";
|
|
3
3
|
import { getSpecType } from "./getSpecType.js";
|
|
4
4
|
import { mapOpenSpec2 } from "./mapOpenSpec2.js";
|
|
5
5
|
import { mapOpenSpec3 } from "./mapOpenSpec3.js";
|