Skip to content

Commit

Permalink
Merge branch 'feature-DATAAPI-33_allow-default-configuration-for-apis…
Browse files Browse the repository at this point in the history
…' into release-3.6.0
  • Loading branch information
DominicWatson committed Oct 24, 2024
2 parents 4ce1316 + a36068b commit 3ca32ff
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 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.13

* [#86](https://github.com/pixl8/preside-ext-data-api/issues/86) Fix issue with id field appearing as required for POST requests

## v3.5.12

* Ability to have deleted record detail in queue data
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ settings.rest.apis[ "/myGroovyApi/v1" ] = {
, description = "REST API to expose data with an alternate structure"
, dataApiNamespace = "myGroovyApi"
, dataApiQueueEnabled = true
, dataApiDefaults = { allowIdInsert=true, verbs="GET" }
, dataApiQueues = {
default = { pageSize=100, atomicChanges=true }
}
Expand Down
1 change: 1 addition & 0 deletions config/Config.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ component {
, description = "Generic Preside REST API for external systems to interact with Preside data"
, configHandler = "dataApiManager"
, dataApiQueues = { default={ pageSize=1, name="", atomicChanges=false } }
, dataApiDefaults = { allowIdInsert=false }
};
settings.rest.apis[ "/data/v1/docs" ] = {
description = "Documentation for REST APIs (no authentication required)"
Expand Down
6 changes: 5 additions & 1 deletion interceptors/DataApiInterceptors.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ component extends="coldbox.system.Interceptor" {
var dataApiNamespace = "";
var dataApiDocs = false;
var dataApiQueues = {};
var dataApiDefaults = {};
var base = [];

for( var apiRoute in apiSettings ) {
Expand All @@ -29,13 +30,15 @@ component extends="coldbox.system.Interceptor" {
dataApiDocs = isTrue( apiSettings[ apiRoute ].dataApiDocs ?: "" );
dataApiQueueEnabled = isTrue( apiSettings[ apiRoute ].dataApiQueueEnabled ?: !dataApiDocs );
dataApiQueues = apiSettings[ apiRoute ].dataApiQueues ?: {};
dataApiDefaults = apiSettings[ apiRoute ].dataApiDefaults ?: {};

dataApiConfigurationService.addDataApiRoute(
dataApiRoute = apiRoute
, dataApiNamespace = dataApiNamespace
, dataApiDocs = dataApiDocs
, dataApiQueueEnabled = dataApiQueueEnabled
, dataApiQueues = dataApiQueues
, dataApiDefaults = dataApiDefaults
);

base = duplicate( dataApiDocs ? apis[ "/data/v1/docs" ] : apis[ "/data/v1" ] );
Expand All @@ -52,7 +55,8 @@ component extends="coldbox.system.Interceptor" {
, dataApiNamespace = ""
, dataApiDocs = false
, dataApiQueueEnabled = IsTrue( apiSettings[ "/data/v1" ].dataApiQueueEnabled ?: true )
, dataApiQueues = apiSettings[ "/data/v1" ].dataApiQueues ?: {}
, dataApiQueues = apiSettings[ "/data/v1" ].dataApiQueues ?: {}
, dataApiDefaults = apiSettings[ "/data/v1" ].dataApiDefaults ?: {}
);
dataApiConfigurationService.addDataApiRoute(
dataApiRoute = "/data/v1/docs"
Expand Down
12 changes: 10 additions & 2 deletions services/DataApiConfigurationService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,12 @@ component {
if ( _isTrue( isEnabled ) ) {
var namespace = _getNamespaceWithSeparator( args.namespace );
var entityName = getObjectEntity( objectName, args.namespace );
var supportedVerbs = poService.getObjectAttribute( objectName, "dataApiVerbs#namespace#", "" );
var supportedVerbs = poService.getObjectAttribute( objectName, "dataApiVerbs#namespace#", getDefaultConfigForApiNamespace( "verbs", namespace ) );
var selectFields = poService.getObjectAttribute( objectName, "dataApiFields#namespace#", "" );
var upsertFields = poService.getObjectAttribute( objectName, "dataApiUpsertFields#namespace#", "" );
var excludeFields = _getExcludedFields( objectName, namespace );
var upsertExcludeFields = _getExcludedFields( objectName, namespace, "upsert" );
var allowIdInsert = poService.getObjectAttribute( objectName, "dataApiAllowIdInsert#namespace#", "" );
var allowIdInsert = poService.getObjectAttribute( objectName, "dataApiAllowIdInsert#namespace#", getDefaultConfigForApiNamespace( "allowIdInsert", namespace ) );
var allowQueue = poService.getObjectAttribute( objectName, "dataApiQueueEnabled#namespace#", true );
var queueName = poService.getObjectAttribute( objectName, "dataApiQueue#namespace#", "default" );
var category = poService.getObjectAttribute( objectName, "dataApiCategory#namespace#", "" );
Expand Down Expand Up @@ -382,13 +382,15 @@ component {
, required boolean dataApiDocs
, required boolean dataApiQueueEnabled
, required struct dataApiQueues
, struct dataApiDefaults = {}
) {
variables._dataApiRoutes = variables._dataApiRoutes ?: {};
variables._dataApiRoutes[ arguments.dataApiRoute ] = {
dataApiNamespace = arguments.dataApiNamespace
, dataApiDocs = arguments.dataApiDocs
, dataApiQueueEnabled = arguments.dataApiQueueEnabled
, dataApiQueues = arguments.dataApiQueues
, dataApiDefaults = arguments.dataApiDefaults
};
_addNamespace( arguments.dataApiNamespace );
}
Expand Down Expand Up @@ -597,6 +599,12 @@ component {
};
}

public function getDefaultConfigForApiNamespace( required string key, string namespace=_getDataApiNamespace(), any defaultValue="" ) {
var route = getRouteForNamespace( arguments.namespace );

return route.dataApiDefaults[ arguments.key ] ?: arguments.defaultValue;
}

// PRIVATE HELPERS
private any function _simpleLocalCache( required string cacheKey, required any generator ) {
if ( !_localCache.keyExists( arguments.cacheKey ) ) {
Expand Down
2 changes: 1 addition & 1 deletion services/DataApiSpecService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ component {
private struct function _getEntitySchema( required string entityName, boolean forSelect=true, boolean forceIdField=false ) {
var schema = { required=[], properties=StructNew( "linked" ) };
var confService = _getConfigService();
var fields = arguments.forSelect ? confService.getSelectFields( arguments.entityName ) : confService.getUpsertFields( arguments.entityName );
var fields = Duplicate( arguments.forSelect ? confService.getSelectFields( arguments.entityName ) : confService.getUpsertFields( arguments.entityName ) );
var fieldSettings = confService.getFieldSettings( arguments.entityName );
var objectName = confService.getEntityObject( arguments.entityName );
var props = $getPresideObjectService().getObjectProperties( objectName );
Expand Down

0 comments on commit 3ca32ff

Please sign in to comment.