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

How do I specify not > required items? #1649

Open
abarker-gravity opened this issue Sep 3, 2024 · 3 comments
Open

How do I specify not > required items? #1649

abarker-gravity opened this issue Sep 3, 2024 · 3 comments

Comments

@abarker-gravity
Copy link

I am trying to generate the following OpenAPI JSON but I am having trouble generating the "not": { "required": [ array. I can't really find any examples of doing this and the only thing I can get working is producing warnings (PHP Warning: @OA\Schema() is missing key-field: "schema") because I'm likely doing it wrong. Any help would be appreciated.

                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "allOf": [
                                    {
                                        "$ref": "#/components/schemas/User"
                                    },
                                    {
                                        "minProperties": 1
                                    }
                                ],
                                "not": {
                                    "required": [
                                        "userId",
                                        "userPubId"
                                    ]
                                }
                            }
                        }
                    }
                },
     *   @OA\RequestBody(
     *     required=true,
     *     @OA\JsonContent(
     *         allOf={
     *             @OA\Schema(ref="#/components/schemas/User"),
     *             @OA\Schema(minProperties=1)
     *         },
     *         not=@OA\Schema(
     *                 required={
     *                     "userId",
     *                     "userPubId"
     *                 }
     *             )
     *
     *     )
     *   ),
@DerManoMann
Copy link
Collaborator

I don't think there is built in support for that. You'd have to create nested arrays yourself using standard doctrine annotations syntax.

@abarker-gravity
Copy link
Author

@DerManoMann Thanks for the reply. I am not very familiar with the standard doctrine annotations syntax. Is there a reference somewhere? The only thing ive found is https://www.doctrine-project.org/projects/doctrine-orm/en/2.16/reference/annotations-reference.html which seem to be focused on the ORM annotations. How would I convert the not=@OA\Schema( to a doctrine annotation?

@DerManoMann
Copy link
Collaborator

This might be what you need.

/**
 * @OA\RequestBody(
 *     required=true,
 *     @OA\JsonContent(
 *         allOf={
 *             @OA\Schema(ref="#/components/schemas/User"),
 *             @OA\Schema(minProperties=1)
 *         },
 *         not={
 *             "required"={
 *                 "userId",
 *                 "userPubId"
 *             }
 *         }
 *     )
 *   )
 */

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

No branches or pull requests

2 participants