Skip to content

Support use x-* in ref#1776

Merged
DerManoMann merged 1 commit into
zircote:masterfrom
krissss:fix-ref-x
Jul 19, 2025
Merged

Support use x-* in ref#1776
DerManoMann merged 1 commit into
zircote:masterfrom
krissss:fix-ref-x

Conversation

@krissss

@krissss krissss commented Jul 17, 2025

Copy link
Copy Markdown
Contributor
@OA\Schema(
     schema="String",
     @OA\Property(property="value", type="string"),
     x={
        "custom-key": @OA\Schema(
            @OA\Property(property="value", type="string"),
        )
    }
)

The above annotation will generate x-custom-key in the OpenAPI document.

However, we need to get ref of x-custom-key with $openapi->ref('#/components/schemas/String/x/custom-key') (note that here we use x/custom-key instead of x-custom-key).

This is not conducive to writing ref in the code ourselves. For example,

@OA\Post(
    path="/api/~/endpoint",
    @OA\Response(
        response="default",
        description="A response",
        @OA\JsonContent(ref="#/components/schemas/String/x/custom-key")
    )
)

This will generate the following incorrect documentation when using $openapi->toYaml()(use x/custom-key)

...
            application/json:
              schema:
                $ref: '#/components/schemas/String/x/custom-key'
...

Therefore, we have to write it in the following way (use x-custom-key)

@OA\Post(
    path="/api/~/endpoint",
    @OA\Response(
        response="default",
        description="A response",
        @OA\JsonContent(ref="#/components/schemas/String/x-custom-key")
    )
)

However, if it is written directly in the above way, the validation will fail.

This PR is to fix this issue to support the use of ref x-*.

@DerManoMann

Copy link
Copy Markdown
Collaborator

Interesting - I didn't even know you can nest complex structures in x. Somehow I always assumed it was a flat map...

@DerManoMann DerManoMann left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@DerManoMann DerManoMann merged commit efd7611 into zircote:master Jul 19, 2025
23 checks passed
@DerManoMann

Copy link
Copy Markdown
Collaborator

Thanks @krissss

@krissss krissss deleted the fix-ref-x branch July 20, 2025 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants