PHPackages                             amsify42/php-swagger-postman - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. amsify42/php-swagger-postman

ActiveLibrary[API Development](/categories/api)

amsify42/php-swagger-postman
============================

PHP package for generating swagger json through its annotation and generate postman collection from it

2.1.5(9mo ago)118MITPHPPHP &gt;=7.4

Since Aug 5Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/amsify42/php-swagger-postman)[ Packagist](https://packagist.org/packages/amsify42/php-swagger-postman)[ RSS](/packages/amsify42-php-swagger-postman/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (2)Versions (17)Used By (0)

PHP Swagger Postman
===================

[](#php-swagger-postman)

```
composer require amsify42/php-swagger-postman

```

### For generating enpoint specific Attribute, you can call this method

[](#for-generating-enpoint-specific-attribute-you-can-call-this-method)

```
$attribute = new \Amsify42\PhpSwaggerPostman\Swagger\Attribute();
echo $attribute->generate();
```

#### You can also pass parameter rules and route params also with key value pair to get it added to the attribute

[](#you-can-also-pass-parameter-rules-and-route-params-also-with-key-value-pair-to-get-it-added-to-the-attribute)

```
echo $attribute->generate(
  ['name' => 'required', 'address_id' => 'reqiured|integer'],
  ['userId' => 42]
);
```

#### For generating response data in attibute

[](#for-generating-response-data-in-attibute)

```
$attribute->setSuccessData(['id' => 42, 'name' => 'SomeUser']);
echo $attribute->generate();
```

#### You can also pass callback for checking rules and decide the param needs to have TinyInt or Enum Values or Custom Property Attribute

[](#you-can-also-pass-callback-for-checking-rules-and-decide-the-param-needs-to-have-tinyint-or-enum-values-or-custom-property-attribute)

```
$attribute->checkRules(
                function ($name, $rule) {
                    if ($rule == 'some_custom_rule') {
                        return [
                            'property' => ''// Pass some custom property attribute syntax or empty string for skipping
                        ];
                    } else if ($rule == 'enum') {
                        return  [
                            'enum' => ['paid', 'unpaid']
                        ];
                    } else if ($rule == 'boolean') {
                        return  [
                            'tinyint' => true
                        ];
                    }
                    return NULL;
                }
            );
```

By default `NULL` needs to be return if array of tinyint/enum/property is not return and if you want to generate property for a param which might be having simple or nested array

```
$attribute->checkRules(
                function ($name, $rule) use($attribute) {
                    if ($rule == 'array') {
                        return [
                            'property' => $attribute->createObjectOrArrayProperty(
                                $_POST[$name], // or $_GET[$name] or value from body data
                                $name
                              )
                        ];
                    }
                    return NULL;
                }
            );
```

#### For adding security

[](#for-adding-security)

```
$attribute->setSecurity('XApiKey'); // The XApiKey will be from the security attribute already added
```

Example security attribute already added

```
#[OA\SecurityScheme(
    securityScheme: "XApiKey",
    type: "apiKey",
    in: "header",
    name: "X-Api-Key"
)]
```

#### For adding header with static value

[](#for-adding-header-with-static-value)

```
$attribute->setHeader(['Auth-Key' => 'some_key']);
```

#### For adding response which already defined

[](#for-adding-response-which-already-defined)

```
$attribute->setResponse([
                [
                    'code' => 422,
                    'ref' => '#/components/responses/Validation' // Validation here is the name of response which is already defined somewhere
                ]
            ]);
```

Example Validation already defined

```
#[OA\Response(
    response: "Validation",
    description: "Validation Errors",
    content: new OA\JsonContent(
        properties: [
            new OA\Property(
                property: "message",
                example: "Please check the inputs provided"
            ),
            new OA\Property(
                property: "errors",
                type: "object"
            )
        ]
    )
)]
```

#### For generating *Annotation* instead of *Attribute*

[](#for-generating-annotation-instead-of-attribute)

```
$annotation = new \Amsify42\PhpSwaggerPostman\Swagger\Annotation();
echo $annotation->generate();
```

*Notes:*

1. You can use all the method with **Annotation** which is mentioned above for **Attribute** but *Attribute* requires minimum php `8.2` version.
2. For using Annotation with latest `swagger-php` installed, you may have to separately install `doctrine/annotations`

```
composer require doctrine/annotations

```

Refer to this link for more details

### Scanning the directory and generating swagger json for API documentation and postman collection and postman environment json.

[](#scanning-the-directory-and-generating-swagger-json-for-api-documentation-and-postman-collection-and-postman-environment-json)

```
$swagger = new \Amsify42\PhpSwaggerPostman\Swagger;
$swagger->getGeneratedJson(
    "path/to/scan-directory",
    "path/to/export-swagger-and-postman-json/"
);
```

**Notes:**

1. Make sure to have `OA/Info` and at least one API endpoint already added before running `$swagger->getGeneratedJson()` method.
2. For detecting source classes properly while scanning the directory, Either set `autoload` in `composer.json` or use `spl_autoload_register()` method for customize autoloading of the classes.

```
use OpenApi\Attributes as OA;

#[OA\Info(title: "My API", version: "1.0.0")]

#[OA\Get(path:"/api/users")]
#[OA\Response(response:"200", description:"An example endpoint")]
```

**Annotation Example**

```
/**
 * @OA\Info(
 *   version="1.0.0",
 *   title="My API"
 * )
 */

/**
 * @OA\Get(
 *     path="/api/users",
 *     @OA\Response(response="200", description="An example endpoint")
 * )
 */
```

If you want postman environment to have baseURL variable value, you can either set like this

```
$swagger = new \Amsify42\PhpSwaggerPostman\Swagger('http://www.site.com');
$swagger->getGeneratedJson(
    "path/to/scan-directory",
    "path/to/export-swagger-and-postman-json/"
);
```

or define at least one server in Attribute

```
#[OA\Server(
    url: 'http://www.site.com',
    description: 'some description about site'
)]
```

or in Annotation

```
/**
 * @OA\Server(
 *     url="http://www.site.com",
 *     description="some description about site"
 * )
 */
```

for adding environment suffix in postman environment file name, you can pass it in second parameter of Swagger Constructor

```
$swagger = new \Amsify42\PhpSwaggerPostman\Swagger('http://www.site.com', 'Local');
```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance57

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~27 days

Recently: every ~15 days

Total

16

Last Release

287d ago

PHP version history (2 changes)2.0.0PHP ^7.4

2.0.3PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7560182?v=4)[Amsify42](/maintainers/amsify42)[@amsify42](https://github.com/amsify42)

---

Top Contributors

[![amsify42](https://avatars.githubusercontent.com/u/7560182?v=4)](https://github.com/amsify42 "amsify42 (54 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/amsify42-php-swagger-postman/health.svg)

```
[![Health](https://phpackages.com/badges/amsify42-php-swagger-postman/health.svg)](https://phpackages.com/packages/amsify42-php-swagger-postman)
```

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

3.0k37.6M134](/packages/darkaonline-l5-swagger)[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.4k67.4M262](/packages/nelmio-api-doc-bundle)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M574](/packages/shopware-core)[tangwei/apidocs

A swagger library for Hyperf.

53137.0k8](/packages/tangwei-apidocs)[hyperf/swagger

A swagger library for Hyperf.

20371.1k7](/packages/hyperf-swagger)[pimcore/studio-backend-bundle

Pimcore Studio Backend Bundle

20203.9k22](/packages/pimcore-studio-backend-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
