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

Get and modify existing Schema #1666

Open
Kiina opened this issue Oct 15, 2024 · 3 comments
Open

Get and modify existing Schema #1666

Kiina opened this issue Oct 15, 2024 · 3 comments
Labels

Comments

@Kiina
Copy link
Contributor

Kiina commented Oct 15, 2024

I have a class like this:

#[OA\Schema]
class Request{
    #[OA\Property]
    private int $code;
    #[OA\Property]
    private string $message;
    /**
     * @var JsonSerializable|array<string, mixed>|null
     */
    #[OA\Property]
    private JsonSerializable|array|null $payload;
}

Now I've written a processor that generates other schemas and I have a reflection class on the Request class.
Is there any way to get the schema for a corresponding class and change a property to insert a reference to another schema I've generated?

I tried using

$analysis->getSchemaForSource($namespace . $arg->value->class->name);

But the resulting Schema seems empty except for the line in which the class starts:

object(OpenApi\Attributes\Schema)#20252 (2) {
  ["_context"]=>
  object(OpenApi\Context)#20228 (1) {
    ["-"]=>
    string(84) "/composer/Payload/Request.php on line 16"
  }
  ["_unmerged"]=>
  array(0) {
  }
}

(btw that JsonSerializable part seems to kinda break generation, the output is:

payload:
  description: mixed>|null

)

@DerManoMann
Copy link
Collaborator

That should be what is needed.

Not sure what you mean with JsonSerializable part seems to kinda break generation - a code sample would be good.

@Kiina
Copy link
Contributor Author

Kiina commented Mar 3, 2025

Not sure what you mean with JsonSerializable part seems to kinda break generation - a code sample would be good.

Ah yeah JsonSerializable isn't the issue, it's the array shape. This was before I discovered that they don't work, so the JsonSerializable|array<string, mixed>|null breaks because it can't parse the array shape, not because of the JsonSerializable.

That should be what is needed.

So should modifying an existing schema work now?

@DerManoMann
Copy link
Collaborator

It should as the library does it too. Array shape is still broken, working on it.

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