colymba/silverstripe-restfulapi

Config::type_mismatch when authentication_policy is an array

Closed this issue · 3 comments

When setting authentication_policy to an array of methods a Config::type_mismatch() error is thrown due to the initial value being false.

@dylanitorium are you setting your config via YML or PHP? Can you also confirm the framework version you are using?

Would be great if you could post your config and the PHP error dump.

Hey yeah, sorry I should have done that in the first place.
I'm setting the config via YML and using the version is 3.5.

Error dump:

[User Error] Uncaught UnexpectedValueException: Type mismatch in configuration. All values for a particular property must contain the same type (or no value at all).
GET /api/regionalOffice
Line 169 in /home/ubuntu/projects/moeforms/framework/core/Config.php
Source
160 		return self::ISNT_ARRAY;
161 	}
162 
163 	/**
164 	 * What to do if there's a type mismatch.
165 	 *
166 	 * @throws UnexpectedValueException
167 	 */
168 	protected static function type_mismatch() {
169 		throw new UnexpectedValueException('Type mismatch in configuration. All values for a particular property must'
170 			. ' contain the same type (or no value at all).');
171 	}
172 
173 	/**
174 	 * @todo If we can, replace next static & static methods with DI once that's in
175 	 */
Trace
Config::type_mismatch() 
Config.php:433
Config::merge_low_into_high(Array,,) 
Config.php:540
Config->getUncached(RESTfulAPI,authentication_policy,0,Array,,Array) 
Config.php:592
Config->get(RESTfulAPI,authentication_policy) 
Config.php:917
Config_ForClass->__get(authentication_policy) 
RESTfulAPI.php:343
RESTfulAPI->index(SS_HTTPRequest) 
RequestHandler.php:288
RequestHandler->handleAction(SS_HTTPRequest,index) 
Controller.php:202
Controller->handleAction(SS_HTTPRequest,index) 
RequestHandler.php:200
RequestHandler->handleRequest(SS_HTTPRequest,DataModel) 
Controller.php:158
Controller->handleRequest(SS_HTTPRequest,DataModel) 
Director.php:385
Director::handleRequest(SS_HTTPRequest,Session,DataModel) 
Director.php:149
Director::direct(/api/regionalOffice,DataModel) 
main.php:191

config.yml:

# Extensions
Subsite:
  extensions:
    - 'FormDataSubsiteExtension'

# API Access
BaseSubmission:
  api_access: 'POST,PUT,GET,DELETE'

School:
  api_access: 'GET'

RegionalOffice:
  api_access: 'GET'

Gender:
  api_access: 'GET'

Dichotomy:
  api_access: 'GET'



# Components config
RESTfulAPI_DefaultQueryHandler:
  dependencies:
    deSerializer: '%$RESTfulAPI_MoeForms_EmberDataDeSerializer'

# RestfulAPI config
RESTfulAPI:
  dependencies:
    serializer: '%$RESTfulAPI_MoeForms_EmberDataSerializer'

  cors:
    Enabled: true
    Allow-Origin: '*'
    Allow-Headers: '*'
    Allow-Methods: 'OPTIONS, GET, PUT, POST, PATCH, DELETE'
    Max-Age: 86400

  authentication_policy:
    - 'DELETE'
    - 'PUT'

Let me know if I can provide anything else. If it helps, when I set the RESTfulAPI::authentication_policy to the array in PHP it seems to work okay.

Cheers!

@dylanitorium this came from the default false config value. Just push a new commit and release that fixes it.