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

[Feature]: PHPDoc with union of constant strings could/should be considered an enum #2310

Open
RobertMe opened this issue Jul 8, 2024 · 1 comment

Comments

@RobertMe
Copy link

RobertMe commented Jul 8, 2024

Description

Hi,

I have some code like this:

/**
 * @var 'one'|'two'|'three'
 */
public string $prop;

In the OpenAPI JSON this however is rendered into:

"prop": {
  "oneOf": [
    {
      "type": "string"
    },
    {
      "type": "string"
    },
    {
      "type": "string"
    }
  ]
},

Which obviously is kinda wrong because of the oneOf which contains the same value ({"type": "string"}) multiple times.

Furthermore it would be nice if this union would automatically be converted into an enum, resulting in:

"prop": {
  "type": "string",
  "enum": [
    "one",
    "two",
    "three"
  ]
}

Additional context

No response

@Robert-Embloom
Copy link

In addition to this. When setting an enum as well (either using #[Property(enum: ['one', 'two', 'three']) or using Symfony-s Choice constraint) this "breaks" Swagger UI as well, as it just shows the oneOf and not the enum. When then removing this PHPDoc it does properly show the possible enum values. Which in turn also makes me wonder whether it would actually be valid to have a combination of enum and oneOf (as I can imagine that the enum cases all must be of the same type).

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

No branches or pull requests

2 participants