Skip to content

Commit

Permalink
void type correctly transformed to response
Browse files Browse the repository at this point in the history
  • Loading branch information
romalytvynenko committed Jun 20, 2024
1 parent 4987b24 commit 160541b
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/ScrambleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use Dedoc\Scramble\Support\TypeToSchemaExtensions\LengthAwarePaginatorTypeToSchema;
use Dedoc\Scramble\Support\TypeToSchemaExtensions\ModelToSchema;
use Dedoc\Scramble\Support\TypeToSchemaExtensions\ResponseTypeToSchema;
use Dedoc\Scramble\Support\TypeToSchemaExtensions\VoidTypeToSchema;
use PhpParser\ParserFactory;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
Expand Down Expand Up @@ -160,6 +161,7 @@ public function configurePackage(Package $package): void
AnonymousResourceCollectionTypeToSchema::class,
LengthAwarePaginatorTypeToSchema::class,
ResponseTypeToSchema::class,
VoidTypeToSchema::class,
]),
array_merge($exceptionToResponseExtensions, [
ValidationExceptionToResponseExtension::class,
Expand Down
25 changes: 25 additions & 0 deletions src/Support/TypeToSchemaExtensions/VoidTypeToSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Dedoc\Scramble\Support\TypeToSchemaExtensions;

use Dedoc\Scramble\Extensions\TypeToSchemaExtension;
use Dedoc\Scramble\Support\Generator\Response;
use Dedoc\Scramble\Support\Type\Generic;
use Dedoc\Scramble\Support\Type\Type;
use Dedoc\Scramble\Support\Type\VoidType;

class VoidTypeToSchema extends TypeToSchemaExtension
{
public function shouldHandle(Type $type)
{
return $type instanceof VoidType;
}

/**
* @param Generic $type
*/
public function toResponse(Type $type)
{
return Response::make(200);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ info:
servers:
- { url: 'http://localhost/api' }
paths:
/test: { get: { operationId: errorsResponsesTest.addsAuthorizationErrorResponse, tags: [ErrorsResponsesTest_], responses: { 200: { description: '', content: { application/json: { schema: { type: string } } } }, 403: { $ref: '#/components/responses/AuthorizationException' } } } }
/test: { get: { operationId: errorsResponsesTest.addsAuthorizationErrorResponse, tags: [ErrorsResponsesTest_], responses: { 200: { description: '' }, 403: { $ref: '#/components/responses/AuthorizationException' } } } }
components:
responses: { AuthorizationException: { description: 'Authorization error', content: { application/json: { schema: { type: object, properties: { message: { type: string, description: 'Error overview.' } }, required: [message] } } } } }
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ info:
servers:
- { url: 'http://localhost/api' }
paths:
/test: { get: { operationId: errorsResponsesTest.addsErrorsWithCustomRequest, tags: [ErrorsResponsesTest_], parameters: [{ name: foo, in: query, required: true, schema: { type: string } }], responses: { 200: { description: '', content: { application/json: { schema: { type: string } } } }, 422: { $ref: '#/components/responses/ValidationException' }, 403: { $ref: '#/components/responses/AuthorizationException' } } } }
/test: { get: { operationId: errorsResponsesTest.addsErrorsWithCustomRequest, tags: [ErrorsResponsesTest_], parameters: [{ name: foo, in: query, required: true, schema: { type: string } }], responses: { 200: { description: '' }, 422: { $ref: '#/components/responses/ValidationException' }, 403: { $ref: '#/components/responses/AuthorizationException' } } } }
components:
responses: { ValidationException: { description: 'Validation error', content: { application/json: { schema: { type: object, properties: { message: { type: string, description: 'Errors overview.' }, errors: { type: object, description: 'A detailed description of each field that failed validation.', additionalProperties: { type: array, items: { type: string } } } }, required: [message, errors] } } } }, AuthorizationException: { description: 'Authorization error', content: { application/json: { schema: { type: object, properties: { message: { type: string, description: 'Error overview.' } }, required: [message] } } } } }
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ info:
servers:
- { url: 'http://localhost/api' }
paths:
'/test/{user}': { get: { operationId: errorsResponsesTest.addsNotFoundErrorResponse, tags: [ErrorsResponsesTest_], parameters: [{ name: user, in: path, required: true, description: 'The user ID', schema: { type: integer } }], responses: { 200: { description: '', content: { application/json: { schema: { type: string } } } }, 404: { $ref: '#/components/responses/ModelNotFoundException' }, 403: { $ref: '#/components/responses/AuthorizationException' } } } }
'/test/{user}': { get: { operationId: errorsResponsesTest.addsNotFoundErrorResponse, tags: [ErrorsResponsesTest_], parameters: [{ name: user, in: path, required: true, description: 'The user ID', schema: { type: integer } }], responses: { 200: { description: '' }, 404: { $ref: '#/components/responses/ModelNotFoundException' }, 403: { $ref: '#/components/responses/AuthorizationException' } } } }
components:
responses: { ModelNotFoundException: { description: 'Not found', content: { application/json: { schema: { type: object, properties: { message: { type: string, description: 'Error overview.' } }, required: [message] } } } }, AuthorizationException: { description: 'Authorization error', content: { application/json: { schema: { type: object, properties: { message: { type: string, description: 'Error overview.' } }, required: [message] } } } } }
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ info:
servers:
- { url: 'http://localhost/api' }
paths:
/test: { get: { operationId: errorsResponsesTest.addsValidationErrorResponse, tags: [ErrorsResponsesTest_], parameters: [{ name: foo, in: query, required: true, schema: { type: string } }], responses: { 200: { description: '', content: { application/json: { schema: { type: string } } } }, 422: { $ref: '#/components/responses/ValidationException' } } } }
/test: { get: { operationId: errorsResponsesTest.addsValidationErrorResponse, tags: [ErrorsResponsesTest_], parameters: [{ name: foo, in: query, required: true, schema: { type: string } }], responses: { 200: { description: '' }, 422: { $ref: '#/components/responses/ValidationException' } } } }
components:
responses: { ValidationException: { description: 'Validation error', content: { application/json: { schema: { type: object, properties: { message: { type: string, description: 'Errors overview.' }, errors: { type: object, description: 'A detailed description of each field that failed validation.', additionalProperties: { type: array, items: { type: string } } } }, required: [message, errors] } } } } }
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ info:
servers:
- { url: 'http://localhost/api' }
paths:
/test: { get: { operationId: errorsResponsesTest.phpdocExceptionResponse, tags: [ErrorsResponsesTest_], responses: { 200: { description: '', content: { application/json: { schema: { type: string } } } }, 422: { $ref: '#/components/responses/ValidationException' } } } }
/test: { get: { operationId: errorsResponsesTest.phpdocExceptionResponse, tags: [ErrorsResponsesTest_], responses: { 200: { description: '' }, 422: { $ref: '#/components/responses/ValidationException' } } } }
components:
responses: { ValidationException: { description: 'Validation error', content: { application/json: { schema: { type: object, properties: { message: { type: string, description: 'Errors overview.' }, errors: { type: object, description: 'A detailed description of each field that failed validation.', additionalProperties: { type: array, items: { type: string } } } }, required: [message, errors] } } } } }
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ info:
servers:
- { url: 'http://localhost/api' }
paths:
/test: { get: { operationId: errorsResponsesTest.addsValidationErrorResponseWithFacadeMadeValidators, tags: [ErrorsResponsesTest_], parameters: [{ name: foo, in: query, required: true, schema: { type: string } }], responses: { 200: { description: '', content: { application/json: { schema: { type: string } } } }, 422: { $ref: '#/components/responses/ValidationException' } } } }
/test: { get: { operationId: errorsResponsesTest.addsValidationErrorResponseWithFacadeMadeValidators, tags: [ErrorsResponsesTest_], parameters: [{ name: foo, in: query, required: true, schema: { type: string } }], responses: { 200: { description: '' }, 422: { $ref: '#/components/responses/ValidationException' } } } }
components:
responses: { ValidationException: { description: 'Validation error', content: { application/json: { schema: { type: object, properties: { message: { type: string, description: 'Errors overview.' }, errors: { type: object, description: 'A detailed description of each field that failed validation.', additionalProperties: { type: array, items: { type: string } } } }, required: [message, errors] } } } } }
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ info:
servers:
- { url: 'http://localhost/api' }
paths:
/test: { get: { operationId: validationFacadeRulesDocumentingTest.index, tags: [ValidationFacadeRulesDocumenting_Test], parameters: [{ name: content, in: query, required: true, schema: { type: string, enum: [wow] } }], responses: { 200: { description: '', content: { application/json: { schema: { type: string } } } } } } }
/test: { get: { operationId: validationFacadeRulesDocumentingTest.index, tags: [ValidationFacadeRulesDocumenting_Test], parameters: [{ name: content, in: query, required: true, schema: { type: string, enum: [wow] } }], responses: { 200: { description: '' } } } }
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ servers:
security:
- { apiKey: { } }
paths:
/test: { get: { operationId: controllerWithoutSecurity.index, tags: [WithoutSecurity], responses: { 200: { description: '', content: { application/json: { schema: { type: string } } } } }, security: [{ }] } }
/test: { get: { operationId: controllerWithoutSecurity.index, tags: [WithoutSecurity], responses: { 200: { description: '' } }, security: [{ }] } }
components:
securitySchemes: { apiKey: { type: apiKey, in: query, name: api_token } }
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ info:
servers:
- { url: 'http://localhost/api' }
paths:
/test: { get: { operationId: validationRulesAndFormRequestAtTheSameTimeTest.index, tags: [ValidationRulesAndFormRequestAtTheSameTime_Test], parameters: [{ name: from_form_request, in: query, schema: { type: integer } }, { name: from_validate_call, in: query, required: true, schema: { type: string } }], responses: { 200: { description: '', content: { application/json: { schema: { type: string } } } }, 422: { $ref: '#/components/responses/ValidationException' } } } }
/test: { get: { operationId: validationRulesAndFormRequestAtTheSameTimeTest.index, tags: [ValidationRulesAndFormRequestAtTheSameTime_Test], parameters: [{ name: from_form_request, in: query, schema: { type: integer } }, { name: from_validate_call, in: query, required: true, schema: { type: string } }], responses: { 200: { description: '' }, 422: { $ref: '#/components/responses/ValidationException' } } } }
components:
responses: { ValidationException: { description: 'Validation error', content: { application/json: { schema: { type: object, properties: { message: { type: string, description: 'Errors overview.' }, errors: { type: object, description: 'A detailed description of each field that failed validation.', additionalProperties: { type: array, items: { type: string } } } }, required: [message, errors] } } } } }

0 comments on commit 160541b

Please sign in to comment.