Download the PHP package futuretek/openapi-gen-server-yii2 without Composer

On this page you can find all versions of the php package futuretek/openapi-gen-server-yii2. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package openapi-gen-server-yii2

PHP OpenAPI Server Generator

Tests PHP 8.4+

A code generator that transforms an OpenAPI 3.0.x specification into a fully typed PHP server implementation for Yii2, with automatic request/response handling, body deserialization, and middleware support.

Key Features

Requirements

Installation

Quick Start

1. Generate code from your OpenAPI spec

This uses defaults: --base-dir=., --namespace=app\api, route file at config/routes.api.php.

2. With custom namespaces

The --route-prefix option prepends a prefix to route targets, useful for Yii2 module-style routing (e.g. api/pet/list-pets instead of pet/list-pets).

3. Implement the generated interfaces

4. Include the generated routes

Directory Layout

Generated files follow the Yii2 namespace = directory convention. The --base-dir points to your application root (@app), and namespaces are converted to directory paths by stripping the first segment (e.g. app).

The first namespace segment (app) maps to --base-dir. Remaining segments become subdirectories:

Namespace Directory (relative to base-dir)
app\api\schemas api/schemas/
app\modules\api\schemas modules/api/schemas/
app\modules\v2\api\schemas modules/v2/api/schemas/

How It Works

Request Flow

  1. Yii2 routes the request to your controller action
  2. AbstractApiController::bindActionParams() intercepts parameter binding:
    • Deserializes the request body (JSON / multipart) into the typed DTO
    • Extracts path, query, header, and cookie parameters with type casting
    • Resolves enum parameters via ::tryFrom()
    • Handles discriminator mapping for polymorphic bodies
  3. Your action receives fully typed parameters and returns a DTO
  4. AbstractApiController::afterAction() serializes the response to JSON (or streams raw bytes for UploadedFileInterface returns)

Body Handling

Response Handling

File Upload Handling

File properties (type: string, format: binary) are converted to PSR-7 UploadedFileInterface instances. Both single files and arrays of files are supported:

Generated schemas use the correct types and attributes:

The built-in Psr7UploadedFile and Psr7Stream classes provide a complete PSR-7 implementation. Use getStream() to read file contents:

Binary / Plain Response Types

Non-JSON response content types are mapped to simple PHP types — no DTO class is generated:

Content-Type format Return type
application/octet-stream binary / byte UploadedFileInterface
text/plain any string
application/json — Generated DTO class

Array Request Bodies

When a request body is an array of DTOs, the generator creates the correct parameter signature:

Schema Setters

Every generated DTO class includes a fluent setter for each property, allowing builder-style construction:

Setters accept ?Type for optional/nullable properties and Type for required ones. They return static for subclass compatibility.

Security

Security schemes are captured in operationMeta. The abstract controller calls AuthenticationInterface and AuthorizationInterface middleware in beforeAction(). Default implementations pass through — override the factory methods to plug in your auth:

Route Prefix

When using Yii2 modules, route targets need a prefix matching the module ID. Use --route-prefix (or Config::$routePrefix) to prepend it:

Route Regex Constraints

Path parameters in generated URL rules include a type-based regex constraint so Yii2 can distinguish them from static segments. Every constraint is scoped to a single path segment (it never matches /), so a parametric route can't accidentally swallow a deeper route's extra segments:

Parameter type Regex Example rule
integer / number \d+ GET items/<id:\d+>
string and all others [^/]+ GET items/<slug:[^/]+>

Ambiguous Route Detection

The generator warns when a parametric route is listed before a static route it would shadow for the same HTTP method — either because they sit at the same depth and the parametric segment matches the static one, or because a shorter parametric route's trailing segment could otherwise consume a longer, more specific route's extra segments. In this situation Yii2 evaluates the parametric rule first and the static rule is never reached.

Fix options:

CLI Options

Output Order

The generator always outputs in this order:

  1. Errors — fatal problems that prevented generation (exit code 1)
  2. Generated files — list of all written .php files
  3. Warnings — non-fatal issues displayed last so they are easy to spot

With --strict, any warnings also cause a non-zero exit code after being displayed — useful for enforcing clean specs in CI.

Spec Quality Checks

The generator performs several spec quality checks during parsing and emits warnings for:

Issue Warning
Duplicate operationId Duplicate operationId 'X' at METHOD /path
type: object schema with no properties and no allOf Schema 'X' is declared as type:object but has no properties — likely a spec error
Inline enum missing x-enum name Inline enum on property 'X' has no x-enum name
Parametric route shadowing a static route (same or differing depth) Ambiguous routes: METHOD /a will shadow METHOD /b

Empty object schemas (no properties, no allOf) are skipped — no PHP file is generated. This catches the common mistake of using type: object for responses that should be a scalar type (string, integer, etc.).

Use --strict to turn any of these warnings into a build failure.

Vendor Extensions

Extension Level Description
x-controller path / operation Override the controller name
x-enum inline enum schema Name override for inline enums (warns if missing)
x-enum-descriptions enum schema Array of per-value descriptions, aligned with enum values

Example

Schema Generation Details

Type Mapping

OpenAPI Type PHP Type
string string
integer int
number float
boolean bool
string + format: date DateTimeInterface
string + format: date-time DateTimeInterface
string + format: binary UploadedFileInterface
array + items: {type: string, format: binary} array with #[ArrayType(UploadedFileInterface::class)] + @var UploadedFileInterface[]
array + items array with #[ArrayType] + @var T[] PHPDoc
object + additionalProperties object with #[MapType]
enum PHP backed enum
allOf Class inheritance (extends)
oneOf / anyOf Union types (A\|B)

PHPDoc Annotations

Array and map properties are annotated with @var for IDE autocompletion:

Controller Interface Conventions

Discriminator Support

Both explicit and auto-derived discriminator mappings are supported:

At runtime, the abstract controller reads the discriminator property from the raw JSON and deserializes into the correct concrete class.

Development

Running Tests

Project Structure

License

MIT License. See LICENSE for details.


All versions of openapi-gen-server-yii2 with dependencies

PHP Build Version
Package Version
Requires php Version >=8.4
futuretek/data-mapper Version ^1.3.0
cebe/php-openapi Version ^1.8.0
symfony/console Version ^7.0
psr/http-message Version ^1.0 || ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package futuretek/openapi-gen-server-yii2 contains the following files

Loading the files please wait ...