uderline / openapi-php-attributes Goto Github PK
View Code? Open in Web Editor NEWAutomatically render your OpenApi 3 file describing your PHP API using attributes
Home Page: https://uderline.github.io/openapi-php-attributes/
License: MIT License
Automatically render your OpenApi 3 file describing your PHP API using attributes
Home Page: https://uderline.github.io/openapi-php-attributes/
License: MIT License
Server are not required section.
This test printed output: OpenApiGenerator\DefinitionCheckerException: [Error] Missing field: servers.url in /home/vagrant/code/laravel-packages/openapi-laravel-attributes/vendor/uderline/openapi-php-attributes/src/DefinitionCheckerException.php:13
Stack trace:
#0 /home/vagrant/code/laravel-packages/openapi-laravel-attributes/vendor/uderline/openapi-php-attributes/src/ApiDescriptionChecker.php(60): OpenApiGenerator\DefinitionCheckerException::missingField()
#1 /home/vagrant/code/laravel-packages/openapi-laravel-attributes/vendor/uderline/openapi-php-attributes/src/ApiDescriptionChecker.php(14): OpenApiGenerator\ApiDescriptionChecker->checkServers()
#2 /home/vagrant/code/laravel-packages/openapi-laravel-attributes/vendor/uderline/openapi-php-attributes/src/ApiDescriptionChecker.php(70): OpenApiGenerator\ApiDescriptionChecker->__construct()
It would reduce some duplication if we could also pass a string to the $enum
prop for OpenApiGenerator\Attributes\Property
. Something along the lines of this:
class Property implements PropertyInterface, JsonSerializable
{
public function __construct(
// more params
private null|array|string $enum = null,
// more params
) {
// more code...
}
...
public function jsonSerialize(): array
{
// more code...
if ($this->enum) {
$array['enum'] = $this->enum();
}
// more code...
return $array;
}
private function enum(): ?array
{
if (!is_string($this->enum)) {
return $this->enum;
}
if(!enum_exists($this->enum)) {
return null;
}
return array_map(
static fn(BackedEnum $enum) => $enum->value,
$this->enum::cases()
);
}
}
This would require a minimum PHP version of 8.1, tho, so if you're ok with that, then I could create a PR. Cheers!
Hello, I have a suggestion for a new feature - the ability to extend functionality externally.
Specifically, I would like to be able to resolve route paths based on the settings of the framework I am using, such as Laravel. I think it would be helpful to have a new RouteDynamic
attribute that takes a ResolverClass
as an argument. This ResolverClass could have a method that accepts a $pathBuilder object, which would allow users to customize the route path resolution based on their specific needs. Thank you for considering this suggestion.
I can submit a simple PR as a proof of concept and continue the discussion there.
I have a parameter in my path, but it's not sent as a parameter to the function.
How can i make it generate a valid openapi.json? (without adding an unsued function-parameter)
{}
in the path, and see if one is missing? #[
GET('/api/{version}/web/{market}/airport-list', [], 'List all Airports'),
PathParameter(name: 'version'),
PathParameter(name: 'market'),
Response(schemaType: SchemaType::ARRAY, ref: Airports::class)
]
public function listAirports(): JsonResponse
Hello,
I have been overseeing an app as a tech lead and noticed that different people generate different JSON files.
After a little bit of tinkering with the code, I noticed there is no default sorting while iterating files. The default file order, however, depends on the system. When running on Linux natively, I am getting different file order than when running on Windows using WSL.
The solution to this is outlined in PR #29
Possible conversation would be on how to effectively sort the files. Sorting by file names takes file path into consideration, so same filenames are okay to use.
How to describe nested objects in the request body?
{
"service": "service key",
"shippingAddress": {
"city": "city",
"isTerminal": false
},
"deliveryAddress": {
"city": "city",
"address": "address",
"isTerminal": false
}
}
I tried to implement the following structure:
#[
POST('/delivery/calculation', [], 'Delivery Calculation'),
Property(Type::REF, CalculationRequest::class),
Response(200, ref: CalculationResponse::class)
]
public function calculation(CalculationRequest $request): JsonResponse
{
}
#[
Schema(name: CalculationRequest::class),
Property(PropertyType::STRING, "service"),
Property(PropertyType::OBJECT, "shippingAddress"),
Property(PropertyType::OBJECT, "deliveryAddress"),
]
class CalculationRequest extends JsonRequest implements ValidateRequestInterface
{
private string $service;
private Address $shippingAddress;
private Address $deliveryAddress;
}
I couldn't find anything similar in the documentation. There is an OpenApiGenerator\Attributes\RefProperty class in the source code, but I couldn't use it, maybe it's for other purposes.
app.swaggerhub.com gives the warning:
should NOT have additional properties additionalProperty: bearerFormat, scheme
Maybe an array_filter() around:
openapi-php-attributes/src/Attributes/SecurityScheme.php
Lines 29 to 37 in 6e5be68
if there is a "
inside a desription, the output isn't escaped correctly.
The json_encode make valid json, and then for some odd reason there is a sripslashes applied to it, why?
Line 40 in 6e5be68
from:
#[Property(PropertyType::STRING, 'destination_arrival', 'date("Y-m-d\TH:i:s")')]
expected:
"destination_arrival": {
"type": "string",
"description": "date(\"Y-m-d\\TH:i:s\")"
},
current:
"destination_arrival": {
"type": "string",
"description": "date("Y-m-d\TH:i:s")"
},
Looks like a SecurityScheme is required in the current version,
If you want to enforce using a SecurityScheme, throw your own exception,
or allow apis that have zero SecurityScheme.
PHP Warning: Undefined array key "security" in <project>/vendor/uderline/openapi-php-attributes/src/Generator.php on line 91
PHP Stack trace:
PHP 1. {main}() <project>/vendor/uderline/openapi-php-attributes/opag:0
PHP 2. OpenApiGenerator\Generator->generate() <project>/vendor/uderline/openapi-php-attributes/opag:38
PHP 3. OpenApiGenerator\Generator->makeFinalArray() <project>/vendor/uderline/openapi-php-attributes/src/Generator.php:77
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.