Skip to content

Commit

Permalink
Merge branch 'hotfix-3.5.10' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicWatson committed Apr 16, 2024
2 parents 1e27868 + dcb4abe commit b171994
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v3.5.10

* Add flag option to allow renderers to process empty values (fix for certain implementations with changes made in 3.5.5)

## v3.5.9

* [DATAAPI-27](https://projects.pixl8.london/browse/DATAAPI-27) - Function count does not exist in the object
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Object properties support the following _optional_ annotations:
* `dataApiFormat`: For the documentation. The format for the property, e.g. 'Email address'.
* `dataApiEnabled`: Whether or not this property should be included in the API
* `dataApiUpsertEnabled`: Whether or not this property should be included in the POST/PUT operations.
* `dataApiRenderEmptyValues`: Whether to force always calling a custom render when the value being processed is empty or null

## Custom renderers

Expand All @@ -72,6 +73,8 @@ If you specify a non-default renderer for an object property, it will be rendere
property name="my_prop" dataApiAlias="myProp" dataApiRenderer="myCustomRenderer";
```

By default for performance reasons, empty/null values are skipped, to force always calling the custom renderer, set the following property `dataApiRenderEmptyValues=true`.

To implement this, you will need a corresponding _viewlet_ at `renderers.content.myCustomRenderer.dataapi` **or** `renderers.content.myCustomRenderer.default` (a renderer _context_ of `dataapi` will be used and the system will fallback to the default renderer if that context is not implemented).

For example:
Expand Down
15 changes: 9 additions & 6 deletions services/DataApiConfigurationService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,16 @@ component {

for( var field in props ) {
fieldSettings[ field ] = {
alias = props[ field ][ "dataApiAlias#namespace#" ] ?: field
, renderer = props[ field ][ "dataApiRenderer#namespace#" ] ?: _getDefaultRendererForField( props[ field ] ?: {} )
, type = props[ field ][ "dataApiType#namespace#" ] ?: ""
, format = props[ field ][ "dataApiFormat#namespace#" ] ?: ""
, derivative = props[ field ][ "dataApiDerivative#namespace#" ] ?: ""
, name = field
alias = props[ field ][ "dataApiAlias#namespace#" ] ?: field
, renderer = props[ field ][ "dataApiRenderer#namespace#" ] ?: _getDefaultRendererForField( props[ field ] ?: {} )
, renderEmptyValues = props[ field ][ "dataApiRenderEmptyValues#namespace#" ] ?: false
, type = props[ field ][ "dataApiType#namespace#" ] ?: ""
, format = props[ field ][ "dataApiFormat#namespace#" ] ?: ""
, derivative = props[ field ][ "dataApiDerivative#namespace#" ] ?: ""
, name = field
};

fieldSettings[ field ].renderEmptyValues = IsBoolean( fieldSettings[ field ].renderEmptyValues ) && fieldSettings[ field ].renderEmptyValues;
}

return fieldSettings;
Expand Down
2 changes: 1 addition & 1 deletion services/DataApiService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ component {
return $isFeatureEnabled( "dataApiUseNullForStrings" ) ? NullValue() : "";
}

if ( !Len( arguments.value ?: "" ) ) {
if ( !Len( arguments.value ?: "" ) && !arguments.fieldSettings.renderEmptyValues ) {
return $isFeatureEnabled( "dataApiUseNullForStrings" ) ? NullValue() : "";
}

Expand Down

0 comments on commit b171994

Please sign in to comment.