generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from dedoc/pr/WildEgo-main
Image and file validator support, request @mediaType tag support
- Loading branch information
Showing
5 changed files
with
136 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
tests/Support/OperationExtensions/RequestBodyExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Route as RouteFacade; | ||
|
||
it('uses application/json media type as a default request media type', function () { | ||
$openApiDocument = generateForRoute(function () { | ||
return RouteFacade::post('api/test', [RequestBodyExtensionTest__uses_application_json_as_default::class, 'index']); | ||
}); | ||
|
||
expect($openApiDocument['paths']['/test']['post']['requestBody']['content']) | ||
->toHaveKey('application/json') | ||
->toHaveLength(1); | ||
}); | ||
class RequestBodyExtensionTest__uses_application_json_as_default | ||
{ | ||
public function index(Illuminate\Http\Request $request) | ||
{ | ||
$request->validate(['foo' => 'string']); | ||
} | ||
} | ||
|
||
it('allows manually defining a request media type', function () { | ||
$openApiDocument = generateForRoute(function () { | ||
return RouteFacade::post('api/test', [RequestBodyExtensionTest__allows_manual_request_media_type::class, 'index']); | ||
}); | ||
|
||
expect($openApiDocument['paths']['/test']['post']['requestBody']['content']) | ||
->toHaveKey('application/xml') | ||
->toHaveLength(1); | ||
}); | ||
class RequestBodyExtensionTest__allows_manual_request_media_type | ||
{ | ||
/** | ||
* @requestMediaType application/xml | ||
*/ | ||
public function index(Illuminate\Http\Request $request) | ||
{ | ||
$request->validate(['foo' => 'string']); | ||
} | ||
} | ||
|
||
it('automatically infers multipart/form-data as request media type when some of body params is binary', function () { | ||
$openApiDocument = generateForRoute(function () { | ||
return RouteFacade::post('api/test', [RequestBodyExtensionTest__automaticall_infers_form_data::class, 'index']); | ||
}); | ||
|
||
expect($openApiDocument['paths']['/test']['post']['requestBody']['content']) | ||
->toHaveKey('multipart/form-data') | ||
->toHaveLength(1); | ||
}); | ||
class RequestBodyExtensionTest__automaticall_infers_form_data | ||
{ | ||
public function index(Illuminate\Http\Request $request) | ||
{ | ||
$request->validate(['foo' => 'file']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters