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

[Bug]: explicit setting of default value in Property causes error "Multiple definitions for [property]" #2330

Open
heiglandreas opened this issue Aug 5, 2024 · 1 comment
Labels

Comments

@heiglandreas
Copy link
Contributor

Version

4.25.0

Description

Since v4.25.0 we have the issue that we can no longer declare default values in a Property definition when this value differs from the value declared in code.

As an example we have this code in a larger codebase:

class X 
{
	#[Property(type: 'boolean', default: true)]
    public int $aboutEnabled = 0;
}

When running bin/console nelmio:apidoc:dump this results in

15:13:00 CRITICAL  [app] User Warning: Multiple definitions for @OA\Property()->default
     Using: 
  Skipping: \X->aboutEnabled in /path/to/X.php ["exception" => ErrorException { …}] ["log_uid" => "nelmio:apidoc:dump#8509bba1f254"]
15:13:00 CRITICAL  [console] Error thrown while running command "'nelmio:api:dump'". Message: "User Warning: Multiple definitions for @OA\Property()->default\n     Using: \n  Skipping: \X->aboutEnabled in /path/to/X.php" ["exception" => ErrorException { …},"command" => "'nelmio:api:dump'","message" => """  User Warning: Multiple definitions for @OA\Property()->default\n       Using: \n    Skipping: \X->aboutEnabled in /path/toX.php  """] ["log_uid" => "nelmio:apidoc:dump#8509bba1f254"]

In DefaultLogger.php line 31:
                                                                                                           
  User Warning: Multiple definitions for @OA\Property()->default                                           
       Using:                                                                                              
    Skipping: \X->aboutEnabled in /path/to/X.php  
                                                                                                           

nelmio:apidoc:dump [--area [AREA]] [--format FORMAT] [--server-url SERVER-URL] [--html-config HTML-CONFIG] [--no-pretty]

With version v4.24.1 everything works as expected and we get the expected OpenAPI output.

When I move the code

// Fix for https://github.com/nelmio/NelmioApiDocBundle/issues/2222
// Property default value has to be set before SymfonyConstraintAnnotationReader::processPropertyAnnotations()
// is called to prevent wrongly detected required properties
if (Generator::UNDEFINED === $property->default && array_key_exists($propertyName, $defaultValues)) {
$property->default = $defaultValues[$propertyName];
}
behind this part
// If type manually defined
if (Generator::UNDEFINED !== $property->type || Generator::UNDEFINED !== $property->ref) {
continue;
}
everything works as expected as we were used to in version v4.24.1

The problem that we have is that we are using this package to create an API documentation for a legacy code-base where a lot of such quirks are necessary to declare the values that will be set from a user-perspective.

As far as I understood the code and the general working so far an explicitly manually set value of a property should always overwrite any inflected value from code-analysis.

Am I wrong in this assumption? Or has this changed?

JSON OpenApi

See above

Additional context

No response

@DjordyKoert
Copy link
Collaborator

As far as I understood the code and the general working so far an explicitly manually set value of a property should always overwrite any inflected value from code-analysis.

You are correct explicitly set values should always have priority.

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

No branches or pull requests

2 participants