You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
useweb\rest\{Get, Post, Resource, Response};
#[Resource('/users')]
class Users {
/** * Returns all users. * * - 200: Successful operation */
#[Get('/')]
publicfunctionlistUsers($max= 10) {
// $max comes from request parameter "max", defaulting to 10// ...
}
/** * Returns a given user. * * - 200: Successful operation * - 404: The user cannot be found */
#[Get('/{id}')]
publicfunctionfindUser($id) {
// $id is extracted from URL segment// ...
}
/** * Creates a user. * * - 201: Successful operation * - 400: Validation failed */
#[Post('/')]
publicfunctioncreateUser($user) {
// $user is deserialized from the request body according to its content type// ...return Response::created('/users/{id}', $id)->entity($created);
}
}
TODO: How do we denote request and response body schemas?
200+UserList: Successful operation and then have UserList defined in the class' api doc?
Implementation
Using the unpkg CDN, we could simply serve the following from /api:
See also https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/installation.md#unpkg
We then need to decide how we want to create the
openapi.json
file:Generate from API docs
Use YAML embedded in the api doc comments like https://github.com/Surnet/swagger-jsdoc:
Generate from annotations
Like this example from https://javascript.plainenglish.io/how-to-implement-and-use-swagger-in-nodejs-d0b95e765245:
(Similar to https://zircote.github.io/swagger-php/)
Mixed approach
We can use some of the annotations here:
TODO: How do we denote request and response body schemas?
200+UserList: Successful operation
and then haveUserList
defined in the class' api doc?(Similar to https://vyuldashev.github.io/laravel-openapi/)
The text was updated successfully, but these errors were encountered: