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

API Resource: example and description are lost if union type has more than 2 members #768

Open
petert82 opened this issue Mar 14, 2025 · 0 comments

Comments

@petert82
Copy link

Using v0.12.11, when trying to document an API resource like this:

/**
 * @mixin MyModel
 */
class MyModelResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            /**
             * The first field
             * @var string|null
             * @example "Some example value"
             */
            'field_one' => $this->field_one,
            /**
             * The second field
             * @var string|null|boolean
             * @example "Some other example"
             */
            'field_two' => $this->field_two,
        ];
    }
}

The generated documentation for field_one works as expected, and includes the description from the doc block as well as the given example:

{
  "type": [
    "string",
    "null"
  ],
  "description": "The first field",
  "examples": [
    "Some example value"
  ]
}

However field_two ignores the description and the example, and just documents that it can be any of string, null or boolean:

{
  "anyOf": [
    {
      "type": "string"
    },
    {
      "type": "null"
    },
    {
      "type": "boolean"
    }
  ]
}

I'm not sure if I'm missing a way to annotate the field to make this work they way I would expect for field_two, or if this is a bug?

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

1 participant