zircote/swagger-php

Get and modify existing Schema

Kiina opened this issue · 0 comments

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

)