Skip to content

Commit

Permalink
style: fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
Rocksheep authored and github-actions[bot] committed Jan 31, 2025
1 parent 02757bd commit f6d6c90
Show file tree
Hide file tree
Showing 79 changed files with 603 additions and 1,061 deletions.
3 changes: 0 additions & 3 deletions src/Builders/InfoBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

class InfoBuilder extends Builder
{
/**
* @return Info
*/
public function build(): Info
{
return (new Server($this->generator))->info();
Expand Down
22 changes: 10 additions & 12 deletions src/Builders/Paths/Operation/ParameterBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
class ParameterBuilder extends Builder
{
/**
* @param Route $route
*
* @return \GoldSpecDigital\ObjectOrientedOAS\Objects\Parameter[]
*/
public function build(Route $route): array
Expand All @@ -40,19 +38,19 @@ public function build(Route $route): array
if (isset($route->route()->defaults[\LaravelJsonApi\Laravel\Routing\Route::RESOURCE_ID_NAME])) {
$id = $route->route()->defaults[\LaravelJsonApi\Laravel\Routing\Route::RESOURCE_ID_NAME];
$examples = collect($this->generator->resources()
->resources($route->schema()::model()))
->map(function ($resource) {
$id = $resource->id();
->resources($route->schema()::model()))
->map(function ($resource) {
$id = $resource->id();

return Example::create($id)->value($id);
})->toArray();
return Example::create($id)->value($id);
})->toArray();

$parameters[] = Parameter::path($id)
->name($id)
->required(true)
->allowEmptyValue(false)
->examples(...$examples)
->schema(OASchema::string());
->name($id)
->required(true)
->allowEmptyValue(false)
->examples(...$examples)
->schema(OASchema::string());
}

return $parameters;
Expand Down
2 changes: 0 additions & 2 deletions src/Builders/Paths/Operation/RequestBodyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public function build(Route $route): ?RequestBody
}

/**
* @param Route $route
*
* @return Descriptors\Actions\ActionDescriptor|null
*/
protected function getDescriptor(Route $route): ?RequestDescriptor
Expand Down
212 changes: 103 additions & 109 deletions src/Builders/Paths/Operation/ResponseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,30 @@ public function build(Route $route): array
}

/**
* @param Schema $data
* @param Schema|null $meta
* @param Schema|null $links
* @param Schema $data
*
* @throws \GoldSpecDigital\ObjectOrientedOAS\Exceptions\InvalidArgumentException
*
* @return Schema
*/
public static function buildResponse(
SchemaContract $data,
?Schema $meta = null,
?Schema $links = null,
): Schema {
$jsonapi = Schema::object('jsonapi')
->properties(Schema::string('version')
->title('version')
->example('1.0')
);
->properties(Schema::string('version')
->title('version')
->example('1.0')
);

$schemas = collect([$jsonapi, $data, $meta, $links])
->whereNotNull()->toArray();
->whereNotNull()->toArray();

return Schema::object()
->properties(...$schemas)
->required('jsonapi', 'data');
->properties(...$schemas)
->required('jsonapi', 'data');
}

