1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 14:34:19 +00:00

More docs

This commit is contained in:
Lorenzo Balugani 2021-05-05 22:45:36 +02:00
parent 30dccec243
commit 425eb4fec0
4 changed files with 119 additions and 8 deletions

View file

@ -35,11 +35,9 @@ app.register_blueprint(swagger_ui_blueprint, url_prefix=SWAGGER_URL)
with app.test_request_context(): with app.test_request_context():
# register all swagger documented functions here
for fn_name in app.view_functions: for fn_name in app.view_functions:
if fn_name == 'static': if fn_name == 'static':
continue continue
print(f"Loading swagger docs for function: {fn_name}")
view_fn = app.view_functions[fn_name] view_fn = app.view_functions[fn_name]
spec.path(view=view_fn) spec.path(view=view_fn)

View file

@ -32,7 +32,26 @@ class EmailParameterSchema(Schema):
email = fields.String(description="The target user's email.") email = fields.String(description="The target user's email.")
class IntegerParameterSchema(Schema):
id = fields.Integer(description="The target numeric id.")
class CreateUser(Schema): class CreateUser(Schema):
email = fields.String(description="The new user's email.") email = fields.String(description="The new user's email.")
username = fields.String(description="The new user's username.") username = fields.String(description="The new user's username.")
password = fields.String(description="The new user's password.") password = fields.String(description="The new user's password.")
class RepositorySchema(Schema):
id = fields.Integer(description="The repository id.")
name = fields.String(description="The repository name.")
start = fields.DateTime(description="The start date of the repository.")
isActive = fields.Boolean(description="True if the repository is active.")
end = fields.DateTime(description="The end date of the repository")
owner = fields.Nested(UserSchema)
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.")

View file

@ -22,6 +22,10 @@ spec.components.schema("I_Login", schema=InputLoginSchema)
spec.components.schema("Success", schema=SuccesSchema) spec.components.schema("Success", schema=SuccesSchema)
spec.components.schema("EmailParameter", schema=EmailParameterSchema) spec.components.schema("EmailParameter", schema=EmailParameterSchema)
spec.components.schema("CreateUser", schema=CreateUser) 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.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
tags = [ tags = [

View file

@ -11,10 +11,100 @@ import datetime
@repository_auth @repository_auth
def page_repository(rid): def page_repository(rid):
""" """
Repository <rid>: ---
+ GET: Gets info about the specified repository. get:
+ PATCH: [name], [close], [open] -> Updates certain aspects of the repository. description: Get details about a repository.
+ DELETE: deletes the specified repository. parameters:
- in: path
schema: IntegerParameterSchema
responses:
'200':
description: The details about the requested schema. The schema is incapsulated in Success.
content:
application/json:
schema: Repository
'404':
description: Could not find the requested repository.
content:
application/json:
schema: Error
'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
delete:
description: Deletes a repository.
parameters:
- in: path
schema: IntegerParameterSchema
responses:
'200':
description: The repository has been deleted successfully.
'404':
description: Could not find the requested repository.
content:
application/json:
schema: Error
'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
'500':
description: Could not delete the repository.
content:
application/json:
schema: Error
tags:
- repository-related
patch:
description: Updates a repository.
requestBody:
required: true
content:
application/json:
schema: RepositoryUpdate
parameters:
- in: path
schema: IntegerParameterSchema
responses:
'200':
description: The repository has been updated successfully.
content:
application/json:
schema: Repository
'404':
description: Could not find the requested repository.
content:
application/json:
schema: Error
'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())
repository = Repository.query.filter_by(id=rid).first() repository = Repository.query.filter_by(id=rid).first()
@ -42,5 +132,5 @@ def page_repository(rid):
Base.session.commit() Base.session.commit()
except Exception as e: except Exception as e:
Base.session.rollback() Base.session.rollback()
return json_error("Cant delete repository because of dependencies.") return json_error("Cant delete repository because of dependencies."), 500
return json_success("Success"), 200 return json_success("Success"), 200