Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenAPI] Property schema has been overwritten due to suspicious type check #6883

Open
c1tru55 opened this issue Dec 20, 2024 · 0 comments
Open

Comments

@c1tru55
Copy link
Contributor

c1tru55 commented Dec 20, 2024

API Platform version(s) affected: 4.0.12

Description

in custom custom decorated api_platform.metadata.property.metadata_factory I return following property schema (schema_type = input):

  'exclusiveMinimum' => 0,
  'type' =>  [
    'integer',
    'null',
  ],

in a result on this line https://github.com/api-platform/core/blob/4.1/src/JsonSchema/SchemaFactory.php#L189 I have following variable values:

$isUnknown = false;
$propertySchema = [
  'exclusiveMinimum' => 0,
  'type' =>  [
    'integer',
    'null',
  ],
];
$propertySchemaType = [
  'integer',
  'null',
];

but since this condition is not passed:

        if (
            !$isUnknown && (
                [] === $types
                || ($propertySchema['$ref'] ?? $propertySchema['anyOf'] ?? $propertySchema['allOf'] ?? $propertySchema['oneOf'] ?? false)
                || (\is_array($propertySchemaType) ? \array_key_exists('string', $propertySchemaType) : 'string' !== $propertySchemaType)
                || ($propertySchema['format'] ?? $propertySchema['enum'] ?? false)
            )
        ) {
            $schema->getDefinitions()[$definitionName]['properties'][$normalizedPropertyName] = new \ArrayObject($propertySchema);

            return;
        }

my schema is changed to:

$propertySchema = [
  'exclusiveMinimum' => 0,
  'anyOf' => 
  [
    [
      '$ref' => '#/components/schemas/Entity.jsonld-Input',
    ],
    [
      'type' => 'null',
    ],
  ],
];

which is not I want.

How to reproduce

Possible Solution

not sure about this condition, why generated schema is changed at all: https://github.com/api-platform/core/blob/4.1/src/JsonSchema/SchemaFactory.php#L189
but this check looks suspicious:

\is_array($propertySchemaType) ? \array_key_exists('string', $propertySchemaType) : 'string' !== $propertySchemaType

especially when type in openapi schema should be string or plain array of strings.
https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-6.1.1

Additional Context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant