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
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ class Controller {
public function get(#[Parameter("Parameter description")] int $id): JsonResponse {
// ...
}

#[
DynamicBuilder(MyFrameworkResolver::class),
Property(PropertyType::REF, "prop4", ref: RefSchema::class)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some properties as an example that DynamicBuilder can be used together with other attributes.

Response(ref: SchemaName::class, description: "Response description")
]
public function getSomethingElse(#[Parameter("Parameter description")] int $id): JsonResponse {
// ...
}
}

#[
Expand Down Expand Up @@ -119,3 +128,17 @@ Will generate
}
}
```

```
class MyFrameworkResolver
{
public function build(PathMethodBuilder $pathBuilder, $instance, $parameters, $reflectionClass, $method)
{
// Here you can add your own logic to build the path
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some rubbish code...

// How to add dependencies? Laravel uses global container so it can be done like this:
$route = Routes::getRoutes()->findByControllerAndMethodName()->getUri();

$pathBuilder->setRoute($route);
}
}
```
15 changes: 15 additions & 0 deletions src/Attributes/DynamicBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace OpenApiGenerator\Attributes;

use Attribute;
use JetBrains\PhpStorm\Pure;

#[Attribute]
class DynamicBuilder {
public static function getBuilder() {
// Make instance of external resolver and pass all the required parameters
}
}
3 changes: 3 additions & 0 deletions src/GeneratorHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace OpenApiGenerator;

use OpenApiGenerator\Attributes\DELETE;
use OpenApiGenerator\Attributes\DynamicBuilder;
use OpenApiGenerator\Attributes\DynamicRoute;
use OpenApiGenerator\Attributes\GET;
use OpenApiGenerator\Attributes\MediaProperty;
use OpenApiGenerator\Attributes\Parameter;
Expand Down Expand Up @@ -72,6 +74,7 @@ public function append(ReflectionClass $reflectionClass)
PUT::class,
DELETE::class,
PATCH::class => $pathBuilder->setRoute($instance, $parameters),
DynamicBuilder::class => DynamicBuilder::getBuilder()->build($pathBuilder, $instance, $parameters, $reflectionClass, $method),
RequestBody::class => $pathBuilder->setRequestBody($instance),
Property::class => $pathBuilder->addProperty($instance),
PropertyItems::class => $pathBuilder->setPropertyItems($instance),
Expand Down