Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Swagger Php Laravel Package

zircote/swagger-php

swagger-php generates OpenAPI 3.0/3.1/3.2 documentation from your PHP 8.2+ code using attributes (preferred) or optional Doctrine annotations. Use it via CLI or programmatically, with helpful error reporting and a full documentation site.

View on GitHub
Deep Wiki
Context7

Minimum requirements

The OpenAPI specification defines a minimum set of information for a valid document.

For the most part that consists of some general information about the API like name, version and at least one endpoint.

The endpoint, in turn, needs to have a path and at least one response.

Minimum required annotations

With the above in mind, a minimal API with a single endpoint could look like this:

<<< @/snippets/minimal_api_at.php

<<< @/snippets/minimal_api_an.php

with the resulting OpenAPI document like this

<<< @/snippets/minimal_api.yaml

::: warning Where to add annotations? Attributes and annotations can be added anywhere in your codebase as long as they are associated with structural elements (classes, methods, properties, etc.). Effectively, annotations can be added anywhere in your code where PHP reflection can find them. :::

Optional elements

Looking at the generated document, you will notice that there are some elements that swagger-php adds automatically when they are missing.

For the most part those are [@OA](https://github.com/OA)\OpenApi, [@OA](https://github.com/OA)\Components and [@OA](https://github.com/OA)\PathItem. These are defined by the OpenAPI specification for grouping and as give the generated JSON/Yaml some more structure. Unless there are specific reasons to add them manually, you should not need to add them yourself.

Annotation placement

Your annotations should be placed next to your application code. The idea is that you should be able to see your annotations right next to the code they describe.

This also has the advantage of making it easier to keep both in sync.

swagger-php will scan your project and merge all meta-data into one [@OA](https://github.com/OA)\OpenApi annotation.

::: warning As of swagger-php v4 all attributes and/or annotations must be associated with a structural element (class, method, parameter or enum) :::

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport