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: 45 additions & 11 deletions src/Schema/Components.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,39 +44,57 @@ 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));
$components->setResponse($responseKey, Response::fromArray($responseData));
}
}

foreach ($data['parameters'] ?? [] as $parameterKey => $parameterData) {
if (!is_array($parameterData)) {
continue;
}

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 (!is_array($exampleData)) {
continue;
}

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 {
Expand All @@ -85,14 +103,22 @@ public static function fromArray(array $data): Components
}

foreach ($data['headers'] ?? [] as $headerKey => $headerData) {
if (!is_array($headerData)) {
continue;
}

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 {
Expand All @@ -109,14 +135,22 @@ public static function fromArray(array $data): Components
}

foreach ($data['links'] ?? [] as $linkKey => $linkData) {
if (!is_array($linkData)) {
continue;
}

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?: array{url: string, description?: string, variables?: array<string, array{default: string, enum?: array<string>, description?: string}>}} $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 {
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
12 changes: 10 additions & 2 deletions src/Schema/Encoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@ 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 (!is_array($header)) {
continue;
}

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
2 changes: 1 addition & 1 deletion src/Schema/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(string $title, string $version)
}

/**
* @param mixed[] $data
* @param array{title: string, version: string, summary?: string, description?: string, termsOfService?: string, license?: array{name: string, identifier?: string, url?: string}, contact?: array{name?: string, url?: string, email?: string}} $data
*/
public static function fromArray(array $data): 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
2 changes: 1 addition & 1 deletion 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?: array{url: string, description?: string, variables?: array<string, array{default: string, enum?: string[], description?: string}>}} $data
*/
public static function fromArray(array $data): Link
{
Expand Down
36 changes: 22 additions & 14 deletions src/Schema/MediaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,38 @@ public static function fromArray(array $data): MediaType
$mediaType = new MediaType();

if (isset($data['schema'])) {
if (isset($data['schema']['$ref'])) {
$mediaType->setSchema(Reference::fromArray($data['schema']));
/** @var mixed[] $schema */
$schema = $data['schema'];
if (isset($schema['$ref'])) {
$mediaType->setSchema(Reference::fromArray($schema));
} else {
$mediaType->setSchema(Schema::fromArray($data['schema']));
$mediaType->setSchema(Schema::fromArray($schema));
}
}

$mediaType->setExample($data['example'] ?? null);

if (isset($data['examples'])) {
foreach ($data['examples'] as $name => $example) {
if (isset($example['$ref'])) {
$mediaType->addExample($name, Reference::fromArray($example));
} else {
$mediaType->addExample($name, Example::fromArray($example));
}
foreach ($data['examples'] ?? [] as $name => $example) {
if (!is_array($example)) {
continue;
}

if (isset($example['$ref'])) {
$mediaType->addExample($name, Reference::fromArray($example));
} else {
/** @var array{summary?: string, description?: string, value?: mixed, externalValue?: string} $exampleData */
$exampleData = $example;
$mediaType->addExample($name, Example::fromArray($exampleData));
}
}

foreach ($data['encoding'] ?? [] as $name => $encoding) {
if (isset($encoding['$ref'])) {
$mediaType->addEncoding($name, Reference::fromArray($encoding));
/** @var array<string, mixed[]> $encoding */
$encoding = $data['encoding'] ?? [];
foreach ($encoding as $name => $encodingItem) {
if (isset($encodingItem['$ref'])) {
$mediaType->addEncoding($name, Reference::fromArray($encodingItem));
} else {
$mediaType->addEncoding($name, Encoding::fromArray($encoding));
$mediaType->addEncoding($name, Encoding::fromArray($encodingItem));
}
}

Expand Down
Loading
Loading