From b27f489f8d5706571b9189612928735f76bf74dc Mon Sep 17 00:00:00 2001 From: darius Date: Thu, 4 Jul 2024 12:54:47 +0200 Subject: [PATCH] doc gen fix --- api/docs/openAPI/go.mod | 2 +- api/docs/openAPI/openApiProjectEndpoints.go | 10 +- api/docs/openAPI/openApiUserEndpoints.go | 5 +- api/types/projectTypes.go | 10 + api/types/userTypes.go | 12 + common/docs/openApi.json | 582 +++++++++++++++++++- 6 files changed, 598 insertions(+), 23 deletions(-) create mode 100644 api/types/projectTypes.go diff --git a/api/docs/openAPI/go.mod b/api/docs/openAPI/go.mod index 5a71a9b..eeacb9a 100644 --- a/api/docs/openAPI/go.mod +++ b/api/docs/openAPI/go.mod @@ -1,6 +1,6 @@ module openAPI -go 1.22 +go 1.22.2 require ( github.com/a-h/respond v0.0.2 diff --git a/api/docs/openAPI/openApiProjectEndpoints.go b/api/docs/openAPI/openApiProjectEndpoints.go index c6047be..5fb8847 100644 --- a/api/docs/openAPI/openApiProjectEndpoints.go +++ b/api/docs/openAPI/openApiProjectEndpoints.go @@ -4,7 +4,7 @@ import ( "github.com/a-h/respond" "github.com/a-h/rest" "net/http" - "portfolio/database/ent" + "portfolio/api/types" ) func RegisterProjectEndpoints() { @@ -21,7 +21,7 @@ func RegisterProjectEndpoints() { Regexp: `\d+`, }). HasDescription("Update project by id"). - HasRequestModel(rest.ModelOf[ent.Project]()). + HasRequestModel(rest.ModelOf[types.Project]()). HasResponseModel(http.StatusOK, rest.ModelOf[string]()). HasResponseModel(http.StatusBadRequest, rest.ModelOf[string]()). HasResponseModel(http.StatusInternalServerError, rest.ModelOf[respond.Error]()). @@ -30,7 +30,7 @@ func RegisterProjectEndpoints() { api.Patch("/projects"). HasDescription("Update projects WIP"). - HasResponseModel(http.StatusOK, rest.ModelOf[[]ent.Project]()). + HasResponseModel(http.StatusOK, rest.ModelOf[[]types.Project]()). HasResponseModel(http.StatusInternalServerError, rest.ModelOf[respond.Error]()). HasResponseModel(http.StatusUnprocessableEntity, rest.ModelOf[respond.Error]()). HasResponseModel(http.StatusUnauthorized, rest.ModelOf[string]()) @@ -41,12 +41,12 @@ func RegisterProjectEndpoints() { Regexp: `\d+`, }). HasDescription("Get project by id"). - HasResponseModel(http.StatusOK, rest.ModelOf[ent.Project]()). + HasResponseModel(http.StatusOK, rest.ModelOf[types.Project]()). HasResponseModel(http.StatusBadRequest, rest.ModelOf[string]()). HasResponseModel(http.StatusUnprocessableEntity, rest.ModelOf[respond.Error]()) api.Get("/projects"). HasDescription("Get projects"). - HasResponseModel(http.StatusOK, rest.ModelOf[[]ent.Project]()). + HasResponseModel(http.StatusOK, rest.ModelOf[[]types.Project]()). HasResponseModel(http.StatusUnprocessableEntity, rest.ModelOf[respond.Error]()) } diff --git a/api/docs/openAPI/openApiUserEndpoints.go b/api/docs/openAPI/openApiUserEndpoints.go index 8698754..34dd12d 100644 --- a/api/docs/openAPI/openApiUserEndpoints.go +++ b/api/docs/openAPI/openApiUserEndpoints.go @@ -5,7 +5,6 @@ import ( "github.com/a-h/rest" "net/http" "portfolio/api/types" - "portfolio/database/ent" ) func RegisterUserEndpoints() { @@ -15,14 +14,14 @@ func RegisterUserEndpoints() { Regexp: `\d+`, }). HasDescription("Get user by uid."). - HasResponseModel(http.StatusOK, rest.ModelOf[ent.User]()). + HasResponseModel(http.StatusOK, rest.ModelOf[types.User]()). HasResponseModel(http.StatusBadRequest, rest.ModelOf[string]()). HasResponseModel(http.StatusInternalServerError, rest.ModelOf[respond.Error]()). HasResponseModel(http.StatusUnprocessableEntity, rest.ModelOf[respond.Error]()) api.Post("/register"). HasDescription("Register."). - HasRequestModel(rest.ModelOf[ent.User]()). + HasRequestModel(rest.ModelOf[types.User]()). HasResponseModel(http.StatusCreated, rest.ModelOf[string]()). HasResponseModel(http.StatusBadRequest, rest.ModelOf[string]()). HasResponseModel(http.StatusInternalServerError, rest.ModelOf[respond.Error]()). diff --git a/api/types/projectTypes.go b/api/types/projectTypes.go new file mode 100644 index 0000000..83340b0 --- /dev/null +++ b/api/types/projectTypes.go @@ -0,0 +1,10 @@ +package types + +type Project struct { + ID int `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + URL string `json:"url,omitempty"` + ImageURL string `json:"image_url,omitempty"` + DocURL string `json:"doc_url,omitempty"` +} diff --git a/api/types/userTypes.go b/api/types/userTypes.go index cfcae0a..adf0960 100644 --- a/api/types/userTypes.go +++ b/api/types/userTypes.go @@ -1,5 +1,9 @@ package types +import ( + "portfolio/database/ent/user" +) + type Username struct { Name string } @@ -8,3 +12,11 @@ type LoginUser struct { Email string Password string } + +type User struct { + ID int `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Email string `json:"email,omitempty"` + Password string `json:"-"` + Role user.Role `json:"role,omitempty"` +} diff --git a/common/docs/openApi.json b/common/docs/openApi.json index 4ac56a5..d1b62fe 100644 --- a/common/docs/openApi.json +++ b/common/docs/openApi.json @@ -1,26 +1,133 @@ { - "components": {}, + "components": { + "schemas": { + "Error": { + "properties": { + "message": { + "type": "string" + }, + "statusCode": { + "type": "integer" + } + }, + "required": [ + "message", + "statusCode" + ], + "type": "object" + }, + "portfolio_api_types_LoginUser": { + "properties": { + "Email": { + "type": "string" + }, + "Password": { + "type": "string" + } + }, + "required": [ + "Email", + "Password" + ], + "type": "object" + }, + "portfolio_api_types_Project": { + "properties": { + "description": { + "type": "string" + }, + "doc_url": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "image_url": { + "type": "string" + }, + "name": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "type": "object" + }, + "portfolio_api_types_User": { + "properties": { + "-": { + "type": "string" + }, + "email": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "role": { + "type": "string" + } + }, + "required": [ + "-" + ], + "type": "object" + } + } + }, "info": { "title": "portfolio", "version": "0.0.0" }, "openapi": "3.0.0", "paths": { - "/nfc/{uid}": { + "/check": { "get": { - "description": "Get nfc data by uid.", - "parameters": [ - { - "description": "id of the user", - "in": "path", - "name": "uid", - "required": true, - "schema": { - "pattern": "\\d+", - "type": "string" - } + "description": "check for user jwt cookie", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + }, + "description": "" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "default": { + "description": "" } - ], + } + } + }, + "/htmx/canEdit": { + "get": { + "description": "check if user is allowed to edit", "responses": { "200": { "content": { @@ -37,6 +144,453 @@ } } } + }, + "/login": { + "post": { + "description": "Login.", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/portfolio_api_types_LoginUser" + } + } + } + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + }, + "description": "" + }, + "401": { + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + }, + "description": "" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "default": { + "description": "" + } + } + } + }, + "/project": { + "post": { + "description": "Create project", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + }, + "description": "" + }, + "401": { + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + }, + "description": "" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "default": { + "description": "" + } + } + } + }, + "/project/{id}": { + "get": { + "description": "Get project by id", + "parameters": [ + { + "description": "id of the project", + "in": "path", + "name": "id", + "required": true, + "schema": { + "pattern": "\\d+", + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/portfolio_api_types_Project" + } + } + }, + "description": "" + }, + "400": { + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + }, + "description": "" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "default": { + "description": "" + } + } + }, + "patch": { + "description": "Update project by id", + "parameters": [ + { + "description": "id of the project", + "in": "path", + "name": "id", + "required": true, + "schema": { + "pattern": "\\d+", + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/portfolio_api_types_Project" + } + } + } + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + }, + "description": "" + }, + "400": { + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + }, + "description": "" + }, + "401": { + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + }, + "description": "" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "default": { + "description": "" + } + } + } + }, + "/projects": { + "get": { + "description": "Get projects", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "items": { + "$ref": "#/components/schemas/portfolio_api_types_Project" + }, + "nullable": true, + "type": "array" + } + } + }, + "description": "" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "default": { + "description": "" + } + } + }, + "patch": { + "description": "Update projects WIP", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "items": { + "$ref": "#/components/schemas/portfolio_api_types_Project" + }, + "nullable": true, + "type": "array" + } + } + }, + "description": "" + }, + "401": { + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + }, + "description": "" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "default": { + "description": "" + } + } + } + }, + "/register": { + "post": { + "description": "Register.", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/portfolio_api_types_User" + } + } + } + }, + "responses": { + "201": { + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + }, + "description": "" + }, + "400": { + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + }, + "description": "" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "default": { + "description": "" + } + } + } + }, + "/user/{uid}": { + "get": { + "description": "Get user by uid.", + "parameters": [ + { + "description": "id of the user", + "in": "path", + "name": "id", + "required": true, + "schema": { + "pattern": "\\d+", + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/portfolio_api_types_User" + } + } + }, + "description": "" + }, + "400": { + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + }, + "description": "" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "description": "" + }, + "default": { + "description": "" + } + } + } } } }