Skip to content

Mapping id to uuid breaks openapi schema compliance in EnvironmentResponse. #315

@fiasco

Description

@fiasco

Describe the bug
See here where the EnvironmentResponse object maps the id field in the response to the uuid field on the object. This prohibits the EnvironmentResponse from being validated successfully against the Cloud Api OpenAPI spec.

I've been using thephpleague/openapi-psr7-validator to validate locally stored and altered objects initially retrieved from Cloud API objects. I want to use this library to homogenise my local data and data that comes via typhonius/acquia-php-sdk-v2 so my functions can use both without excessive conditions to handle the data based on its source. Instead, I can validate the data through the OpenApi Spec, then trust it.

To Reproduce
Here is an example:

use cebe\openapi\Reader;
use cebe\openapi\ReferenceContext;
use cebe\openapi\spec\Reference;
use cebe\openapi\SpecObjectInterface;
use League\OpenAPIValidation\Schema\SchemaValidator;

// ...
    const SpecUrl = 'https://cloudapi-docs.acquia.com/acquia-spec.yaml';
    protected SpecObjectInterface $spec;

    public function validate(array|object $response, string $ref) {
        $response = (array) $response;
         // e.g. #/component/schema/Environment.
        $response['$ref'] = $ref;
        $reference = new Reference($response);
        $context = new ReferenceContext($this->spec, self::SpecUrl);
        $schema = $reference->resolve($context);
        $validator = new SchemaValidator();
       // Throw exception because id property is missing on Environment.
        $validator->validate($response, $schema);
        return true;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions