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

adding attribute examples #1699

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions docs/guide/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,18 @@ related code, the info annotation (and a few more) is kind of global.
The simplest solution to avoid this issue is to add a 'dummy' class to the docblock and add
all 'global' annotations (e.g. `Tag`, `Server`, `SecurityScheme`, etc.) **in a single docblock** to that class.

```php
/**
* @OA\Tag(
* name="user",
* description="User related operations"
* )
* @OA\Info(
* version="1.0",
* title="Example API",
* description="Example info",
* @OA\Contact(name="Swagger API Team")
* )
* @OA\Server(
* url="https://example.localhost",
* description="API server"
* )
*/
class OpenApiSpec
{
}
```
<codeblock id="dummy-class">
<template v-slot:at>

<<< @/snippets/guide/faq/dummy_class_at.php

</template>
<template v-slot:an>

<<< @/snippets/guide/faq/dummy_class_an.php

</template>
</codeblock>

**As of version 4.8 the `doctrine/annotations` library is optional and might cause the same message.**

Expand Down
21 changes: 21 additions & 0 deletions docs/snippets/guide/faq/dummy_class_an.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* @OA\Tag(
* name="user",
* description="User related operations"
* )
* @OA\Info(
* version="1.0",
* title="Example API",
* description="Example info",
* @OA\Contact(name="Swagger API Team")
* )
* @OA\Server(
* url="https://example.localhost",
* description="API server"
* )
*/
class OpenApiSpec
{
}
18 changes: 18 additions & 0 deletions docs/snippets/guide/faq/dummy_class_at.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use OpenApi\Attributes as OA;

#[OA\Tag(name: "user", description: "User related operations")]
#[OA\Info(
version: "1.0",
title: "Example API",
description: "Example info",
contact: new OA\Contact(name: "Swagger API Team"),
)]
#[OA\Server(
url: "https://example.localhost",
description: "API server",
)]
class OpenApiSpec
{
}