1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 22:44:19 +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): class IntegerParameterSchema(Schema):
id = fields.Integer(description="The target numeric id.") rid = fields.Integer(description="The target numeric id.")
class CreateUser(Schema): class CreateUser(Schema):
@ -51,7 +51,22 @@ class RepositorySchema(Schema):
owner = fields.Nested(UserSchema) owner = fields.Nested(UserSchema)
class CreateRepository(Schema):
name = fields.String(description="The repository name.")
class RepositoryUpdate(Schema): class RepositoryUpdate(Schema):
name = fields.String(description="If present, it changes the name of the repository.") name = fields.String(description="If present, it changes the name of the repository.")
close = fields.String(description="If present, it closes the repository.") close = fields.String(description="If present, it closes the repository.")
open = fields.String(description="If present, it opens 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("Repository", schema=RepositorySchema)
spec.components.schema("IntegerParameter", schema=IntegerParameterSchema) spec.components.schema("IntegerParameter", schema=IntegerParameterSchema)
spec.components.schema("RepositoryUpdate", schema=RepositoryUpdate) 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"}) spec.components.security_scheme("jwt", {"type": "http", "scheme": "bearer", "bearerFormat": "JWT"})
# add swagger tags that are used for endpoint annotation # add swagger tags that are used for endpoint annotation

View file

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

View file

@ -10,9 +10,53 @@ from flask_cors import cross_origin
@jwt_required() @jwt_required()
def page_repositories(): def page_repositories():
""" """
Repositories: ---
+ GET: [onlyActive], [onlyDead] -> Gets the list of all the user-related repos. get:
+ POST: name -> Creates a new repository and returns it 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()) user = find_user(get_jwt_identity())
if request.method == "GET": if request.method == "GET":

View file

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

View file

@ -10,9 +10,61 @@ from flask_cors import cross_origin
@repository_auth @repository_auth
def page_repository_conditions(rid): def page_repository_conditions(rid):
""" """
Repository/Condition: ---
+ GET: Returns the conditions of the specified repo. get:
+ POST: type, content -> Adds a condition and returns it. 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() repository = Repository.query.filter_by(id=rid).first()

View file

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

View file

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

View file

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