1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 04:54:18 +00:00

Docs completed, JWT auth working on swagger.

This commit is contained in:
Lorenzo Balugani 2021-05-06 11:25:39 +02:00
parent 7fd0441df4
commit a7d0c3488f
9 changed files with 139 additions and 22 deletions

View file

@ -33,7 +33,7 @@ class EmailParameterSchema(Schema):
class IntegerParameterSchema(Schema):
id = fields.Integer(description="The target numeric id.")
rid = fields.Integer(description="The target numeric id.")
class CreateUser(Schema):
@ -51,7 +51,22 @@ class RepositorySchema(Schema):
owner = fields.Nested(UserSchema)
class CreateRepository(Schema):
name = fields.String(description="The repository name.")
class RepositoryUpdate(Schema):
name = fields.String(description="If present, it changes the name of the repository.")
close = fields.String(description="If present, it closes the repository.")
open = fields.String(description="If present, it opens the repository.")
class ConditionSchema(Schema):
id = fields.Integer(description="The condition id.")
type = fields.Integer(description="The condition type.")
content = fields.String(description="The condition content. Meaning may change according to type.")
class CreateCondition(Schema):
type = fields.Integer(description="The condition type.")
content = fields.String(description="The condition content. Meaning may change according to type.")

View file

@ -26,6 +26,9 @@ spec.components.schema("CreateUser", schema=CreateUser)
spec.components.schema("Repository", schema=RepositorySchema)
spec.components.schema("IntegerParameter", schema=IntegerParameterSchema)
spec.components.schema("RepositoryUpdate", schema=RepositoryUpdate)
spec.components.schema("CreateRepository", schema=CreateRepository)
spec.components.schema("CreateCondition", schema=CreateCondition)
spec.components.schema("Condition", schema=ConditionSchema)
spec.components.security_scheme("jwt", {"type": "http", "scheme": "bearer", "bearerFormat": "JWT"})
# add swagger tags that are used for endpoint annotation

View file

@ -7,13 +7,6 @@ from nest_backend.database import *
def page_doa():
"""
---
get:
description: Test endpoint. If this page works, the server is fine.
tags:
- debug
"""
if request.method == "GET":
return "If you see this, the server is fine."
return "Hello there."

View file

@ -10,9 +10,53 @@ from flask_cors import cross_origin
@jwt_required()
def page_repositories():
"""
Repositories:
+ GET: [onlyActive], [onlyDead] -> Gets the list of all the user-related repos.
+ POST: name -> Creates a new repository and returns it
---
get:
summary: Get a list of repositories.
security:
- jwt: []
responses:
'200':
description: The list of the repositories related to the user (divided in "owner" and "spectator" dict keys), incapsulated in Success.
'403':
description: The user is not authorized.
content:
application/json:
schema: Error
'401':
description: The user is not logged in.
content:
application/json:
schema: Error
tags:
- repository-related
post:
summary: Creates a repository.
security:
- jwt: []
requestBody:
required: true
content:
application/json:
schema: CreateRepository
responses:
'200':
description: The user has been created successfully.
content:
application/json:
schema: Repository
'403':
description: The user is not authorized.
content:
application/json:
schema: Error
'401':
description: The user is not logged in.
content:
application/json:
schema: Error
tags:
- repository-related
"""
user = find_user(get_jwt_identity())
if request.method == "GET":
@ -27,7 +71,7 @@ def page_repositories():
owner = owner.all()
spectator = spectator.all()
return json_success({"owner": [r.to_json() for r in owner],
"spectator": [r.repository.to_json() for r in spectator]})
"spectator": [r.repository.to_json() for r in spectator]})
elif request.method == "POST":
name = request.json.get("name")
if not name:

View file

@ -17,7 +17,8 @@ def page_repository(rid):
parameters:
- in: path
schema: IntegerParameterSchema
security:
- jwt: []
responses:
'200':
description: The details about the requested schema. The schema is incapsulated in Success.
@ -46,6 +47,8 @@ def page_repository(rid):
parameters:
- in: path
schema: IntegerParameterSchema
security:
- jwt: []
responses:
'200':
description: The repository has been deleted successfully.
@ -73,6 +76,8 @@ def page_repository(rid):
- repository-related
patch:
summary: Updates a repository.
security:
- jwt: []
requestBody:
required: true
content:

View file

@ -10,9 +10,61 @@ from flask_cors import cross_origin
@repository_auth
def page_repository_conditions(rid):
"""
Repository/Condition:
+ GET: Returns the conditions of the specified repo.
+ POST: type, content -> Adds a condition and returns it.
---
get:
summary: Get a list of a repository conditions.
parameters:
- in: path
schema: IntegerParameterSchema
security:
- jwt: []
responses:
'200':
description: List of Condition schemas, incapsulated in Success.
'401':
description: The user is not logged in.
content:
application/json:
schema: Error
'403':
description: The user is not authorized.
content:
application/json:
schema: Error
'404':
description: The repository could not be found.
content:
application/json:
schema: Error
tags:
- repository-related
post:
summary: Creates a condition and attaches it to the repository.
security:
- jwt: []
requestBody:
required: true
content:
application/json:
schema: CreateCondition
responses:
'200':
description: The user has been created successfully.
content:
application/json:
schema: Condition
'403':
description: The user is not authorized.
content:
application/json:
schema: Error
'401':
description: The user is not logged in.
content:
application/json:
schema: Error
tags:
- repository-related
"""
repository = Repository.query.filter_by(id=rid).first()

View file

@ -15,7 +15,8 @@ def page_user(email):
parameters:
- in: path
schema: EmailParameterSchema
security:
- jwt: []
responses:
'200':
description: The details about the requested user. The schema is incapsulated in Success.
@ -44,7 +45,8 @@ def page_user(email):
parameters:
- in: path
schema: EmailParameterSchema
security:
- jwt: []
responses:
'200':
description: The user has been deleted successfully.
@ -81,7 +83,8 @@ def page_user(email):
parameters:
- in: path
schema: EmailParameterSchema
security:
- jwt: []
responses:
'200':
description: The user has been updated successfully.

View file

@ -12,6 +12,8 @@ def page_users():
---
get:
summary: Get a list of users.
security:
- jwt: []
responses:
'200':
description: A list of User schemas, incapsulated in Success.
@ -26,10 +28,11 @@ def page_users():
application/json:
schema: Error
tags:
- user-related
- admin-only
post:
summary: Creates a user.
security:
- jwt: []
requestBody:
required: true
content:
@ -53,7 +56,6 @@ def page_users():
schema: Error
tags:
- user-related
- admin-only
"""
user = find_user(get_jwt_identity())
if request.method == "GET":

View file

@ -1,4 +1,4 @@
from openapi_spec_validator import validate_spec_url
import os
validate_spec_url("http://localhost:5000/api/v1/swagger.json")
validate_spec_url("http://localhost:5000/docs/swagger.json")