@rvoh/dream 2.38.0 → 2.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -34
- package/dist/cjs/src/dream-app/index.js +31 -1
- package/dist/cjs/src/helpers/areEqual.js +2 -2
- package/dist/cjs/src/helpers/path/absoluteDreamPath.js +5 -3
- package/dist/cjs/src/serializer/DreamSerializer.js +5 -5
- package/dist/cjs/src/serializer/ObjectSerializer.js +5 -5
- package/dist/cjs/src/serializer/SerializerRenderer.js +21 -28
- package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +40 -33
- package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +38 -33
- package/dist/cjs/src/serializer/helpers/nullFlattenedSerializerKeys.js +44 -68
- package/dist/cjs/src/serializer/helpers/serializersForAssociatedClass.js +4 -3
- package/dist/esm/src/dream-app/index.js +31 -1
- package/dist/esm/src/helpers/areEqual.js +2 -2
- package/dist/esm/src/helpers/path/absoluteDreamPath.js +5 -3
- package/dist/esm/src/serializer/DreamSerializer.js +5 -5
- package/dist/esm/src/serializer/ObjectSerializer.js +5 -5
- package/dist/esm/src/serializer/SerializerRenderer.js +21 -28
- package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +40 -33
- package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +38 -33
- package/dist/esm/src/serializer/helpers/nullFlattenedSerializerKeys.js +44 -68
- package/dist/esm/src/serializer/helpers/serializersForAssociatedClass.js +4 -3
- package/dist/types/src/dream-app/index.d.ts +26 -3
- package/dist/types/src/serializer/DreamSerializer.d.ts +5 -5
- package/dist/types/src/serializer/ObjectSerializer.d.ts +5 -5
- package/dist/types/src/serializer/SerializerRenderer.d.ts +1 -1
- package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +43 -35
- package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +41 -35
- package/dist/types/src/serializer/helpers/nullFlattenedSerializerKeys.d.ts +43 -33
- package/dist/types/src/serializer/helpers/serializersForAssociatedClass.d.ts +4 -3
- package/docs/assets/search.js +1 -1
- package/docs/classes/db.DreamMigrationHelpers.html +11 -11
- package/docs/classes/db.KyselyQueryDriver.html +49 -49
- package/docs/classes/db.PostgresQueryDriver.html +49 -49
- package/docs/classes/db.QueryDriverBase.html +49 -49
- package/docs/classes/errors.CannotSaveMissingDream.html +2 -2
- package/docs/classes/errors.CheckConstraintViolation.html +3 -3
- package/docs/classes/errors.ColumnOverflow.html +3 -3
- package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +3 -3
- package/docs/classes/errors.DataTypeColumnTypeMismatch.html +3 -3
- package/docs/classes/errors.DecryptionError.html +2 -2
- package/docs/classes/errors.DecryptionParseError.html +2 -2
- package/docs/classes/errors.DecryptionRotationError.html +3 -3
- package/docs/classes/errors.GlobalNameNotSet.html +3 -3
- package/docs/classes/errors.InvalidCalendarDate.html +2 -2
- package/docs/classes/errors.InvalidClockTime.html +2 -2
- package/docs/classes/errors.InvalidClockTimeTz.html +2 -2
- package/docs/classes/errors.InvalidDateTime.html +2 -2
- package/docs/classes/errors.MissingSerializersDefinition.html +3 -3
- package/docs/classes/errors.NonLoadedAssociation.html +3 -3
- package/docs/classes/errors.NotNullViolation.html +3 -3
- package/docs/classes/errors.RecordNotFound.html +3 -3
- package/docs/classes/errors.SortableScopeDidNotStabilize.html +3 -3
- package/docs/classes/errors.SortableScopeLockWaitTimedOut.html +3 -3
- package/docs/classes/errors.ValidationError.html +3 -3
- package/docs/classes/index.CalendarDate.html +33 -33
- package/docs/classes/index.ClockTime.html +32 -32
- package/docs/classes/index.ClockTimeTz.html +35 -35
- package/docs/classes/index.DateTime.html +86 -86
- package/docs/classes/index.Decorators.html +19 -19
- package/docs/classes/index.Dream.html +125 -125
- package/docs/classes/index.DreamApp.html +26 -11
- package/docs/classes/index.DreamTransaction.html +3 -3
- package/docs/classes/index.Env.html +5 -5
- package/docs/classes/index.Query.html +65 -65
- package/docs/classes/system.CliFileWriter.html +4 -4
- package/docs/classes/system.DreamBin.html +3 -3
- package/docs/classes/system.DreamCLI.html +7 -7
- package/docs/classes/system.DreamImporter.html +2 -2
- package/docs/classes/system.DreamLogos.html +2 -2
- package/docs/classes/system.DreamSerializerBuilder.html +51 -44
- package/docs/classes/system.ObjectSerializerBuilder.html +49 -43
- package/docs/classes/system.PathHelpers.html +3 -3
- package/docs/classes/utils.Encrypt.html +4 -4
- package/docs/classes/utils.Range.html +2 -2
- package/docs/functions/db.closeAllDbConnections.html +1 -1
- package/docs/functions/db.dreamDbConnections.html +1 -1
- package/docs/functions/db.untypedDb.html +1 -1
- package/docs/functions/db.validateColumn.html +1 -1
- package/docs/functions/db.validateTable.html +1 -1
- package/docs/functions/errors.pgErrorType.html +1 -1
- package/docs/functions/index.DreamSerializer.html +6 -6
- package/docs/functions/index.ObjectSerializer.html +6 -6
- package/docs/functions/index.ReplicaSafe.html +1 -1
- package/docs/functions/index.STI.html +1 -1
- package/docs/functions/index.SoftDelete.html +1 -1
- package/docs/functions/utils.camelize.html +1 -1
- package/docs/functions/utils.capitalize.html +1 -1
- package/docs/functions/utils.cloneDeepSafe.html +1 -1
- package/docs/functions/utils.compact.html +1 -1
- package/docs/functions/utils.groupBy.html +1 -1
- package/docs/functions/utils.hyphenize.html +1 -1
- package/docs/functions/utils.intersection.html +1 -1
- package/docs/functions/utils.isEmpty.html +1 -1
- package/docs/functions/utils.normalizeUnicode.html +1 -1
- package/docs/functions/utils.pascalize.html +1 -1
- package/docs/functions/utils.percent.html +1 -1
- package/docs/functions/utils.range.html +1 -1
- package/docs/functions/utils.round.html +1 -1
- package/docs/functions/utils.sanitizeString.html +1 -1
- package/docs/functions/utils.snakeify.html +1 -1
- package/docs/functions/utils.sort.html +1 -1
- package/docs/functions/utils.sortBy.html +1 -1
- package/docs/functions/utils.sortObjectByKey.html +1 -1
- package/docs/functions/utils.sortObjectByValue.html +1 -1
- package/docs/functions/utils.uncapitalize.html +1 -1
- package/docs/functions/utils.uniq.html +1 -1
- package/docs/index.html +2 -9
- package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
- package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
- package/docs/interfaces/types.BelongsToStatement.html +2 -2
- package/docs/interfaces/types.DecoratorContext.html +2 -2
- package/docs/interfaces/types.DecryptCallbacks.html +2 -2
- package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
- package/docs/interfaces/types.DreamAppOpts.html +2 -2
- package/docs/interfaces/types.DreamDbConfig.html +6 -6
- package/docs/interfaces/types.DurationObject.html +2 -2
- package/docs/interfaces/types.EncryptOptions.html +2 -2
- package/docs/interfaces/types.EncryptionLegacyKeyUsedEvent.html +4 -4
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/types.IntrospectedColumn.html +7 -7
- package/docs/interfaces/types.IntrospectedDatabase.html +2 -2
- package/docs/interfaces/types.IntrospectedEnum.html +2 -2
- package/docs/interfaces/types.IntrospectedTable.html +5 -5
- package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
- package/docs/media/CONTRIBUTING.md +128 -0
- package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/openapi.OpenapiAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiFormats.html +1 -1
- package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaCombinatorFields.html +1 -1
- package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +2 -2
- package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
- package/docs/types/openapi.OpenapiSchemaNull.html +2 -2
- package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaString.html +1 -1
- package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiTypeField.html +1 -1
- package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
- package/docs/types/types.CalendarDateDurationUnit.html +1 -1
- package/docs/types/types.CalendarDateObject.html +1 -1
- package/docs/types/types.Camelized.html +1 -1
- package/docs/types/types.ClockTimeObject.html +1 -1
- package/docs/types/types.DbConnectionType.html +1 -1
- package/docs/types/types.DbTypes.html +1 -1
- package/docs/types/types.DreamAssociationMetadata.html +1 -1
- package/docs/types/types.DreamAttributes.html +1 -1
- package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
- package/docs/types/types.DreamClassColumn.html +1 -1
- package/docs/types/types.DreamColumn.html +1 -1
- package/docs/types/types.DreamColumnNames.html +1 -1
- package/docs/types/types.DreamLogLevel.html +1 -1
- package/docs/types/types.DreamLogger.html +2 -2
- package/docs/types/types.DreamModelSerializerType.html +1 -1
- package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
- package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/types.DreamParamSafeAttributes.html +1 -1
- package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
- package/docs/types/types.DreamSerializable.html +1 -1
- package/docs/types/types.DreamSerializableArray.html +1 -1
- package/docs/types/types.DreamSerializerKey.html +1 -1
- package/docs/types/types.DreamSerializers.html +1 -1
- package/docs/types/types.DreamVirtualColumns.html +1 -1
- package/docs/types/types.DurationUnit.html +1 -1
- package/docs/types/types.EncryptAlgorithm.html +1 -1
- package/docs/types/types.HasManyStatement.html +1 -1
- package/docs/types/types.HasOneStatement.html +1 -1
- package/docs/types/types.Hyphenized.html +1 -1
- package/docs/types/types.IntrospectedValueType.html +1 -1
- package/docs/types/types.Pascalized.html +1 -1
- package/docs/types/types.PrimaryKeyType.html +1 -1
- package/docs/types/types.RoundingPrecision.html +1 -1
- package/docs/types/types.SerializerCasing.html +1 -1
- package/docs/types/types.SimpleObjectSerializerType.html +1 -1
- package/docs/types/types.Snakeified.html +1 -1
- package/docs/types/types.StrictInterface.html +1 -1
- package/docs/types/types.UpdateableAssociationProperties.html +1 -1
- package/docs/types/types.UpdateableProperties.html +1 -1
- package/docs/types/types.ValidationType.html +1 -1
- package/docs/types/types.ViewModel.html +2 -2
- package/docs/types/types.ViewModelClass.html +1 -1
- package/docs/types/types.WeekdayName.html +1 -1
- package/docs/types/types.WhereStatementForDream.html +1 -1
- package/docs/types/types.WhereStatementForDreamClass.html +1 -1
- package/docs/variables/index.DreamConst.html +1 -1
- package/docs/variables/index.ops.html +1 -1
- package/docs/variables/openapi.openapiPrimitiveTypes.html +1 -1
- package/docs/variables/openapi.openapiShorthandPrimitiveTypes.html +1 -1
- package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
- package/docs/variables/system.primaryKeyTypes.html +1 -1
- package/package.json +9 -5
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import snakeify from '../../helpers/snakeify.js';
|
|
2
2
|
import DreamSerializerBuilder from '../builders/DreamSerializerBuilder.js';
|
|
3
|
-
import ObjectSerializerBuilder from '../builders/ObjectSerializerBuilder.js';
|
|
4
3
|
import { inferSerializersFromDreamClassOrViewModelClass } from './inferSerializerFromDreamOrViewModel.js';
|
|
5
4
|
import { serializersForAssociatedClass } from './serializersForAssociatedClass.js';
|
|
6
5
|
/**
|
|
7
|
-
* The keys a flattened `rendersOne` adds to the parent's payload
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
6
|
+
* The keys a flattened `rendersOne` always adds to the parent's payload, returned as an object
|
|
7
|
+
* with each key set to `null`, ready to spread into the parent's payload (`Object.keys` of it for
|
|
8
|
+
* the key names alone): each key one of `serializers` requires. When the associated object is
|
|
9
|
+
* null, these are the keys it renders; when it is present, the rendered serializer's own keys
|
|
10
|
+
* render over them, so each of these it leaves out stays `null` and the payload always includes
|
|
11
|
+
* these keys, whichever serializer renders and whether the object is null. As a property read on
|
|
12
|
+
* an empty object is `undefined`, a null value carries no key it may omit: an attribute,
|
|
13
|
+
* delegatedAttribute or customAttribute declared with `required: false` adds no key unless another
|
|
14
|
+
* of `serializers` requires it. Every key is cased per `casing`, as the renderer cases it. There
|
|
15
|
+
* are several serializers when the association is a polymorphic BelongsTo, one for each target
|
|
16
|
+
* class, or when the associated class is an STI base, one for each child, and their required keys
|
|
17
|
+
* are unioned.
|
|
15
18
|
*
|
|
16
19
|
* Each serializer is built with `undefined` data to read its declarations, as Psychic's OpenAPI
|
|
17
20
|
* generation and `preloadFor` build it, and nothing is rendered: no attribute callback runs and
|
|
@@ -34,85 +37,58 @@ export function nullFlattenedSerializerKeys(serializers, options = {}) {
|
|
|
34
37
|
return nullRequiredKeys(walkSerializers(serializers, newWalk(options)));
|
|
35
38
|
}
|
|
36
39
|
/**
|
|
37
|
-
* The keys a flattened `customAttribute` with this `openapi` adds to the parent's payload
|
|
40
|
+
* The keys a flattened `customAttribute` with this `openapi` always adds to the parent's payload,
|
|
41
|
+
* each set to `null`: each key any shape of `openapi` requires, walked as
|
|
42
|
+
* `nullFlattenedSerializerKeys` walks a flattened `customAttribute` and cased per `casing`. When
|
|
38
43
|
* its callback returns null (or `undefined` without `required: false`), or a serializer built over
|
|
39
|
-
* null data,
|
|
40
|
-
*
|
|
44
|
+
* null data, these are the keys it renders; when it returns any other value, that value's own keys
|
|
45
|
+
* render over them, so each of these the value leaves out, or a returned plain object sets to
|
|
46
|
+
* `undefined`, stays `null`. With `required: false`, a callback that returns `undefined` adds none
|
|
47
|
+
* of them.
|
|
41
48
|
*/
|
|
42
49
|
export function nullFlattenedOpenapiKeys(openapi, options = {}) {
|
|
43
50
|
return nullRequiredKeys(walkOpenapi(openapi, newWalk(options)));
|
|
44
51
|
}
|
|
45
52
|
/**
|
|
46
|
-
* The keys a
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
53
|
+
* The keys only the other variants of a flattened `rendersOne` contribute to its payload, each set
|
|
54
|
+
* to `null`: each key one of `serializers` (every serializer the association may render with)
|
|
55
|
+
* requires that `renderedSerializer` does not declare at all. A key `renderedSerializer` declares
|
|
56
|
+
* is left out even when it declares it with `required: false` and another serializer requires it;
|
|
57
|
+
* the renderer fills that key with `null` too, since it renders every key
|
|
58
|
+
* `nullFlattenedSerializerKeys` returns beneath the rendered serializer's own keys.
|
|
50
59
|
*/
|
|
51
60
|
export function nullFlattenedSerializerKeysOfOtherVariants(serializers, renderedSerializer, options = {}) {
|
|
52
61
|
return nullKeysRequiredByOthers(walkSerializers(serializers, newWalk(options)), Object.keys(walkSerializers([renderedSerializer], newWalk(options))));
|
|
53
62
|
}
|
|
54
63
|
/**
|
|
55
|
-
* The keys a flattened `customAttribute` with this `openapi`
|
|
56
|
-
*
|
|
64
|
+
* The keys only the other variants of a flattened `customAttribute` with this `openapi` contribute
|
|
65
|
+
* to its payload, each set to `null`: each key a variant of `openapi` requires that
|
|
57
66
|
* `renderedVariant` does not declare. `renderedVariant` is any `openapi` shorthand: one member of
|
|
58
67
|
* an `anyOf` or `oneOf`, or `{ $serializer: childSerializer }` for one child of a `$serializable`
|
|
59
68
|
* ref to an STI base. A key requires its value when an object shape's `required` array lists it,
|
|
60
69
|
* whether the shape's own `properties` declare it or a member of its `allOf`, `anyOf` or `oneOf`
|
|
61
|
-
* does, or when a serializer declares it without `required: false`.
|
|
70
|
+
* does, or when a serializer declares it without `required: false`. A key `renderedVariant`
|
|
71
|
+
* declares is left out even when it is optional there and another variant requires it; the
|
|
72
|
+
* renderer fills that key with `null` too, since it renders every key `nullFlattenedOpenapiKeys`
|
|
73
|
+
* returns beneath the value's own keys.
|
|
62
74
|
*/
|
|
63
75
|
export function nullFlattenedOpenapiKeysOfOtherVariants(openapi, renderedVariant, options = {}) {
|
|
64
76
|
return nullKeysRequiredByOthers(walkOpenapi(openapi, newWalk(options)), Object.keys(walkOpenapi(renderedVariant, newWalk(options))));
|
|
65
77
|
}
|
|
66
78
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* several do, the first of them whose required keys the object all has, and when none is found,
|
|
79
|
-
* the object adds each key any variant requires. The object's top-level keys render cased per
|
|
80
|
-
* `casing`, so they are compared cased, and a key it has is never added.
|
|
79
|
+
* Lists the single shapes a value of a flattened `customAttribute` with this `openapi` may take,
|
|
80
|
+
* which a consumer can union into one description of the flattened payload: a `$serializer` ref to
|
|
81
|
+
* each serializer a `$serializable` ref resolves to (one per child for an STI base), or the members
|
|
82
|
+
* of an `anyOf` or `oneOf` (an `anyOf`'s members listed before a sibling `oneOf`'s, not paired with
|
|
83
|
+
* them), each member that itself has several shapes (a nested `anyOf` or `oneOf`, or a
|
|
84
|
+
* `$serializable` ref to an STI base) contributing those shapes in its place. An `allOf` beside
|
|
85
|
+
* the `anyOf` or `oneOf` describes every value, so each shape is that `allOf` with the shape added
|
|
86
|
+
* to its members. Anything else (a single shape, a ref with `many: true`, or a primitive) has no
|
|
87
|
+
* variants and returns an empty list. Each shape may be passed back as the `renderedVariant` of
|
|
88
|
+
* `nullFlattenedOpenapiKeysOfOtherVariants`. The renderer does not read a value's shape from this
|
|
89
|
+
* list: whatever shape the value takes, it renders every key `nullFlattenedOpenapiKeys` returns.
|
|
81
90
|
*/
|
|
82
|
-
export function
|
|
83
|
-
if (value instanceof DreamSerializerBuilder || value instanceof ObjectSerializerBuilder)
|
|
84
|
-
return nullKeysRequiredByOthers(walkOpenapi(openapi, newWalk(options)), Object.keys(walkSerializerBuilder(value, newWalk(options))));
|
|
85
|
-
if (typeof value !== 'object' || value === null)
|
|
86
|
-
return {};
|
|
87
|
-
const { casing } = newWalk(options);
|
|
88
|
-
const valueKeys = Object.keys(value).map(key => setCase(key, casing));
|
|
89
|
-
const variants = openapiVariants(openapi);
|
|
90
|
-
const candidates = variants
|
|
91
|
-
.map(variant => ({ variant, requirements: walkOpenapi(variant, newWalk(options)) }))
|
|
92
|
-
.filter(({ requirements }) => valueKeys.every(key => Object.prototype.hasOwnProperty.call(requirements, key)));
|
|
93
|
-
const renderedVariant = variants.length < 2
|
|
94
|
-
? openapi
|
|
95
|
-
: candidates.length === 1
|
|
96
|
-
? candidates[0].variant
|
|
97
|
-
: candidates.find(({ requirements }) => Object.keys(requirements).every(key => !requirements[key] || valueKeys.includes(key)))?.variant;
|
|
98
|
-
const requiredKeys = renderedVariant
|
|
99
|
-
? {
|
|
100
|
-
...nullFlattenedOpenapiKeysOfOtherVariants(openapi, renderedVariant, options),
|
|
101
|
-
...nullFlattenedOpenapiKeys(renderedVariant, options),
|
|
102
|
-
}
|
|
103
|
-
: nullFlattenedOpenapiKeys(openapi, options);
|
|
104
|
-
valueKeys.forEach(key => delete requiredKeys[key]);
|
|
105
|
-
return requiredKeys;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* The shapes a value of `openapi` may take, each one a variant a plain object may render: a
|
|
109
|
-
* `$serializer` ref to each serializer a `$serializable` ref resolves to, or the members of an
|
|
110
|
-
* `anyOf` or `oneOf`, each member that itself has several variants (a nested `anyOf` or `oneOf`,
|
|
111
|
-
* or a `$serializable` ref to an STI base) contributing those variants in its place. An `allOf`
|
|
112
|
-
* beside the `anyOf` or `oneOf` describes every value, so each variant is that `allOf` with the
|
|
113
|
-
* variant added to its members.
|
|
114
|
-
*/
|
|
115
|
-
function openapiVariants(openapi) {
|
|
91
|
+
export function flattenedOpenapiVariants(openapi) {
|
|
116
92
|
if (typeof openapi !== 'object' || Array.isArray(openapi))
|
|
117
93
|
return [];
|
|
118
94
|
if ('$serializable' in openapi)
|
|
@@ -123,7 +99,7 @@ function openapiVariants(openapi) {
|
|
|
123
99
|
...(('anyOf' in openapi && openapi.anyOf) || []),
|
|
124
100
|
...(('oneOf' in openapi && openapi.oneOf) || []),
|
|
125
101
|
].flatMap(member => {
|
|
126
|
-
const memberVariants =
|
|
102
|
+
const memberVariants = flattenedOpenapiVariants(member);
|
|
127
103
|
return memberVariants.length > 1 ? memberVariants : [member];
|
|
128
104
|
});
|
|
129
105
|
const sharedMembers = ('allOf' in openapi && openapi.allOf) || [];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import uniq from '../../helpers/uniq.js';
|
|
2
2
|
import { inferSerializersFromDreamClassOrViewModelClass } from './inferSerializerFromDreamOrViewModel.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Used by every flattened rendersOne render, whether the associated object is present or null: it
|
|
5
|
+
* lists every serializer the association may render with, whose required keys the renderer renders
|
|
6
|
+
* as null in the parent's payload, beneath the present object's own keys or alone when the object
|
|
7
|
+
* is null, where there is no object to resolve a serializer from.
|
|
7
8
|
*
|
|
8
9
|
* Resolves, in order, to the `serializer` option, the serializers of the `dreamClass` or
|
|
9
10
|
* `viewModelClass` option, or the serializers of each class `parentClass` declares the association
|
|
@@ -19,7 +19,7 @@ import standardizeFullyQualifiedModelName from '../helpers/standardizeFullyQuali
|
|
|
19
19
|
import expandStiClasses from '../helpers/sti/expandStiClasses.js';
|
|
20
20
|
import inferSerializerFromDreamOrViewModel, { inferSerializersFromDreamClassOrViewModelClass, } from '../serializer/helpers/inferSerializerFromDreamOrViewModel.js';
|
|
21
21
|
import isDreamSerializer from '../serializer/helpers/isDreamSerializer.js';
|
|
22
|
-
import { nullFlattenedOpenapiKeys, nullFlattenedOpenapiKeysOfOtherVariants, nullFlattenedSerializerKeys, nullFlattenedSerializerKeysOfOtherVariants, } from '../serializer/helpers/nullFlattenedSerializerKeys.js';
|
|
22
|
+
import { flattenedOpenapiVariants, nullFlattenedOpenapiKeys, nullFlattenedOpenapiKeysOfOtherVariants, nullFlattenedSerializerKeys, nullFlattenedSerializerKeysOfOtherVariants, } from '../serializer/helpers/nullFlattenedSerializerKeys.js';
|
|
23
23
|
import serializerNameFromFullyQualifiedModelName from '../serializer/helpers/serializerNameFromFullyQualifiedModelName.js';
|
|
24
24
|
import BaseClockTime from '../utils/datetime/BaseClockTime.js';
|
|
25
25
|
import CalendarDate from '../utils/datetime/CalendarDate.js';
|
|
@@ -108,6 +108,7 @@ export default class DreamApp {
|
|
|
108
108
|
nullFlattenedSerializerKeysOfOtherVariants,
|
|
109
109
|
nullFlattenedOpenapiKeys,
|
|
110
110
|
nullFlattenedOpenapiKeysOfOtherVariants,
|
|
111
|
+
flattenedOpenapiVariants,
|
|
111
112
|
serializerNameFromFullyQualifiedModelName,
|
|
112
113
|
autogeneratedFileDisclaimer,
|
|
113
114
|
};
|
|
@@ -272,6 +273,28 @@ export default class DreamApp {
|
|
|
272
273
|
get importExtension() {
|
|
273
274
|
return this._importExtension;
|
|
274
275
|
}
|
|
276
|
+
_importAliasPrefix = '@';
|
|
277
|
+
/**
|
|
278
|
+
* The prefix of the import aliases the CLI generators write: the `@` in
|
|
279
|
+
* `@models/User.js`, `@serializers/UserSerializer.js` and
|
|
280
|
+
* `@spec/factories/UserFactory.js`. Set with
|
|
281
|
+
* `dreamApp.set('importAliasPrefix', '#')` to have them write
|
|
282
|
+
* `#models/User.js` and so on, which Node resolves as subpath imports
|
|
283
|
+
* declared under `imports` in the app's package.json.
|
|
284
|
+
*
|
|
285
|
+
* Defaults to `@`. The default becomes `#` in Dream 3; an app that wants
|
|
286
|
+
* to keep `@` should set it explicitly with
|
|
287
|
+
* `dreamApp.set('importAliasPrefix', '@')`.
|
|
288
|
+
*
|
|
289
|
+
* Psychic's resource controller-spec generator still writes its
|
|
290
|
+
* `@spec/unit/helpers/authentication.js` import with a literal `@` until
|
|
291
|
+
* Psychic reads this setting (planned for 3.17.0), so a Psychic app should
|
|
292
|
+
* keep its `@spec` alias, or wait for that release, before switching to
|
|
293
|
+
* `#` only.
|
|
294
|
+
*/
|
|
295
|
+
get importAliasPrefix() {
|
|
296
|
+
return this._importAliasPrefix;
|
|
297
|
+
}
|
|
275
298
|
/**
|
|
276
299
|
* if set to true, it will bypass deprecation checks that run
|
|
277
300
|
* during the sync hook. Defaults to false, we only recommend
|
|
@@ -482,6 +505,9 @@ export default class DreamApp {
|
|
|
482
505
|
case 'importExtension':
|
|
483
506
|
this._importExtension = options;
|
|
484
507
|
break;
|
|
508
|
+
case 'importAliasPrefix':
|
|
509
|
+
this._importAliasPrefix = options;
|
|
510
|
+
break;
|
|
485
511
|
case 'logger':
|
|
486
512
|
this._logger = options;
|
|
487
513
|
break;
|
|
@@ -608,3 +634,7 @@ export const DreamAppAllowedPackageManagersEnumValues = ['pnpm', 'yarn', 'npm',
|
|
|
608
634
|
// to style import suffixes. When integrating with other apps, this
|
|
609
635
|
// suffix style can change, and may need to be configured.
|
|
610
636
|
export const GeneratorImportStyles = ['.js', '.ts', 'none'];
|
|
637
|
+
// GeneratorImportAliasPrefixes are used by CLI generators to determine the
|
|
638
|
+
// prefix of the import aliases they write (`@models/User.js` vs
|
|
639
|
+
// `#models/User.js`). The default is `@`; it becomes `#` in Dream 3.
|
|
640
|
+
export const GeneratorImportAliasPrefixes = ['@', '#'];
|
|
@@ -28,7 +28,7 @@ function areEqualOrUndefined(a, b) {
|
|
|
28
28
|
if (typeof a === 'boolean')
|
|
29
29
|
return a === b;
|
|
30
30
|
if (typeof a === 'number')
|
|
31
|
-
return a === b;
|
|
31
|
+
return a === b || (Number.isNaN(a) && Number.isNaN(b));
|
|
32
32
|
if (typeof a === 'string')
|
|
33
33
|
return a === b;
|
|
34
34
|
if (a instanceof DateTime)
|
|
@@ -40,7 +40,7 @@ function areEqualOrUndefined(a, b) {
|
|
|
40
40
|
if (a instanceof ClockTimeTz)
|
|
41
41
|
return b instanceof ClockTimeTz && a.equals(b);
|
|
42
42
|
if (Array.isArray(a))
|
|
43
|
-
return Array.isArray(b) && a.length === b.length &&
|
|
43
|
+
return Array.isArray(b) && a.length === b.length && a.every((value, index) => areEqual(value, b[index]));
|
|
44
44
|
if (a instanceof Dream)
|
|
45
45
|
return a.equals(b);
|
|
46
46
|
return undefined;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import DreamApp from '../../dream-app/index.js';
|
|
1
2
|
import addImportSuffix from '../cli/addImportSuffix.js';
|
|
2
3
|
import pascalize from '../pascalize.js';
|
|
3
4
|
export default function absoluteDreamPath(destinationDreamPathType, fullyQualifiedDestinationModelName) {
|
|
@@ -13,13 +14,14 @@ export default function absoluteDreamPath(destinationDreamPathType, fullyQualifi
|
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
function rootPath(destinationDreamPathType) {
|
|
17
|
+
const prefix = DreamApp.getOrFail().importAliasPrefix;
|
|
16
18
|
switch (destinationDreamPathType) {
|
|
17
19
|
case 'models':
|
|
18
|
-
return
|
|
20
|
+
return `${prefix}models/`;
|
|
19
21
|
case 'serializers':
|
|
20
|
-
return
|
|
22
|
+
return `${prefix}serializers/`;
|
|
21
23
|
case 'factories':
|
|
22
|
-
return
|
|
24
|
+
return `${prefix}spec/factories/`;
|
|
23
25
|
default: {
|
|
24
26
|
// protection so that if a new DreamPaths is ever added, this will throw a type error at build time
|
|
25
27
|
const _never = destinationDreamPathType;
|
|
@@ -10,11 +10,11 @@ import DreamSerializerBuilder from './builders/DreamSerializerBuilder.js';
|
|
|
10
10
|
*
|
|
11
11
|
* A serializer must not read its data while being built: what it declares may not
|
|
12
12
|
* depend on its data. Dream and Psychic build it without data to read its shape (the
|
|
13
|
-
* OpenAPI schema, and the
|
|
14
|
-
* `
|
|
15
|
-
* built throws when a flattened association or
|
|
16
|
-
* rendered. Read the data inside a `customAttribute`
|
|
17
|
-
* the serializer renders, not while it is built.
|
|
13
|
+
* OpenAPI schema, and the keys a flattened association or `customAttribute` that uses
|
|
14
|
+
* it renders as `null` where its value does not supply them), so a serializer that
|
|
15
|
+
* reads its data while being built throws when a flattened association or
|
|
16
|
+
* `customAttribute` that uses it is rendered. Read the data inside a `customAttribute`
|
|
17
|
+
* callback, which runs only when the serializer renders, not while it is built.
|
|
18
18
|
*
|
|
19
19
|
* @param dreamClass - The Dream model class the serializer renders
|
|
20
20
|
* @param data - The Dream instance to render
|
|
@@ -10,11 +10,11 @@ import ObjectSerializerBuilder from './builders/ObjectSerializerBuilder.js';
|
|
|
10
10
|
*
|
|
11
11
|
* A serializer must not read its data while being built: what it declares may not
|
|
12
12
|
* depend on its data. Dream and Psychic build it without data to read its shape (the
|
|
13
|
-
* OpenAPI schema, and the
|
|
14
|
-
* `
|
|
15
|
-
* built throws when a flattened association or
|
|
16
|
-
* rendered. Read the data inside a `customAttribute`
|
|
17
|
-
* the serializer renders, not while it is built.
|
|
13
|
+
* OpenAPI schema, and the keys a flattened association or `customAttribute` that uses
|
|
14
|
+
* it renders as `null` where its value does not supply them), so a serializer that
|
|
15
|
+
* reads its data while being built throws when a flattened association or
|
|
16
|
+
* `customAttribute` that uses it is rendered. Read the data inside a `customAttribute`
|
|
17
|
+
* callback, which runs only when the serializer renders, not while it is built.
|
|
18
18
|
*
|
|
19
19
|
* @param data - The object to render
|
|
20
20
|
* @param passthroughData - Data available to this serializer and passed down to the serializers
|
|
@@ -9,7 +9,7 @@ import { DateTime } from '../utils/datetime/DateTime.js';
|
|
|
9
9
|
import DreamSerializerBuilder from './builders/DreamSerializerBuilder.js';
|
|
10
10
|
import ObjectSerializerBuilder from './builders/ObjectSerializerBuilder.js';
|
|
11
11
|
import inferSerializerFromDreamOrViewModel from './helpers/inferSerializerFromDreamOrViewModel.js';
|
|
12
|
-
import { nullFlattenedOpenapiKeys,
|
|
12
|
+
import { nullFlattenedOpenapiKeys, nullFlattenedSerializerKeys, } from './helpers/nullFlattenedSerializerKeys.js';
|
|
13
13
|
import { serializersForAssociatedClass } from './helpers/serializersForAssociatedClass.js';
|
|
14
14
|
export default class SerializerRenderer {
|
|
15
15
|
serializerBuilder;
|
|
@@ -79,29 +79,27 @@ export default class SerializerRenderer {
|
|
|
79
79
|
return accumulator;
|
|
80
80
|
if (attribute.options.flatten) {
|
|
81
81
|
const flattenOptions = { casing: this.renderOpts.casing, passthroughData };
|
|
82
|
-
// a flattened customAttribute's keys are the parent's own keys, cased like them
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
// renders
|
|
87
|
-
// declare, and each key the rendered one requires that a returned plain object leaves out
|
|
82
|
+
// a flattened customAttribute's keys are the parent's own keys, cased like them, and
|
|
83
|
+
// always include each key any shape of its openapi requires: a callback that returns
|
|
84
|
+
// null or undefined, or a serializer built over null or undefined data (which renders
|
|
85
|
+
// null), renders each of them as null, as a null flattened rendersOne does, and a
|
|
86
|
+
// present value renders its own keys over them, so a required key it leaves out is null
|
|
88
87
|
const valueIsSerializerBuilder = value instanceof DreamSerializerBuilder || value instanceof ObjectSerializerBuilder;
|
|
89
88
|
const valueRendersNull = value === null ||
|
|
90
89
|
value === undefined ||
|
|
91
90
|
(valueIsSerializerBuilder &&
|
|
92
91
|
(value['data'] ?? null) === null);
|
|
92
|
+
const nullRequiredKeys = nullFlattenedOpenapiKeys(attribute.options.openapi, flattenOptions);
|
|
93
93
|
if (valueRendersNull)
|
|
94
|
-
return {
|
|
95
|
-
...accumulator,
|
|
96
|
-
...nullFlattenedOpenapiKeys(attribute.options.openapi, flattenOptions),
|
|
97
|
-
};
|
|
94
|
+
return { ...accumulator, ...nullRequiredKeys };
|
|
98
95
|
const renderedValue = applyRenderingOptionsToAttribute(null, value, attribute.name, {}, this.passthroughData, this.renderOpts);
|
|
99
96
|
return {
|
|
100
97
|
...accumulator,
|
|
101
|
-
...
|
|
98
|
+
...nullRequiredKeys,
|
|
102
99
|
// a returned serializer renders its keys in the render's casing; a returned plain
|
|
103
|
-
// object's top-level keys are cased here, its nested values left as returned
|
|
104
|
-
|
|
100
|
+
// object's top-level keys are cased here, its nested values left as returned, and a
|
|
101
|
+
// key it sets to undefined is skipped, so a required key renders null beneath it
|
|
102
|
+
...(valueIsSerializerBuilder ? renderedValue : this.setCaseOfDefinedKeys(renderedValue)),
|
|
105
103
|
};
|
|
106
104
|
}
|
|
107
105
|
else {
|
|
@@ -118,12 +116,6 @@ export default class SerializerRenderer {
|
|
|
118
116
|
case 'rendersOne': {
|
|
119
117
|
const outputAttributeName = this.setCase(attribute.options.as ?? attribute.name);
|
|
120
118
|
const associatedObject = data[attribute.name];
|
|
121
|
-
if (!associatedObject && attribute.options.flatten) {
|
|
122
|
-
return {
|
|
123
|
-
...accumulator,
|
|
124
|
-
...nullFlattenedSerializerKeys(serializersForAssociatedClass(data instanceof Dream ? data.constructor : null, attribute.name, attribute.options), { casing: this.renderOpts.casing, passthroughData }),
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
119
|
const serializer = associatedObject
|
|
128
120
|
? serializerForAssociatedObject(associatedObject, attribute.options, renderTimeResolutionContext(attribute.options, 'rendersOne', attribute.name))
|
|
129
121
|
: null;
|
|
@@ -134,12 +126,11 @@ export default class SerializerRenderer {
|
|
|
134
126
|
if (attribute.options.flatten) {
|
|
135
127
|
return {
|
|
136
128
|
...accumulator,
|
|
137
|
-
//
|
|
138
|
-
// (each STI child, each polymorphic target)
|
|
139
|
-
// rendered
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
: {}),
|
|
129
|
+
// a flattened rendersOne always renders each key any serializer the association may
|
|
130
|
+
// render with (each STI child, each polymorphic target) requires: as null when the
|
|
131
|
+
// associated object is null, and beneath the rendered serializer's own keys when it is
|
|
132
|
+
// present, so a required key the rendered serializer leaves out renders as null
|
|
133
|
+
...nullFlattenedSerializerKeys(serializersForAssociatedClass(data instanceof Dream ? data.constructor : null, attribute.name, attribute.options), { casing: this.renderOpts.casing, passthroughData }),
|
|
143
134
|
// passthrough data must be passed both into the serializer and render
|
|
144
135
|
// because, if the serializer does accept passthrough data, then passing it in is how
|
|
145
136
|
// it gets into the serializer, but if it does not accept passthrough data, and therefore
|
|
@@ -204,11 +195,13 @@ export default class SerializerRenderer {
|
|
|
204
195
|
}, renderedAttributes);
|
|
205
196
|
return renderedAttributes;
|
|
206
197
|
}
|
|
207
|
-
|
|
198
|
+
setCaseOfDefinedKeys(value) {
|
|
208
199
|
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
209
200
|
return value;
|
|
210
201
|
return Object.keys(value).reduce((casedValue, key) => {
|
|
211
|
-
|
|
202
|
+
const keyValue = value[key];
|
|
203
|
+
if (keyValue !== undefined)
|
|
204
|
+
casedValue[this.setCase(key)] = keyValue;
|
|
212
205
|
return casedValue;
|
|
213
206
|
}, {});
|
|
214
207
|
}
|
|
@@ -110,28 +110,29 @@ export default class DreamSerializerBuilder {
|
|
|
110
110
|
* - `openapi` - (required) OpenAPI schema definition for the computed value
|
|
111
111
|
* - `flatten` - When `true`, spreads the returned object's properties directly into the
|
|
112
112
|
* parent serialized output instead of nesting them under `name`. The `openapi` option
|
|
113
|
-
* then describes the whole returned object, not each property
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
113
|
+
* then describes the whole returned object, not each property: either an object schema
|
|
114
|
+
* with full property bodies (`type: 'object'`, `properties`, and `required` listing the
|
|
115
|
+
* keys that are always present), or `{ $serializer: SomeSerializer }` when the callback
|
|
116
|
+
* returns what that serializer renders. A serializer ref with `many: true` does not
|
|
117
|
+
* type-check here, since a list has no properties to spread. Whatever the callback
|
|
118
|
+
* returns, each key any shape of the `openapi` requires renders, as `null` wherever the
|
|
119
|
+
* value does not supply it (a returned plain object's key set to `undefined` does not
|
|
120
|
+
* supply it): a key an object shape lists in its `required` array, a key a `$serializer` or
|
|
121
|
+
* `$serializable` ref's serializer declares without `required: false` (for an STI base,
|
|
122
|
+
* any child's serializer), and each such key of any `allOf`, `anyOf` or `oneOf` member. So
|
|
123
|
+
* a `null` return, a serializer built over `null` or `undefined` data, or an `undefined`
|
|
124
|
+
* return without `required: false` renders each of them as `null`, and a present value
|
|
125
|
+
* renders its own keys over them, so a key another shape requires renders as `null` even
|
|
126
|
+
* when the value's own shape leaves it optional; the payload always includes the same
|
|
127
|
+
* keys whichever shape the value takes and whether it is null. An optional key no shape
|
|
128
|
+
* requires stays absent unless the value supplies it, and an `undefined` return with
|
|
129
|
+
* `required: false` adds no keys.
|
|
129
130
|
* Every key it adds follows the render's casing like the parent's own keys: a returned
|
|
130
131
|
* plain object's top-level keys and the `openapi`'s `properties` keys are cased (so
|
|
131
132
|
* `casing: 'snake'` renders `phoneNumber` as `phone_number`, present or `null`), while
|
|
132
|
-
* nested values render as returned. Attributes render in declaration order, so a key the
|
|
133
|
-
* another attribute takes the value of whichever is declared
|
|
134
|
-
* that value must match both
|
|
133
|
+
* nested values render as returned. Attributes render in declaration order, so a key the
|
|
134
|
+
* returned object shares with another attribute takes the value of whichever is declared
|
|
135
|
+
* later, and that value must match both the attribute's declaration and the `openapi`'s
|
|
135
136
|
* - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
|
|
136
137
|
* when omitted, attributes are required by default
|
|
137
138
|
* @returns The serializer builder for method chaining
|
|
@@ -181,23 +182,29 @@ export default class DreamSerializerBuilder {
|
|
|
181
182
|
* declaration order, so when the parent and the association share a key (e.g., `id`),
|
|
182
183
|
* whichever is declared later wins: the association's value replaces an attribute declared
|
|
183
184
|
* before the `rendersOne`, and an attribute declared after it replaces the association's.
|
|
184
|
-
*
|
|
185
|
-
* attribute, delegatedAttribute or customAttribute declared without
|
|
186
|
-
* every non-flattened `rendersOne` and `rendersMany` (for a
|
|
187
|
-
* key the serializer of any of its target classes requires,
|
|
188
|
-
* STI base, each key the serializer of any of its STI children
|
|
189
|
-
* (so an `id` declared before the `rendersOne` becomes `null`
|
|
190
|
-
*
|
|
185
|
+
* Each key its serializer requires always renders, as `null` wherever the association
|
|
186
|
+
* does not supply it: an attribute, delegatedAttribute or customAttribute declared without
|
|
187
|
+
* `required: false`, and every non-flattened `rendersOne` and `rendersMany` (for a
|
|
188
|
+
* polymorphic `BelongsTo`, each key the serializer of any of its target classes requires,
|
|
189
|
+
* and for an association to an STI base, each key the serializer of any of its STI children
|
|
190
|
+
* requires), in the same order (so an `id` declared before the `rendersOne` becomes `null`
|
|
191
|
+
* when the association is `null`). A flattened `customAttribute` in that serializer adds the
|
|
191
192
|
* keys its `openapi` requires: a key an object shape lists in its `required` array, a key a
|
|
192
193
|
* `$serializer` or `$serializable` ref's serializer declares without `required: false`, and
|
|
193
194
|
* each such key of an `allOf`, `anyOf` or `oneOf` member; a ref with `many: true` adds none,
|
|
194
|
-
* and a flattened `customAttribute` declared with `required: false` adds none.
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
195
|
+
* and a flattened `customAttribute` declared with `required: false` adds none. When the
|
|
196
|
+
* association is `null`, each of these keys renders as `null` and nothing in its serializer
|
|
197
|
+
* is rendered, so its custom attribute callbacks do not run. When it is present, the held
|
|
198
|
+
* object's serializer renders its own keys over them, so a key another STI child's or
|
|
199
|
+
* target's serializer requires renders as `null` where the held one's serializer does not
|
|
200
|
+
* render it, including a key that serializer declares with `required: false`; the payload
|
|
201
|
+
* always includes the same keys whichever is held and, for an association or a property
|
|
202
|
+
* given a `serializer` or `viewModelClass` option, whether it is `null` (a `null` property
|
|
203
|
+
* that is not an association and has neither option renders none of these keys, since no
|
|
204
|
+
* serializer is known for it). A key declared with `required: false` that no serializer
|
|
205
|
+
* requires stays absent unless it renders. The association's OpenAPI schema describes the
|
|
206
|
+
* parent's payload too, so a shared key's value must match both the parent's declaration
|
|
207
|
+
* and the association's, whichever declaration wins
|
|
201
208
|
* - `optional` - When `true`, allows the association to be null/missing without causing
|
|
202
209
|
* an `OpenapiResponseValidationFailure` during Psychic controller unit specs. By default,
|
|
203
210
|
* `rendersOne` expects the association to be present (mirroring the `optional` option on
|