Skip to content

Commit

Permalink
Merge pull request #336 from JarvusInnovations/develop
Browse files Browse the repository at this point in the history
Release: v1.20.1
  • Loading branch information
themightychris authored Mar 22, 2022
2 parents 809698c + 10edfed commit c83a479
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions php-classes/Emergence/OpenAPI/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class Reader
'type'
];

public static $parameterObjectProperties = [
'name',
'in'
];


public static function readTree(array $base = [], $root = 'api-docs')
{
Expand Down Expand Up @@ -70,14 +75,26 @@ function (array $keys) {
$data['components']['schemas'],
[__CLASS__, 'isSchemaObject'],
function (array $keys) {
return implode('\\', $keys);
return implode('-', $keys);
}
);

$data['components']['schemas'] = array_map([__CLASS__, 'normalizeSchemaObject'], $data['components']['schemas']);
ksort($data['components']['schemas']);


// collapse and normalize parameters
$data['components']['parameters'] = static::findObjects(
$data['components']['parameters'],
[__CLASS__, 'isParameterObject'],
function (array $keys) {
return implode('-', $keys);
}
);

ksort($data['components']['parameters']);


return $data;
}

Expand Down Expand Up @@ -124,6 +141,17 @@ protected static function isSchemaObject(array $object)
return false;
}

protected static function isParameterObject(array $object)
{
foreach (static::$parameterObjectProperties AS $key) {
if (array_key_exists($key, $object)) {
return true;
}
}

return false;
}

protected static function normalizePathObject(array $object, array &$outSubPaths = null, array &$outDefinitions = null)
{
if (!empty($object['x-recordsRequestHandler'])) {
Expand Down Expand Up @@ -153,9 +181,7 @@ protected static function fillPathsFromRecordsRequestHandler($className, &$outPa
$recordNoun = $recordClass::$singularNoun;

// generate record definition
$recordDefinitionName = preg_replace_callback('/(^|\s+)([a-zA-Z])/', function ($matches) {
return strtoupper($matches[2]);
}, $recordNoun);
$recordDefinitionName = str_replace('\\', '-', $recordClass::getRootClass());

$recordDefinition = [];
static::fillSchemaFromActiveRecord($recordClass, $recordDefinition);
Expand Down

0 comments on commit c83a479

Please sign in to comment.