Compare commits

..

2 Commits

Author SHA1 Message Date
54e37e59fc docs: update swagger 2025-11-23 13:35:00 +01:00
5d4b38ddc4 feat: add validation tags to request DTOs 2025-11-23 13:34:53 +01:00
5 changed files with 226 additions and 51 deletions

View File

@@ -1819,6 +1819,9 @@ const docTemplate = `{
"definitions": { "definitions": {
"dto.ConfirmAccountDeletionRequest": { "dto.ConfirmAccountDeletionRequest": {
"type": "object", "type": "object",
"required": [
"token"
],
"properties": { "properties": {
"delete_posts": { "delete_posts": {
"type": "boolean" "type": "boolean"
@@ -1830,20 +1833,30 @@ const docTemplate = `{
}, },
"dto.CreatePostRequest": { "dto.CreatePostRequest": {
"type": "object", "type": "object",
"required": [
"url"
],
"properties": { "properties": {
"content": { "content": {
"type": "string" "type": "string",
"maxLength": 10000
}, },
"title": { "title": {
"type": "string" "type": "string",
"maxLength": 200,
"minLength": 3
}, },
"url": { "url": {
"type": "string" "type": "string",
"maxLength": 2048
} }
} }
}, },
"dto.ForgotPasswordRequest": { "dto.ForgotPasswordRequest": {
"type": "object", "type": "object",
"required": [
"username_or_email"
],
"properties": { "properties": {
"username_or_email": { "username_or_email": {
"type": "string" "type": "string"
@@ -1852,12 +1865,20 @@ const docTemplate = `{
}, },
"dto.LoginRequest": { "dto.LoginRequest": {
"type": "object", "type": "object",
"required": [
"password",
"username"
],
"properties": { "properties": {
"password": { "password": {
"type": "string" "type": "string",
"maxLength": 128,
"minLength": 8
}, },
"username": { "username": {
"type": "string" "type": "string",
"maxLength": 50,
"minLength": 3
} }
} }
}, },
@@ -1875,31 +1896,51 @@ const docTemplate = `{
}, },
"dto.RegisterRequest": { "dto.RegisterRequest": {
"type": "object", "type": "object",
"required": [
"email",
"password",
"username"
],
"properties": { "properties": {
"email": { "email": {
"type": "string" "type": "string",
"maxLength": 254
}, },
"password": { "password": {
"type": "string" "type": "string",
"maxLength": 128,
"minLength": 8
}, },
"username": { "username": {
"type": "string" "type": "string",
"maxLength": 50,
"minLength": 3
} }
} }
}, },
"dto.ResendVerificationRequest": { "dto.ResendVerificationRequest": {
"type": "object", "type": "object",
"required": [
"email"
],
"properties": { "properties": {
"email": { "email": {
"type": "string" "type": "string",
"maxLength": 254
} }
} }
}, },
"dto.ResetPasswordRequest": { "dto.ResetPasswordRequest": {
"type": "object", "type": "object",
"required": [
"new_password",
"token"
],
"properties": { "properties": {
"new_password": { "new_password": {
"type": "string" "type": "string",
"maxLength": 128,
"minLength": 8
}, },
"token": { "token": {
"type": "string" "type": "string"
@@ -1920,39 +1961,60 @@ const docTemplate = `{
}, },
"dto.UpdateEmailRequest": { "dto.UpdateEmailRequest": {
"type": "object", "type": "object",
"required": [
"email"
],
"properties": { "properties": {
"email": { "email": {
"type": "string" "type": "string",
"maxLength": 254
} }
} }
}, },
"dto.UpdatePasswordRequest": { "dto.UpdatePasswordRequest": {
"type": "object", "type": "object",
"required": [
"current_password",
"new_password"
],
"properties": { "properties": {
"current_password": { "current_password": {
"type": "string" "type": "string"
}, },
"new_password": { "new_password": {
"type": "string" "type": "string",
"maxLength": 128,
"minLength": 8
} }
} }
}, },
"dto.UpdatePostRequest": { "dto.UpdatePostRequest": {
"type": "object", "type": "object",
"required": [
"title"
],
"properties": { "properties": {
"content": { "content": {
"type": "string" "type": "string",
"maxLength": 10000
}, },
"title": { "title": {
"type": "string" "type": "string",
"maxLength": 200,
"minLength": 3
} }
} }
}, },
"dto.UpdateUsernameRequest": { "dto.UpdateUsernameRequest": {
"type": "object", "type": "object",
"required": [
"username"
],
"properties": { "properties": {
"username": { "username": {
"type": "string" "type": "string",
"maxLength": 50,
"minLength": 3
} }
} }
}, },

View File

@@ -1816,6 +1816,9 @@
"definitions": { "definitions": {
"dto.ConfirmAccountDeletionRequest": { "dto.ConfirmAccountDeletionRequest": {
"type": "object", "type": "object",
"required": [
"token"
],
"properties": { "properties": {
"delete_posts": { "delete_posts": {
"type": "boolean" "type": "boolean"
@@ -1827,20 +1830,30 @@
}, },
"dto.CreatePostRequest": { "dto.CreatePostRequest": {
"type": "object", "type": "object",
"required": [
"url"
],
"properties": { "properties": {
"content": { "content": {
"type": "string" "type": "string",
"maxLength": 10000
}, },
"title": { "title": {
"type": "string" "type": "string",
"maxLength": 200,
"minLength": 3
}, },
"url": { "url": {
"type": "string" "type": "string",
"maxLength": 2048
} }
} }
}, },
"dto.ForgotPasswordRequest": { "dto.ForgotPasswordRequest": {
"type": "object", "type": "object",
"required": [
"username_or_email"
],
"properties": { "properties": {
"username_or_email": { "username_or_email": {
"type": "string" "type": "string"
@@ -1849,12 +1862,20 @@
}, },
"dto.LoginRequest": { "dto.LoginRequest": {
"type": "object", "type": "object",
"required": [
"password",
"username"
],
"properties": { "properties": {
"password": { "password": {
"type": "string" "type": "string",
"maxLength": 128,
"minLength": 8
}, },
"username": { "username": {
"type": "string" "type": "string",
"maxLength": 50,
"minLength": 3
} }
} }
}, },
@@ -1872,31 +1893,51 @@
}, },
"dto.RegisterRequest": { "dto.RegisterRequest": {
"type": "object", "type": "object",
"required": [
"email",
"password",
"username"
],
"properties": { "properties": {
"email": { "email": {
"type": "string" "type": "string",
"maxLength": 254
}, },
"password": { "password": {
"type": "string" "type": "string",
"maxLength": 128,
"minLength": 8
}, },
"username": { "username": {
"type": "string" "type": "string",
"maxLength": 50,
"minLength": 3
} }
} }
}, },
"dto.ResendVerificationRequest": { "dto.ResendVerificationRequest": {
"type": "object", "type": "object",
"required": [
"email"
],
"properties": { "properties": {
"email": { "email": {
"type": "string" "type": "string",
"maxLength": 254
} }
} }
}, },
"dto.ResetPasswordRequest": { "dto.ResetPasswordRequest": {
"type": "object", "type": "object",
"required": [
"new_password",
"token"
],
"properties": { "properties": {
"new_password": { "new_password": {
"type": "string" "type": "string",
"maxLength": 128,
"minLength": 8
}, },
"token": { "token": {
"type": "string" "type": "string"
@@ -1917,39 +1958,60 @@
}, },
"dto.UpdateEmailRequest": { "dto.UpdateEmailRequest": {
"type": "object", "type": "object",
"required": [
"email"
],
"properties": { "properties": {
"email": { "email": {
"type": "string" "type": "string",
"maxLength": 254
} }
} }
}, },
"dto.UpdatePasswordRequest": { "dto.UpdatePasswordRequest": {
"type": "object", "type": "object",
"required": [
"current_password",
"new_password"
],
"properties": { "properties": {
"current_password": { "current_password": {
"type": "string" "type": "string"
}, },
"new_password": { "new_password": {
"type": "string" "type": "string",
"maxLength": 128,
"minLength": 8
} }
} }
}, },
"dto.UpdatePostRequest": { "dto.UpdatePostRequest": {
"type": "object", "type": "object",
"required": [
"title"
],
"properties": { "properties": {
"content": { "content": {
"type": "string" "type": "string",
"maxLength": 10000
}, },
"title": { "title": {
"type": "string" "type": "string",
"maxLength": 200,
"minLength": 3
} }
} }
}, },
"dto.UpdateUsernameRequest": { "dto.UpdateUsernameRequest": {
"type": "object", "type": "object",
"required": [
"username"
],
"properties": { "properties": {
"username": { "username": {
"type": "string" "type": "string",
"maxLength": 50,
"minLength": 3
} }
} }
}, },

View File

@@ -6,27 +6,44 @@ definitions:
type: boolean type: boolean
token: token:
type: string type: string
required:
- token
type: object type: object
dto.CreatePostRequest: dto.CreatePostRequest:
properties: properties:
content: content:
maxLength: 10000
type: string type: string
title: title:
maxLength: 200
minLength: 3
type: string type: string
url: url:
maxLength: 2048
type: string type: string
required:
- url
type: object type: object
dto.ForgotPasswordRequest: dto.ForgotPasswordRequest:
properties: properties:
username_or_email: username_or_email:
type: string type: string
required:
- username_or_email
type: object type: object
dto.LoginRequest: dto.LoginRequest:
properties: properties:
password: password:
maxLength: 128
minLength: 8
type: string type: string
username: username:
maxLength: 50
minLength: 3
type: string type: string
required:
- password
- username
type: object type: object
dto.RefreshTokenRequest: dto.RefreshTokenRequest:
properties: properties:
@@ -39,23 +56,40 @@ definitions:
dto.RegisterRequest: dto.RegisterRequest:
properties: properties:
email: email:
maxLength: 254
type: string type: string
password: password:
maxLength: 128
minLength: 8
type: string type: string
username: username:
maxLength: 50
minLength: 3
type: string type: string
required:
- email
- password
- username
type: object type: object
dto.ResendVerificationRequest: dto.ResendVerificationRequest:
properties: properties:
email: email:
maxLength: 254
type: string type: string
required:
- email
type: object type: object
dto.ResetPasswordRequest: dto.ResetPasswordRequest:
properties: properties:
new_password: new_password:
maxLength: 128
minLength: 8
type: string type: string
token: token:
type: string type: string
required:
- new_password
- token
type: object type: object
dto.RevokeTokenRequest: dto.RevokeTokenRequest:
properties: properties:
@@ -68,26 +102,43 @@ definitions:
dto.UpdateEmailRequest: dto.UpdateEmailRequest:
properties: properties:
email: email:
maxLength: 254
type: string type: string
required:
- email
type: object type: object
dto.UpdatePasswordRequest: dto.UpdatePasswordRequest:
properties: properties:
current_password: current_password:
type: string type: string
new_password: new_password:
maxLength: 128
minLength: 8
type: string type: string
required:
- current_password
- new_password
type: object type: object
dto.UpdatePostRequest: dto.UpdatePostRequest:
properties: properties:
content: content:
maxLength: 10000
type: string type: string
title: title:
maxLength: 200
minLength: 3
type: string type: string
required:
- title
type: object type: object
dto.UpdateUsernameRequest: dto.UpdateUsernameRequest:
properties: properties:
username: username:
maxLength: 50
minLength: 3
type: string type: string
required:
- username
type: object type: object
handlers.APIInfo: handlers.APIInfo:
properties: properties:

View File

@@ -1,51 +1,51 @@
package dto package dto
type LoginRequest struct { type LoginRequest struct {
Username string `json:"username"` Username string `json:"username" validate:"required,min=3,max=50"`
Password string `json:"password"` Password string `json:"password" validate:"required,min=8,max=128"`
} }
type RegisterRequest struct { type RegisterRequest struct {
Username string `json:"username"` Username string `json:"username" validate:"required,min=3,max=50"`
Email string `json:"email"` Email string `json:"email" validate:"required,email,max=254"`
Password string `json:"password"` Password string `json:"password" validate:"required,min=8,max=128"`
} }
type ResendVerificationRequest struct { type ResendVerificationRequest struct {
Email string `json:"email"` Email string `json:"email" validate:"required,email,max=254"`
} }
type ForgotPasswordRequest struct { type ForgotPasswordRequest struct {
UsernameOrEmail string `json:"username_or_email"` UsernameOrEmail string `json:"username_or_email" validate:"required"`
} }
type ResetPasswordRequest struct { type ResetPasswordRequest struct {
Token string `json:"token"` Token string `json:"token" validate:"required"`
NewPassword string `json:"new_password"` NewPassword string `json:"new_password" validate:"required,min=8,max=128"`
} }
type UpdateEmailRequest struct { type UpdateEmailRequest struct {
Email string `json:"email"` Email string `json:"email" validate:"required,email,max=254"`
} }
type UpdateUsernameRequest struct { type UpdateUsernameRequest struct {
Username string `json:"username"` Username string `json:"username" validate:"required,min=3,max=50"`
} }
type UpdatePasswordRequest struct { type UpdatePasswordRequest struct {
CurrentPassword string `json:"current_password"` CurrentPassword string `json:"current_password" validate:"required"`
NewPassword string `json:"new_password"` NewPassword string `json:"new_password" validate:"required,min=8,max=128"`
} }
type ConfirmAccountDeletionRequest struct { type ConfirmAccountDeletionRequest struct {
Token string `json:"token"` Token string `json:"token" validate:"required"`
DeletePosts bool `json:"delete_posts"` DeletePosts bool `json:"delete_posts"`
} }
type RefreshTokenRequest struct { type RefreshTokenRequest struct {
RefreshToken string `json:"refresh_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." binding:"required"` RefreshToken string `json:"refresh_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." validate:"required"`
} }
type RevokeTokenRequest struct { type RevokeTokenRequest struct {
RefreshToken string `json:"refresh_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." binding:"required"` RefreshToken string `json:"refresh_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." validate:"required"`
} }

View File

@@ -1,12 +1,12 @@
package dto package dto
type CreatePostRequest struct { type CreatePostRequest struct {
Title string `json:"title"` Title string `json:"title" validate:"omitempty,min=3,max=200"`
URL string `json:"url"` URL string `json:"url" validate:"required,url,max=2048"`
Content string `json:"content"` Content string `json:"content" validate:"omitempty,max=10000"`
} }
type UpdatePostRequest struct { type UpdatePostRequest struct {
Title string `json:"title"` Title string `json:"title" validate:"required,min=3,max=200"`
Content string `json:"content"` Content string `json:"content" validate:"omitempty,max=10000"`
} }