diff --git a/code/backend/nest_backend/api_schemas.py b/code/backend/nest_backend/api_schemas.py index 440c4f3..fcabdb9 100644 --- a/code/backend/nest_backend/api_schemas.py +++ b/code/backend/nest_backend/api_schemas.py @@ -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.") \ No newline at end of file diff --git a/code/backend/nest_backend/api_spec.py b/code/backend/nest_backend/api_spec.py index 3c38860..dd19f74 100644 --- a/code/backend/nest_backend/api_spec.py +++ b/code/backend/nest_backend/api_spec.py @@ -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 diff --git a/code/backend/nest_backend/routes/doa.py b/code/backend/nest_backend/routes/doa.py index 80bb1e0..b8b670a 100644 --- a/code/backend/nest_backend/routes/doa.py +++ b/code/backend/nest_backend/routes/doa.py @@ -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." diff --git a/code/backend/nest_backend/routes/repository/repositories.py b/code/backend/nest_backend/routes/repository/repositories.py index 18e0baf..4a054a5 100644 --- a/code/backend/nest_backend/routes/repository/repositories.py +++ b/code/backend/nest_backend/routes/repository/repositories.py @@ -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: diff --git a/code/backend/nest_backend/routes/repository/repository.py b/code/backend/nest_backend/routes/repository/repository.py index 4205e81..d5d3577 100644 --- a/code/backend/nest_backend/routes/repository/repository.py +++ b/code/backend/nest_backend/routes/repository/repository.py @@ -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: diff --git a/code/backend/nest_backend/routes/repository/repository_conditions.py b/code/backend/nest_backend/routes/repository/repository_conditions.py index 3c58963..ed43e50 100644 --- a/code/backend/nest_backend/routes/repository/repository_conditions.py +++ b/code/backend/nest_backend/routes/repository/repository_conditions.py @@ -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() diff --git a/code/backend/nest_backend/routes/users/user.py b/code/backend/nest_backend/routes/users/user.py index b44b3e0..9ba4802 100644 --- a/code/backend/nest_backend/routes/users/user.py +++ b/code/backend/nest_backend/routes/users/user.py @@ -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. diff --git a/code/backend/nest_backend/routes/users/users.py b/code/backend/nest_backend/routes/users/users.py index 21c9e2f..aa2c3e2 100644 --- a/code/backend/nest_backend/routes/users/users.py +++ b/code/backend/nest_backend/routes/users/users.py @@ -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": diff --git a/code/backend/nest_backend/test/openapi_compliance_test.py b/code/backend/nest_backend/test/openapi_compliance_test.py index 9c41f8b..21041ef 100644 --- a/code/backend/nest_backend/test/openapi_compliance_test.py +++ b/code/backend/nest_backend/test/openapi_compliance_test.py @@ -1,4 +1,4 @@ from openapi_spec_validator import validate_spec_url import os -validate_spec_url("http://localhost:5000/api/v1/swagger.json") \ No newline at end of file +validate_spec_url("http://localhost:5000/docs/swagger.json") \ No newline at end of file