PHPackages                             calcinai/strut - 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. calcinai/strut

ActiveLibrary[API Development](/categories/api)

calcinai/strut
==============

Library for creating and manipulating Swagger schemas

v1.0.0(7y ago)1415.6k↑14.3%3[2 issues](https://github.com/calcinai/strut/issues)1MITPHP

Since Oct 4Pushed 7y ago1 watchersCompare

[ Source](https://github.com/calcinai/strut)[ Packagist](https://packagist.org/packages/calcinai/strut)[ RSS](/packages/calcinai-strut/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)DependenciesVersions (10)Used By (1)

Strut
=====

[](#strut)

Yet another OpenAPI/Swagger manipulation library!

This library is almost 100% generated code by [Gendarme](https://github.com/calcinai/gendarme). The reasoning behind this is that all the information required to manipulate a schema outlined in the specification.

Installation
------------

[](#installation)

via composer

```
composer require calcinai/strut

```

Usage
-----

[](#usage)

The test case for this is the OpenAPI petstore.

The library will deserialize an OpenAPI specification into native PHP objects, then serialize it back into its original form, with the only differences (sometimes) being the order of properties in objects (which is of no consequence).

### Loading documents

[](#loading-documents)

```
$schema = json_decode(file_get_contents('http://petstore.swagger.io/v2/swagger.json'));
$openapi = \Calcinai\Strut\OpenAPI::create($schema);
print_r($swagger);
```

This will produce (snipped):

```
Calcinai\Strut\OpenAPI Object
(
 [data:protected] => Array
  (
   [openapi] => 3.0
   [info] => Calcinai\Strut\Definitions\Info Object
    (
     [data:protected] => Array
      (
       [version] => 1.0.0
       [title] => OpenAPI Petstore
       [license] => Calcinai\Strut\Definitions\License Object
        (
         [data:protected] => Array
          (
           [name] => MIT
          )

        )

      )

    )

   [servers] => Array
    (
     [0] => Calcinai\Strut\Definitions\Server Object
      (
       [data:protected] => Array
        (
         [url] => https://petstore.openapis.org/v1
         [description] => Development server
        )

      )

    )

   [paths] => Calcinai\Strut\Definitions\Paths Object
    (
     [data:protected] => Array
      (
       [/pets] => Calcinai\Strut\Definitions\PathItem Object
        (
         [data:protected] => Array
          (
           [get] => Calcinai\Strut\Definitions\Operation Object
            (
             [data:protected] => Array
              (
               [summary] => List all pets
               [operationId] => listPets
               [tags] => Array
                (
                 [0] => pets
                )

               [parameters] => Array
                (
                 [0] => Calcinai\Strut\Definitions\Parameter Object
                  (
                   [data:protected] => Array
                    (
                     [name] => limit
                     [in] => query
                     [description] => How many items to return at one time (max 100)
                     [required] =>
                     [schema] => Calcinai\Strut\Definitions\Schema Object
                      (
                       [data:protected] => Array
                        (
                         [type] => integer
                         [format] => int32
                        )

                      )

                    )

                  )

                )

               [responses] => Calcinai\Strut\Definitions\Responses Object
                (
                 [data:protected] => Array
                  (
                   [200] => Calcinai\Strut\Definitions\Response Object
                    (
                     [data:protected] => Array
                      (
                       [description] => An paged array of pets
                       [headers] => Calcinai\Strut\Definitions\HeadersOrReferences Object
                        (
                         [data:protected] => Array
                          (
                           [x-next] => Calcinai\Strut\Definitions\Header Object
                            (
                             [data:protected] => Array
                              (
                               [schema] => Calcinai\Strut\Definitions\Schema Object
                                (
                                 [data:protected] => Array
                                  (
                                   [type] => string
                                  )

                                )

                               [description] => A link to the next page of responses
                              )

                            )

                          )

                        )

                       [content] => Calcinai\Strut\Definitions\MediaTypes Object
                        (
                         [data:protected] => Array
                          (
                           [application/json] => Calcinai\Strut\Definitions\MediaType Object
                            (
                             [data:protected] => Array
                              (
                               [schema] => Calcinai\Strut\Definitions\Reference Object
                                (
                                 [data:protected] => Array
                                  (
                                   [$ref] => #/components/schemas/Pets
                                  )

                                )

                              )

                            )

                          )

                        )

                      )

                    )

...

```

### Creating and modifying documents

[](#creating-and-modifying-documents)

The following is an example of how that schema would be programatically generated:

```
$pet = Schema::create()
    ->addRequired('id')
    ->addRequired('name')
    ->setProperties(Properties::create()
        ->set('id', Schema::create()
            ->setType('integer')
            ->setFormat('int64')
        )
        ->set('name', Schema::create()
            ->setType('string')
        )
        ->set('tag', Schema::create()
            ->setType('string')
        )
    );

$pets = Schema::create()
    ->setType('array')
    ->setItems($pet);

$error = Schema::create()
    ->addRequired('code')
    ->addRequired('message')
    ->setProperties(Properties::create()
        ->set('code', Schema::create()
            ->setType('integer')
            ->setFormat('int32')
        )
        ->set('error', Schema::create()
            ->setType('string')
        )
    );

$schema = OpenAPI::create()
    ->setInfo(
        Info::create()
            ->setTitle('Swagger Petstore')
            ->setVersion('1.0.0')
            ->setLicense(
                License::create()
                    ->setName('MIT')
            )
    )
    ->addServer(\Calcinai\Strut\Definitions\Server::create()->setUrl('petstore.swagger.io'))
    ->setPaths(Paths::create()
        ->set('/pets', PathItem::create()
            ->setGet(Operation::create()
                ->setSummary('List all pets')
                ->setOperationId('listPets')
                ->addTag('pets')
                ->setResponses(Responses::create()
                    ->set('200', Response::create()
                        ->setDescription('A paged array of pets')
                    )
                    ->set('default', Response::create()
                        ->setDescription('Unexpected error')
                    )
                )
            )
        )
    )
    ->setComponents(\Calcinai\Strut\Definitions\Components::create()
        ->setSchemas(\Calcinai\Strut\Definitions\SchemasOrReferences::create()
            ->set('Pet', $pet)
            ->set('Pets', $pets)
            ->set('Error', $error)
        )
    );

echo json_encode($schema, JSON_PRETTY_PRINT);
```

This will output:

```
{
    "info": {
        "title": "Swagger Petstore",
        "version": "1.0.0",
        "license": {
            "name": "MIT"
        }
    },
    "servers": [
        {
            "url": "petstore.swagger.io"
        }
    ],
    "paths": {
        "\/pets": {
            "get": {
                "summary": "List all pets",
                "operationId": "listPets",
                "tags": [
                    "pets"
                ],
                "responses": {
                    "200": {
                        "description": "A paged array of pets"
                    },
                    "default": {
                        "description": "Unexpected error"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "Pet": {
                "required": [
                    "id",
                    "name"
                ],
                "properties": {
                    "id": {
                        "type": "integer",
                        "format": "int64"
                    },
                    "name": {
                        "type": "string"
                    },
                    "tag": {
                        "type": "string"
                    }
                }
            },
            "Pets": {
                "type": "array",
                "items": {
                    "required": [
                        "id",
                        "name"
                    ],
                    "properties": {
                        "id": {
                            "type": "integer",
                            "format": "int64"
                        },
                        "name": {
                            "type": "string"
                        },
                        "tag": {
                            "type": "string"
                        }
                    }
                }
            },
            "Error": {
                "required": [
                    "code",
                    "message"
                ],
                "properties": {
                    "code": {
                        "type": "integer",
                        "format": "int32"
                    },
                    "error": {
                        "type": "string"
                    }
                }
            }
        }
    }
}
```

This isn't the full example, but it gives an idea of the structure.

Contributing
------------

[](#contributing)

I'd love feedback and/or contributions, but they will probably need to target the generation library. Head to [Gendarme](https://github.com/calcinai/gendarme) if this sounds like you. Basic command for generating this library is

```
./bin/gendarme generate --namespace "Calcinai\Strut" --root-class Swagger  ../strut/lib/schema.json ../strut/src/

```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 97.3% 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 ~118 days

Recently: every ~194 days

Total

8

Last Release

2682d ago

Major Versions

v0.2.5 → v1.0.02019-01-14

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2415868?v=4)[Michael Calcinai](/maintainers/calcinai)[@calcinai](https://github.com/calcinai)

---

Top Contributors

[![calcinai](https://avatars.githubusercontent.com/u/2415868?v=4)](https://github.com/calcinai "calcinai (36 commits)")[![fsavina](https://avatars.githubusercontent.com/u/4038144?v=4)](https://github.com/fsavina "fsavina (1 commits)")

### Embed Badge

![Health badge](/badges/calcinai-strut/health.svg)

```
[![Health](https://phpackages.com/badges/calcinai-strut/health.svg)](https://phpackages.com/packages/calcinai-strut)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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