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

Repeated $ref - entry in "allOf" #1478

Closed
faatz-lamapoll opened this issue Sep 26, 2023 · 0 comments · Fixed by #1481
Closed

Repeated $ref - entry in "allOf" #1478

faatz-lamapoll opened this issue Sep 26, 2023 · 0 comments · Fixed by #1481
Labels

Comments

@faatz-lamapoll
Copy link

faatz-lamapoll commented Sep 26, 2023

Current behavior

When "extending" a schema (using allOf) and adding required property, the generated schema will contain two $ref - entries to the referenced schema:

use OpenApi\Attributes as OA;

#[OA\Schema(
  schema: 'abstract-user',
  properties: [
    new OA\Property(
      property: 'name',
      type: 'string'
    ),
    new OA\Property(
      property: 'email',
      type: 'string'
    ),
  ]
)]
class AbstractUser {}

#[OA\Schema(
  schema: 'create-user',
  allOf: [
    new OA\Schema(
      ref: '#/components/schemas/abstract-user'
    ),
    new OA\Schema(
      required: ['name', 'email']
    ),
  ]
)]
class CreateUser {}

Will generate following entries in the schema:

...
components:
  schemas:
    ...
    abstract-user: ...
    create-user:
      allOf:
        - $ref: "#/components/schemas/abstract-user"
        - required:
          - name
          - email
        - $ref: "#/components/schemas/abstract-user"

Expected behavior

The schema should contain only one reference to the extended schema, like

...
components:
  schemas:
    ...
    abstract-user: ...
    create-user:
      allOf:
        - $ref: "#/components/schemas/abstract-user"
        - required:
          - name
          - email

Effects

I only use swagger-ui which does not complain about it, but it confuses when exploring the schemas.
I am not sure if more advanced tools will break with it.

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

Successfully merging a pull request may close this issue.

2 participants