You are here

protected function OpenApiGeneratorBase::fixDefaultFalse in OpenAPI 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/openapi/OpenApiGeneratorBase.php \Drupal\openapi\Plugin\openapi\OpenApiGeneratorBase::fixDefaultFalse()

Fix default field value as zero instead of FALSE.

Parameters

array $value: JSON Schema field value.

1 call to OpenApiGeneratorBase::fixDefaultFalse()
OpenApiGeneratorBase::cleanSchema in src/Plugin/openapi/OpenApiGeneratorBase.php
Cleans JSON schema definitions for OpenAPI.

File

src/Plugin/openapi/OpenApiGeneratorBase.php, line 437

Class

OpenApiGeneratorBase
Defines base class for OpenApi Generator plugins.

Namespace

Drupal\openapi\Plugin\openapi

Code

protected function fixDefaultFalse(array &$value) {
  $type_is_array = isset($value['type']) && $value['type'] === 'array';
  $has_properties = isset($value['items']['properties']) && is_array($value['items']['properties']);
  $has_default = isset($value['default']) && is_array($value['default']);
  if ($type_is_array && $has_properties && $has_default) {
    foreach ($value['items']['properties'] as $property_key => $property) {
      if ($property['type'] === 'boolean') {
        foreach ($value['default'] as &$default_values) {
          if (isset($default_values[$property_key]) && empty($default_values[$property_key])) {
            $default_values[$property_key] = FALSE;
          }
        }
      }
    }
  }
}