-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Swagger UI - view the generated docs #18
Comments
This is a great suggestion, I’ll look into how difficult this would be. I’m guessing there’s something out there that does this already but it would definitely make sense being part of the lib |
@mtrajano yes there's this package |
@lexxyungcarter thanks for the pointer I was unsure about this as I thought you needed js to build the files but it looks like Swagger provides bundled js files as a composer package that can be added in a package view file. I will look into this as soon as I’m done working on the securityDefinitions issue #17. Feel free to take a stab at it if you can get to it before me, thank you! |
I think ideally this should be a separate command, say |
Yes. That seems right to me. Or even better, publish the view assrts to reources/views/vendor just as other packages such as laravel horizon, mailables, e.t.c. |
Can't wait for the next release of Laravel Swagger! @mtrajano Is it just me or is there an an issue with 'reading' the type-hinted Requests in the controller? Of late, I can't seem to get mine showing the parameters in the docs. |
@lexxyungcarter me neither, a lot of exciting stuff coming! And that’s weird if you typehint a FormRequest instance in your controller action it should automatically generate the request params for you, it does that based on the rules array you define. Are you getting some sort of error when running or is it just not picking it up? If you share a specific file it might help when looking into it, additionally you can also take a look at the test files for some examples, thanks! |
@mtrajano No errors pop up, it's just not picking up. Here's an example: /**
* create a new contact message
*
* @param ContactMessageRequest $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function store(ContactMessageRequest $request)
{
$response = $this->repo->create(true);
if($response)
return response()->json([
'message' => 'Thank you for your message. We will keep in touch.',
'alert' => 'success',
], 200);
return response()->json([
'message' => 'There was an error sending your message. Please try again or refresh the page.',
'alert' => 'error',
], 422);
} Request <?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ContactMessageRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'concern_id' => 'nullable|numeric',
'name' => 'required|string|max:255',
'email' => 'required|email|max:255',
'phone' => 'required|max:20',
'body' => 'required|max:500',
'country_id' => 'nullable|numeric|exists:countries,id',
];
}
} I have a command that calls the laravel swagger command, which is: $this->call('laravel-swagger:generate', [
'--filter' => '/api',
'--output' => 'storage/api-docs/api-docs.json',
]); However, the generated docs becomes: "\/api\/contact-messages": {
"get": {
"summary": "return all",
"description": "",
"deprecated": false,
"responses": {
"200": {
"description": "OK"
}
}
},
"post": {
"summary": "create a new contact message",
"description": "",
"deprecated": false,
"responses": {
"200": {
"description": "OK"
}
}
}
}, As for the other routes, the route parameters get passed as expected, but not the type-hinted Requests. Any clue on what could be wrong? Thank you. |
Hey, appologies for the late response. It looks like there was a pull request fixing something similar to what you're saying. Would mind upgrading to |
Hey I'm sorry I just got a chance to look at this, a fix has been pushed to master. If you're curious this was the fix: 9c9e10a it broke during the last pr when someone tried fixing something unrelated. Give it a try and let me know if it works, I'm going to push some other minor things and then release |
Wallah! It works now! |
No description provided.
The text was updated successfully, but these errors were encountered: