-
-
Notifications
You must be signed in to change notification settings - Fork 893
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
Comments
I think that we're not detecting properly that you set the type yourself, can you try adding this flag to your core/src/JsonSchema/SchemaFactory.php Line 167 in 9389b4f
|
yeah, came to same solution temporary. #[AsDecorator(decorates: 'api_platform.metadata.property.metadata_factory')]
readonly class FooPropertyMetadataFactory implements PropertyMetadataFactoryInterface
{
public function create(string $resourceClass, string $property, array $options = []): ApiProperty
{
$propertyMetadata = $this->decorated->create($resourceClass, $property, $options);
if (
null !== ($builtinType = $propertyMetadata->getBuiltinTypes()[0] ?? null)
&& !$builtinType->isCollection()
&& null !== ($className = $builtinType->getClassName())
&& is_a($className, FooInterface::class, true)
) {
return $propertyMetadata
->withSchema(/* new schema */)
->withExtraProperties(array_merge($propertyMetadata->getExtraProperties(), [
SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED => true, <---
]))
; but this check anyway looks suspicious: \array_key_exists('string', $propertySchemaType) when type in openapi schema should be string or plain array of strings. |
Agreed although you'd have the same issue no? To know why the check is there we probably need to comment + run the tests. When metadata is read from attributes (
|
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
):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:
but since this condition is not passed:
my schema is changed to:
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:
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
The text was updated successfully, but these errors were encountered: