doc gen fix
This commit is contained in:
parent
c606efd7dc
commit
b27f489f8d
@ -1,6 +1,6 @@
|
||||
module openAPI
|
||||
|
||||
go 1.22
|
||||
go 1.22.2
|
||||
|
||||
require (
|
||||
github.com/a-h/respond v0.0.2
|
||||
|
||||
@ -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]())
|
||||
}
|
||||
|
||||
@ -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]()).
|
||||
|
||||
10
api/types/projectTypes.go
Normal file
10
api/types/projectTypes.go
Normal file
@ -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"`
|
||||
}
|
||||
@ -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"`
|
||||
}
|
||||
|
||||
@ -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,
|
||||
"description": "check for user jwt cookie",
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"pattern": "\\d+",
|
||||
"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": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user