1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00
Oinktube/vendor/zircote/swagger-php
Daniel Neto 7c9f95b33d Refactor and enhance type hinting across various classes in the Swagger-PHP library
- Updated error handling in TokenScanner to use more descriptive variable names.
- Added return type declarations for methods in Analysis, AbstractAnnotation, Components, Items, License, OpenApi, Operation, Parameter, Response, Schema, Context, Generator, and several processors to improve code clarity and type safety.
- Introduced new PipeOperatorEmulator and VoidCastEmulator classes to support PHP 8.5 features.
- Implemented Pipe binary operator and Void cast node classes to enhance the parser's capabilities.
- Improved array filtering and lambda function type hints for better readability and performance.
- Enhanced the handling of annotations and context in various processors to ensure consistent behavior and reduce potential errors.
2025-08-12 11:19:47 -03:00
..
bin https://github.com/WWBN/AVideo/issues/9996#issuecomment-2868568302 2025-05-10 16:23:12 -03:00
src Refactor and enhance type hinting across various classes in the Swagger-PHP library 2025-08-12 11:19:47 -03:00
composer.json https://github.com/WWBN/AVideo/issues/9996#issuecomment-2868568302 2025-05-10 16:23:12 -03:00
CONTRIBUTING.md Better API documentation 2025-04-08 12:15:58 -03:00
LICENSE Better API documentation 2025-04-08 12:15:58 -03:00
NOTICE Better API documentation 2025-04-08 12:15:58 -03:00
package.json Better API documentation 2025-04-08 12:15:58 -03:00
README.md Better API documentation 2025-04-08 12:15:58 -03:00
rector.php Refactor and enhance type hinting across various classes in the Swagger-PHP library 2025-08-12 11:19:47 -03:00

Build Status Total Downloads License

swagger-php

Generate interactive OpenAPI documentation for your RESTful API using PHP attributes (preferred) or doctrine annotations (requires additional doctrine/annotations library).

See the documentation website for supported attributes and annotations.

Annotations are deprecated and may be removed in a future release of swagger-php.

Features

  • Compatible with the OpenAPI 3.0 and 3.1 specification.
  • Extracts information from code & existing phpdoc annotations.
  • Command-line interface available.
  • Documentation site with a getting started guide.
  • Exceptional error reporting (with hints, context)
  • As of PHP 8.1 all annotations are also available as PHP attributes

OpenAPI version support

swagger-php allows to generate specs either for OpenAPI 3.0.0 or OpenAPI 3.1.0. By default the spec will be in version 3.0.0. The command line option --version may be used to change this to 3.1.0.

Programmatically, the method Generator::setVersion() can be used to change the version.

Requirements

swagger-php requires at least PHP 7.4 for annotations and PHP 8.1 for using attributes.

Installation (with Composer)

composer require zircote/swagger-php

For cli usage from anywhere install swagger-php globally and make sure to place the ~/.composer/vendor/bin directory in your PATH so the openapi executable can be located by your system.

composer global require zircote/swagger-php

doctrine/annotations

As of version 4.8 the doctrine annotations library is optional and no longer installed by default.

To use PHPDoc annotations this needs to be installed on top of swagger-php:

composer require doctrine/annotations

If your code uses PHPDoc annotations you will need to install this as well:

composer require doctrine/annotations

Usage

Add annotations to your php files.

/**
 * @OA\Info(title="My First API", version="0.1")
 */

/**
 * @OA\Get(
 *     path="/api/resource.json",
 *     @OA\Response(response="200", description="An example resource")
 * )
 */

Visit the Documentation website for the Getting started guide or look at the examples directory for more examples.

Usage from php

Generate always-up-to-date documentation.

<?php
require("vendor/autoload.php");
$openapi = \OpenApi\Generator::scan(['/path/to/project']);
header('Content-Type: application/x-yaml');
echo $openapi->toYaml();

Documentation of how to use the Generator class can be found in the Generator reference.

Usage from the Command Line Interface

The openapi command line interface can be used to generate the documentation to a static yaml/json file.

./vendor/bin/openapi --help

Usage from the Deserializer

Generate the OpenApi annotation object from a json string, which makes it easier to manipulate objects programmatically.

<?php

use OpenApi\Serializer;

$serializer = new Serializer();
$openapi = $serializer->deserialize($jsonString, 'OpenApi\Annotations\OpenApi');
echo $openapi->toJson();

Contributing

More on OpenApi & Swagger