swagger: add security scheme, improve api semantics

master
ALI Hamza 2020-09-10 08:36:02 +07:00
parent 19795153de
commit 66f7df0d67
Signed by: hamza
GPG Key ID: 22473A32291F8CB6
1 changed files with 53 additions and 61 deletions

@ -33,8 +33,8 @@ paths:
tags: tags:
- Auth Endpoints - Auth Endpoints
summary: Logs out a user, making their access token invalid. summary: Logs out a user, making their access token invalid.
requestBody: security:
$ref: '#/components/requestBodies/TokenRequest' - token: []
responses: responses:
200: 200:
description: You have successfully logged out, and your token is now invalid. description: You have successfully logged out, and your token is now invalid.
@ -75,7 +75,7 @@ paths:
$ref: '#/components/responses/ServerError' $ref: '#/components/responses/ServerError'
/users/{username}: /users/{username}:
post: get:
tags: tags:
- User Endpoints - User Endpoints
summary: Get the information for a user. summary: Get the information for a user.
@ -94,7 +94,7 @@ paths:
$ref: '#/components/schemas/User' $ref: '#/components/schemas/User'
/users/{username}/posts: /users/{username}/posts:
post: get:
tags: tags:
- User Endpoints - User Endpoints
- Post Endpoints - Post Endpoints
@ -104,9 +104,11 @@ paths:
in: path in: path
schema: schema:
type: string type: string
- $ref: '#/components/parameters/AfterParam'
- $ref: '#/components/parameters/BeforeParam'
- $ref: '#/components/parameters/LimitParam'
- $ref: '#/components/parameters/CountParam'
summary: Get the list of posts a user has created/submitted. summary: Get the list of posts a user has created/submitted.
requestBody:
$ref: '#/components/requestBodies/Listing'
responses: responses:
200: 200:
description: A list of posts filtered and formatted. description: A list of posts filtered and formatted.
@ -124,7 +126,7 @@ paths:
$ref: '#/components/responses/ServerError' $ref: '#/components/responses/ServerError'
/users/{username}/comments: /users/{username}/comments:
post: get:
tags: tags:
- User Endpoints - User Endpoints
- Comments Endpoints - Comments Endpoints
@ -134,9 +136,11 @@ paths:
in: path in: path
schema: schema:
type: string type: string
- $ref: '#/components/parameters/AfterParam'
- $ref: '#/components/parameters/BeforeParam'
- $ref: '#/components/parameters/LimitParam'
- $ref: '#/components/parameters/CountParam'
summary: Get the list of comments a user has submitted. summary: Get the list of comments a user has submitted.
requestBody:
$ref: '#/components/requestBodies/Listing'
responses: responses:
200: 200:
description: A list of comments filtered and formatted. description: A list of comments filtered and formatted.
@ -157,6 +161,8 @@ paths:
post: post:
tags: tags:
- Post Endpoints - Post Endpoints
security:
- token: []
requestBody: requestBody:
description: Submit a new post with this endpoint. description: Submit a new post with this endpoint.
required: true required: true
@ -164,18 +170,14 @@ paths:
application/json: application/json:
schema: schema:
required: required:
- token
- title - title
properties: properties:
token:
description: The access token.
title: title:
description: The title of the post created description: The title of the post created
type: string type: string
description: description:
description: The body text of a post, optional. description: The body text of a post, optional.
example: example:
token: abcdef12345678901234
title: I use arch BTW. title: I use arch BTW.
description: Ladies, I'm waiting. description: Ladies, I'm waiting.
responses: responses:
@ -196,8 +198,41 @@ paths:
$ref: '#/components/responses/Unprocessable' $ref: '#/components/responses/Unprocessable'
500: 500:
$ref: '#/components/responses/ServerError' $ref: '#/components/responses/ServerError'
components: components:
parameters:
AfterParam:
name: after
in: query
description: Date after which to return items.
schema:
type: string
format: 'date-time'
example: 2020-01-01T00:00:00.000z
BeforeParam:
name: before
in: query
description: Date before which to return items.
schema:
type: string
format: 'date-time'
example: 2030-01-01T00:00:00.000z
LimitParam:
name: limit
in: query
description: Maximimum number of items to return
schema:
type: integer
maximum: 100
minimum: 0
CountParam:
name: count
in: query
description: The number of items already seen in this listing. Items will always be sorted by newest first.
schema:
type: integer
default: 0
minimum: 0
requestBodies: requestBodies:
AuthCredentials: AuthCredentials:
description: User credentials. description: User credentials.
@ -216,24 +251,6 @@ components:
password: password:
description: The password of the user. description: The password of the user.
type: string type: string
TokenRequest:
description: The access token to identify a user.
required: true
content:
application/json:
schema:
required:
- token
properties:
token:
description: The access token.
type: string
Listing:
description: Query particular data sorted by date and time.
content:
application/json:
schema:
$ref: '#/components/schemas/Listing'
responses: responses:
MalformedBody: MalformedBody:
description: The information in your body is incomplete, or your JSON format is invalid. description: The information in your body is incomplete, or your JSON format is invalid.
@ -398,32 +415,7 @@ components:
code: code:
description: The HTTP error code value accompanying the error. description: The HTTP error code value accompanying the error.
type: integer type: integer
Listing: securitySchemes:
type: object token:
properties: type: http
after: scheme: bearer
description: Filter items to only return those after this date and time.
type: string
format: 'date-time'
default: 2020-01-01T00:00:00.000z
before:
description: Filter items to only return those before this date and time.
type: string
format: 'date-time'
default: 2030-01-01T00:00:00.000z
count:
description: The number of items already seen in this listing. Items will always be sorted by newest first.
type: integer
minimum: 0
default: 0
limit:
description: The maximum number of items to provide. Can be used in conjunction with 'count' to paginate.
type: integer
maximum: 100
minimum: 0
default: 10
example:
after: 2020-01-01T00:00:00.000z
before: 2030-01-01T00:00:00.000z
count: 0
limit: 10