hackathon/schema/schema.yaml

299 lines
7.3 KiB
YAML

openapi: "3.0.0"
info:
version: 0.1.0
title: Swagger Hackathon
description: A hackathon, hosted in JIS API specification created by Hamza Ali.
contact:
name: Hamza Ali
email: me@hamzantal.pw
license:
name: MIT License
url: "https://hamza.mit-license.org/"
paths:
/auth/code:
get:
2021-09-30 10:32:18 +07:00
description: Generate oauth exchange url.
tags: ["Auth"]
operationId: gen oauth
parameters:
- name: callback
in: query
required: true
schema:
type: string
format: uri
responses:
'200':
2021-09-30 10:32:18 +07:00
description: OAuth Consent Page URI.
content:
application/json:
schema:
$ref: "#/components/schemas/ConsentPage"
default:
$ref: "#/components/responses/DefaultResponse"
/auth/authorize:
get:
2021-09-30 10:32:18 +07:00
description: Authorization response callback location.
tags: ["Auth"]
operationId: authorize callback
parameters:
- name: state
in: query
required: true
schema:
type: string
- name: code
in: query
required: true
schema:
type: string
responses:
'302':
2021-09-30 10:32:18 +07:00
description: Redirect to webpage.
headers:
Location:
schema:
type: string
format: uri
default:
$ref: "#/components/responses/DefaultResponse"
/auth/token:
delete:
tags: ["Auth"]
operationId: delete token
2021-12-19 15:30:21 +07:00
x-go-middlewares: ["token"]
parameters:
2021-12-19 15:30:21 +07:00
- $ref: "#/components/parameters/Token"
- name: all
in: query
required: true
schema:
2021-12-19 15:30:21 +07:00
type: boolean
responses:
'204':
2021-09-30 10:32:18 +07:00
description: User successfully logged out.
default:
$ref: "#/components/responses/DefaultResponse"
/users/me:
get:
description: Get self user information.
tags: ["Users"]
operationId: get me
2021-12-19 15:30:21 +07:00
x-go-middlewares: ["token"]
2021-09-30 10:32:18 +07:00
parameters:
2021-12-19 15:30:21 +07:00
- $ref: "#/components/parameters/Token"
2021-09-30 10:32:18 +07:00
responses:
'200':
description: User information.
content:
application/json:
schema:
$ref: "#/components/schemas/User"
default:
$ref: "#/components/responses/DefaultResponse"
2021-12-19 15:30:21 +07:00
put:
2021-09-30 10:32:18 +07:00
description: Update self user.
tags: ["Users"]
operationId: modify user
2021-12-19 15:30:21 +07:00
x-go-middlewares: ["token"]
2021-09-30 10:32:18 +07:00
parameters:
2021-12-19 15:30:21 +07:00
- $ref: "#/components/parameters/Token"
2021-09-30 10:32:18 +07:00
requestBody:
description: Modified user information.
content:
application/json:
schema:
type: object
required:
- name
- grade_level
properties:
name:
type: string
grade_level:
type: integer
responses:
'200':
description: New user data
content:
application/json:
schema:
$ref: "#/components/schemas/User"
default:
$ref: "#/components/responses/DefaultResponse"
/users/email:
get:
description: |-
Get user info by email.
Requires admin to get user info not equal to the owner of the token.
tags: ["Users"]
operationId: get user by email
2021-12-19 15:30:21 +07:00
x-go-middlewares: ["token"]
2021-09-30 10:32:18 +07:00
parameters:
2021-12-19 15:30:21 +07:00
- $ref: "#/components/parameters/Token"
2021-09-30 10:32:18 +07:00
- name: email
in: query
description: User email.
required: true
schema:
type: string
format: email
responses:
'200':
description: User information.
content:
application/json:
schema:
$ref: "#/components/schemas/User"
default:
$ref: "#/components/responses/DefaultResponse"
2021-12-19 15:30:21 +07:00
put:
2021-09-30 10:32:18 +07:00
description: Update another user. Requires admin.
tags: ["Users"]
operationId: modify other user
2021-12-19 15:30:21 +07:00
x-go-middlewares: ["token", "admin_token"]
2021-09-30 10:32:18 +07:00
parameters:
- name: token
in: cookie
description: User authentication token.
required: true
schema:
type: string
- name: email
in: query
description: User email.
required: true
schema:
type: string
format: email
requestBody:
description: Modified user information.
content:
application/json:
schema:
type: object
required:
- name
- email
- picture
- grade_level
- teacher
- admin
properties:
name:
type: string
new_email:
type: string
format: email
picture:
type: string
format: uri
grade_level:
type: integer
teacher:
type: boolean
admin:
type: boolean
responses:
'200':
description: User information.
content:
application/json:
schema:
$ref: "#/components/schemas/User"
default:
$ref: "#/components/responses/DefaultResponse"
/users/all:
get:
2021-12-19 15:30:21 +07:00
description: Get all users. Requires admin.
2021-09-30 10:32:18 +07:00
tags: ["Users"]
operationId: get all users
2021-12-19 15:30:21 +07:00
x-go-middlewares: ["token", "admin_token"]
2021-09-30 10:32:18 +07:00
parameters:
2021-12-19 15:30:21 +07:00
- $ref: "#/components/parameters/Token"
2021-09-30 10:32:18 +07:00
responses:
'200':
description: All user information.
content:
application/json:
schema:
2021-12-19 15:30:21 +07:00
type: array
items:
$ref: "#/components/schemas/User"
default:
$ref: "#/components/responses/DefaultResponse"
components:
2021-12-19 15:30:21 +07:00
parameters:
Token:
name: token
in: cookie
description: User authentication token.
required: true
schema:
type: string
responses:
DefaultResponse:
2021-09-30 10:32:18 +07:00
description: Unexpected server error or invalid user input.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
schemas:
ConsentPage:
type: object
required:
- url
properties:
url:
type: string
format: uri
2021-09-30 10:32:18 +07:00
User:
type: object
required:
- id
- name
- email
- picture
- teacher
- admin
- created_at
properties:
id:
type: string
name:
type: string
email:
type: string
format: email
picture:
type: string
format: uri
grade_level:
type: integer
description: GradeLevel is only present if teacher is false.
teacher:
type: boolean
admin:
type: boolean
created_at:
type: string
format: date-time
Error:
type: object
required:
- message
properties:
message:
type: string