/**
* @param Route $route
*
* @return \LaravelJsonApi\OpenApiSpec\Descriptors\Actions\ActionDescriptor|null
*/
protected function getDescriptor(Route $route): ?Responses\ResponseDescriptor
Expand All @@ -117,118 +111,118 @@ protected function addDefaults(): void
{
$this->jsonapi = $this->components->addSchema(
Schema::object('helper.jsonapi')
->title('Helper/JSONAPI')
->properties(Schema::string('version')
->title('version')
->example('1.0')
)
->required('version')
->title('Helper/JSONAPI')
->properties(Schema::string('version')
->title('version')
->example('1.0')
)
->required('version')
);

$errors = $this->components->addSchema(
Schema::array('helper.errors')
->title('Helper/Errors')
->items(Schema::object('error')
->title('Error')
->properties(
Schema::string('detail'),
Schema::string('status'),
Schema::string('title'),
Schema::object('source')
->properties(Schema::string('pointer'))
->title('Helper/Errors')
->items(Schema::object('error')
->title('Error')
->properties(
Schema::string('detail'),
Schema::string('status'),
Schema::string('title'),
Schema::object('source')
->properties(Schema::string('pointer'))
)
->required('status', 'title')
)
->required('status', 'title')
)
);
$errorBody = Schema::object()->properties($this->jsonapi, $errors);
$this->defaults = collect([
Response::badRequest('400')
->description('Bad request')
->content(
MediaType::create()
->mediaType(MediaTypeInterface::JSON_API_MEDIA_TYPE)
->schema($errorBody)
->examples(Example::create('-')->value([
'jsonapi' => [
'version' => '1.0',
],
'errors' => [
[
'detail' => 'The member id is required.',
'source' => ['pointer' => '/data'],
'status' => '400',
'title' => 'Non-Compliant JSON:API Document',
->description('Bad request')
->content(
MediaType::create()
->mediaType(MediaTypeInterface::JSON_API_MEDIA_TYPE)
->schema($errorBody)
->examples(Example::create('-')->value([
'jsonapi' => [
'version' => '1.0',
],
],
])
)
),
'errors' => [
[
'detail' => 'The member id is required.',
'source' => ['pointer' => '/data'],
'status' => '400',
'title' => 'Non-Compliant JSON:API Document',
],
],
])
)
),
Response::unauthorized('401')
->description('Unauthorized Action')
->content(
MediaType::create()
->mediaType(MediaTypeInterface::JSON_API_MEDIA_TYPE)
->schema($errorBody)
->examples(Example::create('-')->value([
'jsonapi' => [
'version' => '1.0',
],
'errors' => [
[
'title' => 'Unauthorized.',
'status' => '401',
'detail' => 'Unauthenticated.',
->description('Unauthorized Action')
->content(
MediaType::create()
->mediaType(MediaTypeInterface::JSON_API_MEDIA_TYPE)
->schema($errorBody)
->examples(Example::create('-')->value([
'jsonapi' => [
'version' => '1.0',
],
],
])
)
),
'errors' => [
[
'title' => 'Unauthorized.',
'status' => '401',
'detail' => 'Unauthenticated.',
],
],
])
)
),
Response::notFound('404')
->description('Content Not Found')
->content(
MediaType::create()
->mediaType(MediaTypeInterface::JSON_API_MEDIA_TYPE)
->schema($errorBody)
->examples(Example::create('-')->value([
'jsonapi' => [
'version' => '1.0',
],
'errors' => [
[
'title' => 'Not Found',
'status' => '404',
->description('Content Not Found')
->content(
MediaType::create()
->mediaType(MediaTypeInterface::JSON_API_MEDIA_TYPE)
->schema($errorBody)
->examples(Example::create('-')->value([
'jsonapi' => [
'version' => '1.0',
],
],
])
)
),
'errors' => [
[
'title' => 'Not Found',
'status' => '404',
],
],
])
)
),
Response::unprocessableEntity('422')
->statusCode(422)
->description('Unprocessable Entity')
->content(
MediaType::create()
->mediaType(MediaTypeInterface::JSON_API_MEDIA_TYPE)
->schema($errorBody)
->examples(Example::create('-')->value([
'jsonapi' => [
'version' => '1.0',
],
'errors' => [
[
'detail' => 'Lorem Ipsum',
'source' => ['pointer' => '/data/attributes/lorem'],
'title' => 'Unprocessable Entity',
'status' => '422',
->statusCode(422)
->description('Unprocessable Entity')
->content(
MediaType::create()
->mediaType(MediaTypeInterface::JSON_API_MEDIA_TYPE)
->schema($errorBody)
->examples(Example::create('-')->value([
'jsonapi' => [
'version' => '1.0',
],
],
])
)
),
'errors' => [
[
'detail' => 'Lorem Ipsum',
'source' => ['pointer' => '/data/attributes/lorem'],
'title' => 'Unprocessable Entity',
'status' => '422',
],
],
])
)
),
])
->mapWithKeys(function (Response $response) {
$ref = $this->components->addResponse($response);
->mapWithKeys(function (Response $response) {
$ref = $this->components->addResponse($response);

return [$response->objectId => $ref];
});
return [$response->objectId => $ref];
});
}
}
Loading

0 comments on commit f6d6c90

Please sign in to comment.