@tsed/schema 8.34.0 → 8.36.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 +92 -137
- package/lib/esm/domain/index.js +26 -0
- package/lib/esm/fn/compile.js +82 -0
- 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 +60 -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/getOperationsRoutes.js +3 -3
- package/lib/esm/utils/getOperationsStores.js +4 -4
- package/lib/esm/utils/getPropertiesStores.js +2 -2
- package/lib/esm/utils/inlineRefs.js +64 -0
- 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 +20 -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/fn/compile.d.ts +21 -0
- 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 +60 -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/inlineRefs.d.ts +7 -0
- 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 +18 -19
- 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/esm/utils/getJsonSchema.js +0 -66
- 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/compile.d.ts +0 -14
- 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
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,78 +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 (isTemporal(type)) {
|
|
1203
|
-
// Temporal.* types serialize to an ISO-8601 string, like Date.
|
|
1204
|
-
super.set("type", getJsonType(type));
|
|
1205
|
-
this.target(type);
|
|
1206
|
-
if (!this.has("properties")) {
|
|
1207
|
-
super.set("properties", {});
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
else if (isClass(type) || isFunction(type)) {
|
|
1211
|
-
super.set("type", undefined);
|
|
1212
|
-
this.target(type);
|
|
1213
|
-
if (!this.has("properties")) {
|
|
1214
|
-
super.set("properties", {});
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
else {
|
|
1218
|
-
const jsonType = getJsonType(type);
|
|
1219
|
-
if (jsonType === "generic") {
|
|
1220
|
-
this.genericLabel(type);
|
|
1221
|
-
}
|
|
1222
|
-
else {
|
|
1223
|
-
super.set("type", jsonType);
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
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));
|
|
1226
1172
|
}
|
|
1227
1173
|
return this;
|
|
1228
1174
|
}
|
|
@@ -1317,8 +1263,8 @@ export class JsonSchema extends Map {
|
|
|
1317
1263
|
}
|
|
1318
1264
|
return this;
|
|
1319
1265
|
}
|
|
1320
|
-
set(key, value) {
|
|
1321
|
-
if (key in this) {
|
|
1266
|
+
set(key, value, force = false) {
|
|
1267
|
+
if (key in this && !force) {
|
|
1322
1268
|
isFunction(this[key]) && this[key](value);
|
|
1323
1269
|
}
|
|
1324
1270
|
else {
|
|
@@ -1365,7 +1311,7 @@ export class JsonSchema extends Map {
|
|
|
1365
1311
|
const labels = this.get(VendorKeys.GENERIC_LABELS);
|
|
1366
1312
|
if (this.isClass && !labels) {
|
|
1367
1313
|
const ancestor = ancestorOf(this.class);
|
|
1368
|
-
return ancestor === Object ? undefined :
|
|
1314
|
+
return ancestor === Object ? undefined : getJsonEntityStore(ancestor).schema.getGenericLabels();
|
|
1369
1315
|
}
|
|
1370
1316
|
return this.get(VendorKeys.GENERIC_LABELS);
|
|
1371
1317
|
}
|
|
@@ -1379,7 +1325,7 @@ export class JsonSchema extends Map {
|
|
|
1379
1325
|
*/
|
|
1380
1326
|
getRefSchema() {
|
|
1381
1327
|
if (!this.isLocalSchema && this.isClass) {
|
|
1382
|
-
const refSchema =
|
|
1328
|
+
const refSchema = getJsonEntityStore(this.class).schema;
|
|
1383
1329
|
if (refSchema !== this) {
|
|
1384
1330
|
return refSchema;
|
|
1385
1331
|
}
|
|
@@ -1396,9 +1342,10 @@ export class JsonSchema extends Map {
|
|
|
1396
1342
|
if (target === "object") {
|
|
1397
1343
|
this.#target = Object;
|
|
1398
1344
|
}
|
|
1399
|
-
else {
|
|
1345
|
+
else if (typeof target !== "string") {
|
|
1400
1346
|
this.#target = target;
|
|
1401
1347
|
}
|
|
1348
|
+
return this;
|
|
1402
1349
|
}
|
|
1403
1350
|
isRequiredValue(property, value) {
|
|
1404
1351
|
if (this.isRequired(property) && [undefined, null, ""].includes(value)) {
|
|
@@ -1409,6 +1356,14 @@ export class JsonSchema extends Map {
|
|
|
1409
1356
|
}
|
|
1410
1357
|
return false;
|
|
1411
1358
|
}
|
|
1359
|
+
toCollection() {
|
|
1360
|
+
this.#isCollection = true;
|
|
1361
|
+
return this;
|
|
1362
|
+
}
|
|
1363
|
+
unsetType() {
|
|
1364
|
+
super.set("type", undefined);
|
|
1365
|
+
return this;
|
|
1366
|
+
}
|
|
1412
1367
|
setManyOf(keyword, value) {
|
|
1413
1368
|
let resolved = value
|
|
1414
1369
|
.filter((o) => {
|
|
@@ -1418,7 +1373,7 @@ export class JsonSchema extends Map {
|
|
|
1418
1373
|
}
|
|
1419
1374
|
return true;
|
|
1420
1375
|
})
|
|
1421
|
-
.map((item) => this.
|
|
1376
|
+
.map((item) => this.toSchema(item));
|
|
1422
1377
|
if (resolved.length === 1 && !(value[0] instanceof JsonSchema) && !this.isNullable) {
|
|
1423
1378
|
if (!resolved[0].hasDiscriminator) {
|
|
1424
1379
|
return this.type(value[0]);
|
|
@@ -1427,7 +1382,7 @@ export class JsonSchema extends Map {
|
|
|
1427
1382
|
if (!children.length) {
|
|
1428
1383
|
return this.type(value[0]);
|
|
1429
1384
|
}
|
|
1430
|
-
resolved = children.map((item) => this.
|
|
1385
|
+
resolved = children.map((item) => this.toSchema(item));
|
|
1431
1386
|
}
|
|
1432
1387
|
super.set(keyword, resolved);
|
|
1433
1388
|
const jsonSchema = resolved[0];
|
|
@@ -1447,21 +1402,21 @@ export class JsonSchema extends Map {
|
|
|
1447
1402
|
this.#discriminator = discriminator;
|
|
1448
1403
|
}
|
|
1449
1404
|
}
|
|
1450
|
-
|
|
1405
|
+
toSchema(item) {
|
|
1451
1406
|
if (isArray(item)) {
|
|
1452
|
-
return item.map((item) => this.
|
|
1407
|
+
return item.map((item) => this.toSchema(item));
|
|
1453
1408
|
}
|
|
1454
1409
|
if (item && (item.isStore || item.$isJsonDocument || item.isLazyRef)) {
|
|
1455
1410
|
return item;
|
|
1456
1411
|
}
|
|
1457
1412
|
if (item && classOf(item) !== Object && isClass(item)) {
|
|
1458
|
-
return
|
|
1413
|
+
return getJsonEntityStore(item).schema;
|
|
1459
1414
|
}
|
|
1460
1415
|
if (isObject(item)) {
|
|
1461
|
-
return JsonSchema
|
|
1416
|
+
return new JsonSchema(item);
|
|
1462
1417
|
}
|
|
1463
1418
|
if (isPrimitiveClass(item) || item === Date || isTemporal(item) || item === null) {
|
|
1464
|
-
return JsonSchema
|
|
1419
|
+
return new JsonSchema({ type: item });
|
|
1465
1420
|
}
|
|
1466
1421
|
return item;
|
|
1467
1422
|
}
|
|
@@ -1489,14 +1444,14 @@ export class JsonSchema extends Map {
|
|
|
1489
1444
|
const label = genericLabels[index];
|
|
1490
1445
|
if (label) {
|
|
1491
1446
|
if (isEnum(type)) {
|
|
1492
|
-
mapping[label] = [JsonSchema
|
|
1447
|
+
mapping[label] = [new JsonSchema({ type: "string", enum: Object.values(type) })];
|
|
1493
1448
|
}
|
|
1494
1449
|
else if (nextTypes.length) {
|
|
1495
|
-
const nextSchema = this.
|
|
1450
|
+
const nextSchema = this.toSchema(type);
|
|
1496
1451
|
mapping[label] = [nextSchema, this.mapGenerics(nextSchema, nextTypes)];
|
|
1497
1452
|
}
|
|
1498
1453
|
else {
|
|
1499
|
-
mapping[label] = [this.
|
|
1454
|
+
mapping[label] = [this.toSchema(type)];
|
|
1500
1455
|
}
|
|
1501
1456
|
}
|
|
1502
1457
|
return mapping;
|
|
@@ -1508,7 +1463,7 @@ export class JsonSchema extends Map {
|
|
|
1508
1463
|
return properties;
|
|
1509
1464
|
}
|
|
1510
1465
|
return Object.entries(properties).reduce((properties, [key, schema]) => {
|
|
1511
|
-
properties[toJsonRegex(key)] = this.
|
|
1466
|
+
properties[toJsonRegex(key)] = this.toSchema(schema);
|
|
1512
1467
|
if (schema instanceof JsonSchema) {
|
|
1513
1468
|
schema.propertyKey(toJsonRegex(key));
|
|
1514
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";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import "../components/index.js";
|
|
2
|
+
import { DecoratorTypes, getValue, isClass, isPlainObject, nameOf } from "@tsed/core";
|
|
3
|
+
import { JsonSchema, SpecTypes } from "../domain/index.js";
|
|
4
|
+
import { execMapper } from "../registries/JsonSchemaMapperContainer.js";
|
|
5
|
+
import { getJsonEntityStore } from "../registries/JsonEntitiesContainer.js";
|
|
6
|
+
import { inlineRefs } from "../utils/inlineRefs.js";
|
|
7
|
+
/**
|
|
8
|
+
* @ignore
|
|
9
|
+
*/
|
|
10
|
+
const CACHES = new Map();
|
|
11
|
+
/**
|
|
12
|
+
* @ignore
|
|
13
|
+
*/
|
|
14
|
+
function getKey(options) {
|
|
15
|
+
return JSON.stringify(options, (key, value) => {
|
|
16
|
+
if (value && !isPlainObject(value) && isClass(value)) {
|
|
17
|
+
return nameOf(value);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @ignore
|
|
24
|
+
*/
|
|
25
|
+
function get(model, options) {
|
|
26
|
+
const cache = CACHES.get(model) || new Map();
|
|
27
|
+
CACHES.set(model, cache);
|
|
28
|
+
const key = getKey(options);
|
|
29
|
+
if (!cache.has(key)) {
|
|
30
|
+
let schema;
|
|
31
|
+
if (model instanceof JsonSchema) {
|
|
32
|
+
schema = model.toJSON(options);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const entity = getJsonEntityStore(model);
|
|
36
|
+
let mapper = "schema";
|
|
37
|
+
if (entity.is(DecoratorTypes.PARAM)) {
|
|
38
|
+
options = {
|
|
39
|
+
...options,
|
|
40
|
+
root: true,
|
|
41
|
+
groups: entity.schema.getGroups()
|
|
42
|
+
};
|
|
43
|
+
mapper = "item";
|
|
44
|
+
}
|
|
45
|
+
schema = execMapper(mapper, [entity.schema], options);
|
|
46
|
+
}
|
|
47
|
+
if (Object.keys(getValue(options, "components.schemas", {})).length) {
|
|
48
|
+
schema.definitions = options.components.schemas;
|
|
49
|
+
}
|
|
50
|
+
cache.set(key, options.inlineRefs ? inlineRefs(schema) : schema);
|
|
51
|
+
}
|
|
52
|
+
return cache.get(key);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Compile a class, parameter store, or `JsonSchema` into a plain JSON schema object.
|
|
56
|
+
*
|
|
57
|
+
* This is an alias of `getJsonSchema(...)`.
|
|
58
|
+
*
|
|
59
|
+
* @param model Class, parameter store, or `JsonSchema` to compile.
|
|
60
|
+
* @param options JSON schema generation options.
|
|
61
|
+
* @returns Compiled JSON schema object.
|
|
62
|
+
*/
|
|
63
|
+
export function compile(model, options = {}) {
|
|
64
|
+
const specType = options.specType || SpecTypes.JSON;
|
|
65
|
+
options = {
|
|
66
|
+
endpoint: true,
|
|
67
|
+
groups: [],
|
|
68
|
+
inlineEnums: specType === SpecTypes.JSON,
|
|
69
|
+
...options,
|
|
70
|
+
specType,
|
|
71
|
+
components: {
|
|
72
|
+
schemas: {}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
return get(model, options);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* @deprecated Use s.compile() instead
|
|
79
|
+
* @param model
|
|
80
|
+
* @param options
|
|
81
|
+
*/
|
|
82
|
+
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";
|