Update API spec

+ to use json as post data
+ new SessionSummary component to return as list
This commit is contained in:
wancat committed 2023-07-19 20:00:35 +08:00
1 parent da4b1b18a4
commit 87f5e86108
1 file changed
+139 -236
+139 -236
View File
@@ -1,16 +1,15 @@
---
openapi: 3.0.0 openapi: 3.0.0
servers:
- url: /api/v1
info: info:
title: Session API
description: Linux Odyssey API description: Linux Odyssey API
version: '1.0.0'
title: Session API
contact: contact:
email: wancat@wancat.cc email: wancat@wancat.cc
license: license:
name: Apache 2.0 name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
version: 1.0.0
servers:
- url: /api/v1
tags: tags:
- name: admins - name: admins
description: Secured Admin-only calls description: Secured Admin-only calls
@@ -22,6 +21,14 @@ paths:
tags: tags:
- signed-in - signed-in
summary: list existing sessions of current user summary: list existing sessions of current user
security:
- BearerAuth: []
parameters:
- in: query
name: quest_id
description: find sessions by quest id
schema:
type: string
responses: responses:
'200': '200':
description: list of existing session description: list of existing session
@@ -30,22 +37,23 @@ paths:
schema: schema:
type: array type: array
items: items:
$ref: '#/components/schemas/Session' $ref: '#/components/schemas/SessionSummary'
security:
- BearerAuth: []
post: post:
summary: create a new session for current user
tags: tags:
- signed-in - signed-in
summary: create a new session for current user security:
parameters: - BearerAuth: []
- name: quest_id requestBody:
in: body description: session data
description: pass the quest id content:
required: true application/json:
style: form schema:
explode: true type: object
schema: properties:
type: string quest_id:
type: string
responses: responses:
'201': '201':
description: session created description: session created
@@ -58,21 +66,23 @@ paths:
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/inline_response_400' type: object
security: properties:
- BearerAuth: [] message:
type: string
/sessions/{session_id}: /sessions/{session_id}:
get: get:
tags: tags:
- signed-in - signed-in
summary: get a specific session of current user by ID summary: get a specific session of current user by ID
security:
- BearerAuth: []
parameters: parameters:
- name: session_id - in: path
in: path name: session_id
description: ID of the session to retrieve description: ID of the session to retrieve
required: true required: true
style: simple
explode: false
schema: schema:
type: string type: string
format: uuid format: uuid
@@ -88,169 +98,150 @@ paths:
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/inline_response_400' type: object
security: properties:
- BearerAuth: [] message:
type: string
delete: delete:
tags: tags:
- signed-in - signed-in
summary: delete a specific session by ID summary: delete a specific session by ID
security:
- BearerAuth: []
parameters: parameters:
- name: session_id - in: path
in: path name: session_id
required: true required: true
style: simple
explode: false
schema: schema:
type: string type: string
format: uuid format: uuid
responses: responses:
'204': '204':
description: Session successfully deleted description: Session successfully deleted
'404': '404':
description: Session not found description: Session not found
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/inline_response_404' type: object
properties:
message:
type: string
example: 'Session not found.'
'401': '401':
description: Unauthorized description: Unauthorized
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/inline_response_401' type: object
security: properties:
- BearerAuth: [] message:
/inventory: type: string
get: example: 'Unauthorized.'
tags:
- developers
summary: searches inventory
description: |
By passing in the appropriate options, you can search for
available inventory in the system
operationId: searchInventory
parameters:
- name: searchString
in: query
description: pass an optional search string for looking up inventory
required: false
style: form
explode: true
schema:
type: string
- name: skip
in: query
description: number of records to skip for pagination
required: false
style: form
explode: true
schema:
minimum: 0
type: integer
format: int32
- name: limit
in: query
description: maximum number of records to return
required: false
style: form
explode: true
schema:
maximum: 50
minimum: 0
type: integer
format: int32
responses:
'200':
description: search results matching criteria
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/InventoryItem'
'400':
description: bad input parameter
post:
tags:
- admins
summary: adds an inventory item
description: Adds an item to the system
operationId: addInventory
requestBody:
description: Inventory item to add
content:
application/json:
schema:
$ref: '#/components/schemas/InventoryItem'
responses:
'201':
description: item created
'400':
description: 'invalid input, object invalid'
'409':
description: an existing item already exists
/register: /register:
post: post:
summary: Register a new user summary: Register a new user
requestBody: requestBody:
required: true
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/register_body' type: object
required: true properties:
username:
type: string
email:
type: string
password:
type: string
responses: responses:
'201': '201':
description: User created description: User created
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/inline_response_201' type: object
properties:
message:
type: string
example: User created successfully
'400': '400':
description: Bad Request description: Bad Request
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/inline_response_400_1' type: object
properties:
message:
type: string
example: Missing username, email or password
'409': '409':
description: Conflict description: Conflict
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/inline_response_409' type: object
properties:
message:
type: string
example: User already exists
/login: /login:
post: post:
summary: Log in a user summary: Log in a user
requestBody: requestBody:
required: true
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/login_body' type: object
required: true properties:
username:
type: string
password:
type: string
responses: responses:
'200': '200':
description: User logged in description: User logged in
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/inline_response_200' type: object
properties:
message:
type: string
example: Login successful
token:
type: string
description: Access token
'400': '400':
description: Bad Request description: Bad Request
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/inline_response_400_2' type: object
properties:
message:
type: string
example: Missing username or password
'401': '401':
description: Unauthorized description: Unauthorized
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/inline_response_401_1' type: object
properties:
message:
type: string
example: Incorrect username or password
/profile: /profile:
tags:
- signed-in
get: get:
summary: Get the profile of current logged-in user summary: Get the profile of current logged-in user
security:
- BearerAuth: []
responses: responses:
'200': '200':
description: Get user's profile description: Get user's profile
@@ -258,8 +249,7 @@ paths:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/User' $ref: '#/components/schemas/User'
security:
- BearerAuth: []
components: components:
schemas: schemas:
User: User:
@@ -270,7 +260,7 @@ components:
format: uuid format: uuid
username: username:
type: string type: string
example: alex example: 'alex'
email: email:
type: string type: string
format: email format: email
@@ -279,20 +269,19 @@ components:
properties: properties:
name: name:
type: string type: string
introduction: description:
type: string type: string
Session: Session:
type: object type: object
properties: properties:
id: id:
type: string type: string
format: uuid format: uuid
user_id: user:
type: string $ref: '#/components/schemas/User'
format: uuid quest:
quest_id: $ref: '#/components/schemas/Quest'
type: string
format: uuid
created_at: created_at:
type: string type: string
format: date-time format: date-time
@@ -316,6 +305,25 @@ components:
type: array type: array
items: items:
$ref: '#/components/schemas/Hint' $ref: '#/components/schemas/Hint'
SessionSummary:
type: object
properties:
id:
type: string
format: uuid
quest:
$ref: '#/components/schemas/Quest'
created_at:
type: string
format: date-time
updated_at:
type: string
format: date-time
finished_at:
type: string
format: date-time
TreeNode: TreeNode:
type: object type: object
properties: properties:
@@ -327,6 +335,7 @@ components:
type: array type: array
items: items:
$ref: '#/components/schemas/TreeNode' $ref: '#/components/schemas/TreeNode'
Progress: Progress:
type: object type: object
properties: properties:
@@ -338,6 +347,7 @@ components:
skipped_at: skipped_at:
type: string type: string
format: date-time format: date-time
Hint: Hint:
type: object type: object
properties: properties:
@@ -347,114 +357,7 @@ components:
type: string type: string
source: source:
type: string type: string
InventoryItem:
required:
- id
- manufacturer
- name
- releaseDate
type: object
properties:
id:
type: string
format: uuid
example: d290f1ee-6c54-4b01-90e6-d701748f0851
name:
type: string
example: Widget Adapter
releaseDate:
type: string
format: date-time
example: 2016-08-29T09:12:33.001Z
manufacturer:
$ref: '#/components/schemas/Manufacturer'
Manufacturer:
required:
- name
type: object
properties:
name:
type: string
example: ACME Corporation
homePage:
type: string
format: url
example: https://www.acme-corp.com
phone:
type: string
example: 408-867-5309
inline_response_400:
type: object
properties:
message:
type: string
inline_response_404:
type: object
properties:
message:
type: string
example: Session not found.
inline_response_401:
type: object
properties:
message:
type: string
example: Unauthorized.
register_body:
type: object
properties:
username:
type: string
email:
type: string
password:
type: string
inline_response_201:
type: object
properties:
message:
type: string
example: User created successfully
inline_response_400_1:
type: object
properties:
message:
type: string
example: 'Missing username, email or password'
inline_response_409:
type: object
properties:
message:
type: string
example: User already exists
login_body:
type: object
properties:
username:
type: string
password:
type: string
inline_response_200:
type: object
properties:
message:
type: string
example: Login successful
token:
type: string
description: Access token
inline_response_400_2:
type: object
properties:
message:
type: string
example: Missing username or password
inline_response_401_1:
type: object
properties:
message:
type: string
example: Incorrect username or password
securitySchemes: securitySchemes:
BearerAuth: BearerAuth:
type: http type: http