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

The content property is missed in RequestBody attribute #1675

Open
cawa-93 opened this issue Nov 22, 2024 · 3 comments
Open

The content property is missed in RequestBody attribute #1675

cawa-93 opened this issue Nov 22, 2024 · 3 comments
Labels

Comments

@cawa-93
Copy link

cawa-93 commented Nov 22, 2024

The content property is declared in constructor argument but it never been assign to instance property

public function __construct(
string|object|null $ref = null,
?string $request = null,
?string $description = null,
?bool $required = null,
array|MediaType|JsonContent|XmlContent|Attachable|null $content = null,
// annotation
?array $x = null,
?array $attachables = null
) {
parent::__construct([
'ref' => $ref ?? Generator::UNDEFINED,
'request' => $request ?? Generator::UNDEFINED,
'description' => $description ?? Generator::UNDEFINED,
'required' => $required ?? Generator::UNDEFINED,
'x' => $x ?? Generator::UNDEFINED,
'value' => $this->combine($content, $attachables),
]);
}
}

@DerManoMann
Copy link
Collaborator

It does work, though. This example https://github.com/zircote/swagger-php/blob/master/Examples/webhooks81/OpenApiSpec.php#L15 does seem to create the correct result.

Nested annotations/properties in Attributes are not assigned to individual instance properties but all get merged into a single value property. This is a behaviour inherited from how nested docblock annotations work.
See

'value' => $this->combine($content, $attachables),

@cawa-93
Copy link
Author

cawa-93 commented Nov 26, 2024

I'm sorry, but I still don't fully understand how this works.

I'm writing something like a server for WordPress. It uses reflection api to read attributes and register the corresponding routers.

If I have an attribute like:

    #[OA\Patch(
        path: "/users/{id}",
        security: [['basicAuth' => ['edit_users']]],
        requestBody: new OA\RequestBody(
            required: true,
            content: new OA\JsonContent(
                type: UserExtended::class,
            ),
        ),
    )]
    public impl() { ... }

how can I get body shape using api?

/** @var OA\Patch $instance */
$instance = $attribute->newInstance();
$instance->requestBody ... ???

@DerManoMann
Copy link
Collaborator

Are you saying requestBody is null?

BTW: I wonder if it is worth re-implementing all that parsing - have had a look at https://github.com/DerManoMann/openapi-router - maybe just writing a new adapter might be simpler?

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

No branches or pull requests

2 participants