Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .github/.kodiak.toml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/codesniffer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
name: "Codesniffer"
uses: contributte/.github/.github/workflows/codesniffer.yml@master
with:
php: "8.2"
php: "8.4"
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ on:
branches: ["*"]

schedule:
- cron: "0 8 * * 1"
- cron: "0 9 * * 1"

jobs:
coverage:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester-coverage-v2.yml@master
with:
php: "8.2"
php: "8.4"
4 changes: 2 additions & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ on:
branches: ["*"]

schedule:
- cron: "0 8 * * 1"
- cron: "0 10 * * 1"

jobs:
phpstan:
name: "Phpstan"
uses: contributte/.github/.github/workflows/phpstan.yml@master
with:
php: "8.2"
php: "8.4"
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
workflow_dispatch:

push:
branches: [ "*" ]
branches: ["*"]

schedule:
- cron: "0 8 * * 1"
- cron: "0 10 * * 1"

jobs:
test85:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Contributte
Copyright (c) 2025 Contributte

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
![](https://heatbadger.now.sh/github/readme/contributte/openapi/)
![](https://heatbadger.vercel.app/github/readme/contributte/openapi/)

<p align=center>
<a href="https://github.com/contributte/openapi/actions"><img src="https://badgen.net/github/checks/contributte/openapi/master?cache=300"></a>
<a href="https://coveralls.io/r/contributte/openapi"><img src="https://badgen.net/coveralls/c/github/contributte/openapi"></a>
<a href="https://packagist.org/packages/contributte/openapi"> <img src="https://badgen.net/packagist/dm/contributte/openapi"> </a>
<a href="https://packagist.org/packages/contributte/openapi"> <img src="https://badgen.net/packagist/v/contributte/openapi"> </a>
<a href="https://coveralls.io/r/contributte/openapi"><img src="https://badgen.net/coveralls/c/github/contributte/openapi?cache=300"></a>
<a href="https://packagist.org/packages/contributte/openapi"><img src="https://badgen.net/packagist/dm/contributte/openapi"></a>
<a href="https://packagist.org/packages/contributte/openapi"><img src="https://badgen.net/packagist/v/contributte/openapi"></a>
</p>
<p align=center>
<a href="https://packagist.org/packages/contributte/openapi"><img src="https://badgen.net/packagist/php/contributte/openapi"></a>
<a href="https://github.com/contributte/openapi"><img src="https://badgen.net/github/license/contributte/openapi"></a>
<a href="https://bit.ly/ctteg"><img src="https://badgen.net/badge/support/gitter/cyan"></a>
<a href="https://bit.ly/cttfo"><img src="https://badgen.net/badge/support/forum/yellow"></a>
<a href="https://contributte.org/partners.html"><img src="https://badgen.net/badge/become/a%20patron/F96854"></a>
<p>
<a href="https://contributte.org/partners.html"><img src="https://badgen.net/badge/sponsor/donations/F96854"></a>
</p>

<p align=center>
Website 🚀 <a href="https://contributte.org">contributte.org</a> | Contact 👨🏻‍💻 <a href="https://f3l1x.io">f3l1x.io</a> | Twitter 🐦 <a href="https://twitter.com/contributte">@contributte</a>
Expand All @@ -30,12 +29,12 @@ composer require contributte/openapi

For details on how to use this package, check out our [documentation](.docs).

## Version
## Versions

| State | Version | Branch | Nette | PHP |
|-------------|---------|----------|------|---------|
| dev | `^0.2` | `master` | 4.0+ | `>=8.2` |
| stable | `^0.1` | `master` | 4.0+ | `>=8.1` |
| State | Version | Branch | Nette | PHP |
|-------------|---------|----------|--------|---------|
| dev | `^0.2` | `master` | `3.2+` | `>=8.2` |
| stable | `^0.1` | `master` | `3.2+` | `>=8.1` |

## Development

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"nette/utils": "^4.0.0"
},
"require-dev": {
"contributte/qa": "^0.4",
"contributte/tester": "^0.4",
"contributte/phpstan": "^0.2",
"contributte/qa": "^0.4.0",
"contributte/tester": "^0.4.0",
"contributte/phpstan": "^0.2.0",
"tracy/tracy": "^2.11.0",
"symfony/yaml": "^6.4.0 || ^7.0.0 || ^8.0.0"
},
Expand Down
4 changes: 1 addition & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ includes:
- vendor/contributte/phpstan/phpstan.neon

parameters:
level: 8
level: 9
phpVersion: 80200

scanDirectories:
Expand All @@ -14,5 +14,3 @@ parameters:
paths:
- src
- .docs

ignoreErrors:
56 changes: 41 additions & 15 deletions src/Schema/Components.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,65 +38,85 @@ class Components
private ?VendorExtensions $vendorExtensions = null;

/**
* @param mixed[] $data
* @param array{schemas?: array<string, mixed[]>, responses?: array<string, mixed[]>, parameters?: array<string, mixed[]>, examples?: array<string, mixed[]>, requestBodies?: array<string, mixed[]>, headers?: array<string, mixed[]>, securitySchemes?: array<string, mixed[]>, links?: array<string, mixed[]>, callbacks?: array<string, mixed[]>, pathItems?: array<string, mixed[]>} $data
*/
public static function fromArray(array $data): Components
{
$components = new Components();

foreach ($data['schemas'] ?? [] as $schemaKey => $schemaData) {
/** @var array<string, mixed[]> $schemas */
$schemas = $data['schemas'] ?? [];
foreach ($schemas as $schemaKey => $schemaData) {
if (isset($schemaData['$ref'])) {
$components->setSchema($schemaKey, Reference::fromArray($schemaData));
} else {
$components->setSchema($schemaKey, Schema::fromArray($schemaData));
}
}

foreach ($data['responses'] ?? [] as $responseKey => $responseData) {
/** @var array<string, mixed[]> $responses */
$responses = $data['responses'] ?? [];
foreach ($responses as $responseKey => $responseData) {
if (isset($responseData['$ref'])) {
$components->setResponse((string) $responseKey, Reference::fromArray($responseData));
$components->setResponse($responseKey, Reference::fromArray($responseData));
} else {
$components->setResponse((string) $responseKey, Response::fromArray($responseData));
/** @var array{description: string, headers?: array<string, mixed[]>, content?: array<string, mixed[]>, links?: array<string, mixed[]>} $response */
$response = $responseData;
$components->setResponse($responseKey, Response::fromArray($response));
}
}

foreach ($data['parameters'] ?? [] as $parameterKey => $parameterData) {
if (isset($parameterData['$ref'])) {
$components->setParameter($parameterKey, Reference::fromArray($parameterData));
} else {
$components->setParameter($parameterKey, Parameter::fromArray($parameterData));
/** @var array{name: string, in: string, description?: string, required?: bool, deprecated?: bool, allowEmptyValue?: bool, style?: string, explode?: bool, allowReserved?: bool, schema?: mixed[], example?: mixed, examples?: array<string, mixed[]>} $param */
$param = $parameterData;
$components->setParameter($parameterKey, Parameter::fromArray($param));
}
}

foreach ($data['examples'] ?? [] as $exampleKey => $exampleData) {
if (isset($exampleData['$ref'])) {
$components->setExample($exampleKey, Reference::fromArray($exampleData));
} else {
$components->setExample($exampleKey, Example::fromArray($exampleData));
/** @var array{summary?: string, description?: string, value?: mixed, externalValue?: string} $example */
$example = $exampleData;
$components->setExample($exampleKey, Example::fromArray($example));
}
}

foreach ($data['requestBodies'] ?? [] as $requestBodyKey => $requestBodyData) {
/** @var array<string, mixed[]> $requestBodies */
$requestBodies = $data['requestBodies'] ?? [];
foreach ($requestBodies as $requestBodyKey => $requestBodyData) {
if (isset($requestBodyData['$ref'])) {
$components->setRequestBody($requestBodyKey, Reference::fromArray($requestBodyData));
} else {
$components->setRequestBody($requestBodyKey, RequestBody::fromArray($requestBodyData));
/** @var array{description?: string, content?: array<string, mixed[]>, required?: bool} $requestBody */
$requestBody = $requestBodyData;
$components->setRequestBody($requestBodyKey, RequestBody::fromArray($requestBody));
}
}

foreach ($data['headers'] ?? [] as $headerKey => $headerData) {
if (isset($headerData['$ref'])) {
$components->setHeader($headerKey, Reference::fromArray($headerData));
} else {
$components->setHeader($headerKey, Header::fromArray($headerData));
/** @var array{description?: string, required?: bool, deprecated?: bool, allowEmptyValue?: bool, style?: string, explode?: bool, allowReserved?: bool, schema?: mixed[], example?: mixed, examples?: array<string, mixed[]>} $header */
$header = $headerData;
$components->setHeader($headerKey, Header::fromArray($header));
}
}

foreach ($data['securitySchemes'] ?? [] as $securitySchemeKey => $securitySchemeData) {
/** @var array<string, mixed[]> $securitySchemes */
$securitySchemes = $data['securitySchemes'] ?? [];
foreach ($securitySchemes as $securitySchemeKey => $securitySchemeData) {
if (isset($securitySchemeData['$ref'])) {
$components->setSecurityScheme($securitySchemeKey, Reference::fromArray($securitySchemeData));
} else {
$components->setSecurityScheme($securitySchemeKey, SecurityScheme::fromArray($securitySchemeData));
/** @var array{type: string, description?: string, name?: string, in?: string, scheme?: string, bearerFormat?: string, flows?: array<string, mixed[]>, openIdConnectUrl?: string} $securityScheme */
$securityScheme = $securitySchemeData;
$components->setSecurityScheme($securitySchemeKey, SecurityScheme::fromArray($securityScheme));
}
}

Expand All @@ -112,15 +132,21 @@ public static function fromArray(array $data): Components
if (isset($linkData['$ref'])) {
$components->setLink($linkKey, Reference::fromArray($linkData));
} else {
$components->setLink($linkKey, Link::fromArray($linkData));
/** @var array{operationRef?: string, operationId?: string, parameters?: mixed[], requestBody?: mixed, description?: string, server?: mixed[]} $link */
$link = $linkData;
$components->setLink($linkKey, Link::fromArray($link));
}
}

foreach ($data['pathItems'] ?? [] as $pathItemKey => $pathItemData) {
/** @var array<string, mixed[]> $pathItems */
$pathItems = $data['pathItems'] ?? [];
foreach ($pathItems as $pathItemKey => $pathItemData) {
if (isset($pathItemData['$ref'])) {
$components->setPathItem($pathItemKey, Reference::fromArray($pathItemData));
} else {
$components->setPathItem($pathItemKey, PathItem::fromArray($pathItemData));
/** @var array{get?: mixed[], put?: mixed[], post?: mixed[], delete?: mixed[], options?: mixed[], head?: mixed[], patch?: mixed[], trace?: mixed[], summary?: string, description?: string, servers?: array<mixed[]>, parameters?: array<mixed[]>} $pathItem */
$pathItem = $pathItemData;
$components->setPathItem($pathItemKey, PathItem::fromArray($pathItem));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Schema/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Contact
private ?VendorExtensions $vendorExtensions = null;

/**
* @param mixed[] $data
* @param array{name?: string, url?: string, email?: string} $data
*/
public static function fromArray(array $data): Contact
{
Expand Down
10 changes: 7 additions & 3 deletions src/Schema/Encoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@ class Encoding
private ?VendorExtensions $vendorExtensions = null;

/**
* @param mixed[] $data
* @param array{contentType?: string, headers?: array<string, mixed[]>, style?: string, explode?: bool, allowReserved?: bool} $data
*/
public static function fromArray(array $data): self
{
$encoding = new Encoding();

$encoding->contentType = $data['contentType'] ?? null;
/** @var string|null $contentType */
$contentType = $data['contentType'] ?? null;
$encoding->contentType = $contentType;

foreach ($data['headers'] ?? [] as $name => $header) {
if (isset($header['$ref'])) {
$encoding->addHeader($name, Reference::fromArray($header));
} else {
$encoding->addHeader($name, Header::fromArray($header));
/** @var array{description?: string, required?: bool, deprecated?: bool, allowEmptyValue?: bool, style?: string, explode?: bool, allowReserved?: bool, schema?: mixed[], example?: mixed, examples?: array<string, mixed[]>} $headerData */
$headerData = $header;
$encoding->addHeader($name, Header::fromArray($headerData));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Schema/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Example
private ?VendorExtensions $vendorExtensions = null;

/**
* @param mixed[] $data
* @param array{summary?: string, description?: string, value?: mixed, externalValue?: string} $data
*/
public static function fromArray(array $data): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/ExternalDocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(string $url)
}

/**
* @param mixed[] $data
* @param array{url: string, description?: string} $data
*/
public static function fromArray(array $data): ExternalDocumentation
{
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Header
private array $examples = [];

/**
* @param mixed[] $data
* @param array{description?: string, required?: bool, deprecated?: bool, allowEmptyValue?: bool, style?: string, explode?: bool, allowReserved?: bool, schema?: mixed[], example?: mixed, examples?: mixed[]} $data
*/
public static function fromArray(array $data): Header
{
Expand Down
21 changes: 18 additions & 3 deletions src/Schema/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,31 @@ public function __construct(string $title, string $version)
}

/**
* @param mixed[] $data
* @param array{title: string, version: string, summary?: string, description?: string, termsOfService?: string, license?: mixed[], contact?: mixed[]} $data
*/
public static function fromArray(array $data): Info
{
$info = new Info($data['title'], $data['version']);
$info->setSummary($data['summary'] ?? null);
$info->setDescription($data['description'] ?? null);
$info->setTermsOfService($data['termsOfService'] ?? null);
$info->setLicense(isset($data['license']) ? License::fromArray($data['license']) : null);
$info->setContact(isset($data['contact']) ? Contact::fromArray($data['contact']) : null);

if (isset($data['license'])) {
/** @var array{name: string, identifier?: string, url?: string} $license */
$license = $data['license'];
$info->setLicense(License::fromArray($license));
} else {
$info->setLicense(null);
}

if (isset($data['contact'])) {
/** @var array{name?: string, url?: string, email?: string} $contact */
$contact = $data['contact'];
$info->setContact(Contact::fromArray($contact));
} else {
$info->setContact(null);
}

$info->setVendorExtensions(VendorExtensions::fromArray($data));

return $info;
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(string $name)
}

/**
* @param mixed[] $data
* @param array{name: string, identifier?: string, url?: string} $data
*/
public static function fromArray(array $data): License
{
Expand Down
12 changes: 10 additions & 2 deletions src/Schema/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Link
private ?VendorExtensions $vendorExtensions = null;

/**
* @param mixed[] $data
* @param array{operationRef?: string, operationId?: string, parameters?: mixed[], requestBody?: mixed, description?: string, server?: mixed[]} $data
*/
public static function fromArray(array $data): Link
{
Expand All @@ -31,7 +31,15 @@ public static function fromArray(array $data): Link
$link->setParameters($data['parameters'] ?? []);
$link->setRequestBody($data['requestBody'] ?? null);
$link->setDescription($data['description'] ?? null);
$link->setServer(isset($data['server']) ? Server::fromArray($data['server']) : null);

if (isset($data['server'])) {
/** @var array{url: string, description?: string, variables?: array<string, mixed[]>} $server */
$server = $data['server'];
$link->setServer(Server::fromArray($server));
} else {
$link->setServer(null);
}

$link->setVendorExtensions(VendorExtensions::fromArray($data));

return $link;
Expand Down
Loading
Loading