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
2 changes: 1 addition & 1 deletion src/Parsers/DefaultLaravelAttributeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function handleBoolean(Parameter $parameter): void

$schema = new Schema($is_not_json ? Schema::INTEGER_TYPE : Schema::BOOLEAN_TYPE);

if($is_not_json) {
if ($is_not_json) {
$schema->setMinimum(0);
$schema->setMaximum(1);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Parsers/DefaultLaravelResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class DefaultLaravelResponseParser implements ParsesResponse
*/
public function __invoke(?Schema $schema, ReflectionClass $response): ?Schema
{
if (!$response->getName()) {
if (! $response->getName()) {
return null;
}

if (!$this->isJsonResource($response)) {
if (! $this->isJsonResource($response)) {
return null;
}

Expand All @@ -42,7 +42,7 @@ public function __invoke(?Schema $schema, ReflectionClass $response): ?Schema

protected function getProperties(array $parameters): ?PropertiesCollection
{
if(empty($parameters)) {
if (empty($parameters)) {
return null;
}

Expand All @@ -64,4 +64,4 @@ protected function isResourceCollection(ReflectionClass $class): bool
{
return $class->isSubclassOf(ResourceCollection::class);
}
}
}
24 changes: 11 additions & 13 deletions src/Services/SwaggerGeneratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
use Smoggert\SwaggerGenerator\Exceptions\SwaggerGeneratorException;
use Smoggert\SwaggerGenerator\Interfaces\ParsesParameter;
use Smoggert\SwaggerGenerator\Interfaces\ParsesResponse;
use Smoggert\SwaggerGenerator\SwaggerDefinitions\Content;
use Smoggert\SwaggerGenerator\SwaggerDefinitions\Parameter;
use Smoggert\SwaggerGenerator\SwaggerDefinitions\Request;
use Smoggert\SwaggerGenerator\SwaggerDefinitions\Response;
use Smoggert\SwaggerGenerator\SwaggerDefinitions\Content;
use Smoggert\SwaggerGenerator\SwaggerDefinitions\Schema;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
Expand Down Expand Up @@ -60,12 +60,12 @@ class SwaggerGeneratorService
protected array $apis = [];

/**
* @var $parsers string[]
* @var string[]
*/
protected array $parsers = [];

/**
* @var $parsers string[]
* @var string[]
*/
protected array $response_parsers = [];

Expand Down Expand Up @@ -523,7 +523,7 @@ protected function createRequestBodyComponent(ReflectionClass $class): string
*/
protected function createResponseBodyFromJsonResource(?ReflectionType $type): ?Schema
{
if(! $type) {
if (! $type) {
return null;
}

Expand All @@ -541,7 +541,7 @@ protected function createResponseBodyFromJsonResource(?ReflectionType $type): ?S
*/
$parser = new $parser_class;

if(! $parser instanceof ParsesResponse) {
if (! $parser instanceof ParsesResponse) {
throw new SwaggerGeneratorException("Parser configuration [$parser_class] does not implement [ParsesResponse].");
}

Expand Down Expand Up @@ -704,7 +704,7 @@ protected function parseParameter(Parameter $query_parameter, string $context):

$parser = new $parser_class;

if(! $parser instanceof ParsesParameter) {
if (! $parser instanceof ParsesParameter) {
throw new SwaggerGeneratorException("Parser configuration [$parser_class] does not implement [ParsesParameter].");
}

Expand Down Expand Up @@ -745,7 +745,7 @@ protected function getResponses(Route $route, string $verb): array

$response = $this->generateResponse($route);

if(! empty($response)) {
if (! empty($response)) {
$responses = array_merge($responses, $response);
}

Expand All @@ -760,7 +760,7 @@ protected function generateResponse(Route $route): array
{
$method = $this->getRouteMethod($route);

if (!$method) {
if (! $method) {
return [];
}

Expand All @@ -770,13 +770,13 @@ protected function generateResponse(Route $route): array

$response_class_name = $reflection_class?->getName();

if (!$response_class_name) {
if (! $response_class_name) {
return [];
}

$schema_name = $this->trimResourcePath($reflection_class->getName());

if (!$this->hasSchema($schema_name)) {
if (! $this->hasSchema($schema_name)) {
$response_schema = $this->createResponseBodyFromJsonResource($reflection_type);

if ($response_schema) {
Expand All @@ -793,7 +793,7 @@ protected function generateResponse(Route $route): array
);

return [
$this->wrapString($this->getStatusCode($reflection_type)) => $response->toArray()
$this->wrapString($this->getStatusCode($reflection_type)) => $response->toArray(),
];
}

Expand All @@ -802,8 +802,6 @@ protected function hasSchema(string $schema_key): bool
return isset($this->schemas[$schema_key]);
}



/**
* @throws ReflectionException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/SwaggerDefinitions/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Content implements Arrayable

public function setJsonSchema(string $json_schema): void
{
$this->schemas[ 'application/json'] = $json_schema;
$this->schemas['application/json'] = $json_schema;
}

public function seFormUrlEncodedSchema(string $form_url_encoded_schema): void
Expand Down
2 changes: 1 addition & 1 deletion src/SwaggerDefinitions/PropertiesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function add(string $name, Schema $schema, bool $required = false): void
{
$this->properties[$name] = $schema;

if($required) {
if ($required) {
$this->required[] = $name;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/SwaggerDefinitions/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class Request implements Arrayable
{
use HasToArray;

public function __construct(protected string|null $description, protected Content $content)
{
}
Expand Down
1 change: 1 addition & 0 deletions src/SwaggerDefinitions/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class Response implements Arrayable
{
use HasToArray;

public function __construct(protected string $description, protected Content $content)
{
}
Expand Down