Giter VIP home page Giter VIP logo

openapi-php-attributes's People

Contributors

akiosarkiz avatar boris-glumpler avatar derpgoncz avatar edersoares avatar edineivaldameri avatar lampelk avatar puggan avatar uderline avatar zaneevat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

openapi-php-attributes's Issues

Error when not defined `Server` attribute

img

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()

Allow BackedEnums for OpenApiGenerator\Attributes\Property

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!

Extending functionality

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.

path-parms thats not a function-param?

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)

  • Could you automaticly search for {} in the path, and see if one is missing?
  • Could we have another Attribute, like: PathParameter
    #[
        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

Different outputs generated on different systems

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.

Using ref Property

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.

invalid securityScheme

image

app.swaggerhub.com gives the warning:
should NOT have additional properties additionalProperty: bearerFormat, scheme

Maybe an array_filter() around:

return [
$this->securityKey => [
'type' => $this->type,
'name' => $this->name,
'in' => $this->in,
'bearerFormat' => $this->bearerFormat,
'scheme' => $this->scheme,
],
];

invalid output/json

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?

$schema = stripslashes(json_encode($generator, JSON_PRETTY_PRINT));


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")"
},

Undefined array key "security"

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.