GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Swagger-PHP
  • User Guide
  • Reference
  • OpenApi
  • Releases
  • Installation
  • Generating OpenAPI documents
  • Using Attributes
  • Using Docblock Annotations deprecated
  • Minimum requirements
  • Augmentation
  • References
  • Enums
  • Shortcuts

This view

  • Original page
  • New address

GeezerVison is showing zircote.com — Attributes | Swagger-PHP

Attributes ​

PHP attributes describe the API next to the code they document. The attributes are in the OpenApi\Spec namespace. Using Spec Attributes covers them in detail.

Namespace

Using a namespace alias simplifies typing and improves readability.

php
use OpenApi\Spec as OA;

#[OA\Info(/*...*/)]

Nesting ​

Attributes can be nested, or placed side by side on the same element. swagger-php merges side-by-side attributes according to their parent/child relationships.

Example

Nested:

php
    #[OA\Operation\Get(
        path: '/api/users',
        responses: [
            new OA\Response(response: 200, description: 'OK'),
            new OA\Response(response: 401, description: 'Not allowed'),
        ]
    )]
    public function users() { /* ... */ }

Not nested:

php
    #[OA\Operation\Get(path: '/api/users')]
    #[OA\Response(response: 200, description: 'OK')]
    #[OA\Response(response: 401, description: 'Not allowed')]
    public function users() { /* ... */ }

Depending on how much nesting there is this can make things a bit simpler and easier to read. The merge works only while it is unambiguous. Responses and parameters has the rules.

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.