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 · 2 comments
Labels
Do Not close Do not auto-close issue/PR enhancement

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).

Copy link

This issue has been marked as stale because it has not had any activity for 60 days. Remove stale label or comment to prevent this from being closed in 21 days.

@github-actions github-actions bot added the stale stale issue/PR label Mar 26, 2025
@DjordyKoert DjordyKoert added Do Not close Do not auto-close issue/PR and removed stale stale issue/PR labels Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Do Not close Do not auto-close issue/PR enhancement
Projects
None yet
Development

No branches or pull requests

3 participants