Skip to content

Commit

Permalink
docs: update OpenAPIs docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
just-pthai-it committed Aug 23, 2024
1 parent 2f27385 commit a949160
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 38 deletions.
16 changes: 3 additions & 13 deletions core/controllers/FeedbackController.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"TSS-microservices/common"
feedback_form "TSS-microservices/core/http/requests/feedback-form"
feedback_response "TSS-microservices/core/http/responses/feedback"
"TSS-microservices/core/models"
"TSS-microservices/core/repositories"
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -122,18 +123,7 @@ func (controller *FeedbackController) GetById(context *gin.Context) {
// type: string
// responses:
// 200:
// description: list of feedback
// schema:
// type: object
// properties:
// data:
// type: array
// items:
// "$ref": "#/definitions/FeedbackModel"
// limit:
// type: integer
// offset:
// type: integer
// "$ref": "#/responses/GetManyResponse"

func (controller *FeedbackController) GetMany(context *gin.Context) {
limit, _ := strconv.Atoi(context.DefaultQuery("limit", "10"))
Expand All @@ -159,5 +149,5 @@ func (controller *FeedbackController) GetMany(context *gin.Context) {
return
}

context.JSON(http.StatusOK, gin.H{"data": feedback, "limit": limit, "offset": offset})
context.JSON(http.StatusOK, feedback_response.GetManyResponse{Body: feedback_response.GetManyResponseBody{Limit: limit, Offset: offset, Data: feedback}}.Body)
}
2 changes: 1 addition & 1 deletion core/controllers/HermesController.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (controller *HermesController) SendMail(context *gin.Context) {
mailTemplate.Subject = input.Subject
}

message, err := controller.handleMailMessage(mailTemplate, input.PlaceHolder)
message, err := controller.handleMailMessage(mailTemplate, input.Placeholder)

if err != nil {
context.JSON(common.ErrorHandlerHttpResponse(err))
Expand Down
17 changes: 14 additions & 3 deletions core/http/requests/hermes-forms/SendMailFormRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ package hermes_forms

type SendMailFormRequest struct {
// required: true
// type: string
Code string `json:"code" binding:"required"`
// required: true
Recipients []string `json:"recipients" binding:"required"`
PlaceHolder map[string]string `json:"placeholder" binding:"required"`
Subject string `json:"subject"`
// type: array
// items:
// type: string
// example: ["[email protected]", "[email protected]"]
Recipients []string `json:"recipients" binding:"required"`
// required: false
// type: object
Placeholder map[string]string `json:"placeholder" binding:"required"`
// required: false
// type: string
// extensions:
// x-note: All key must be capital the first character
Subject string `json:"subject"`
}

// swagger:parameters SendMail
Expand Down
15 changes: 15 additions & 0 deletions core/http/responses/feedback/GetManyResponse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package feedback

import "TSS-microservices/core/models"

// swagger:response GetManyResponse
type GetManyResponse struct {
// in: body
Body GetManyResponseBody `json:"body"`
}

type GetManyResponseBody struct {
Limit int `json:"limit"`
Offset int `json:"offset"`
Data []models.Feedback `json:"data"`
}
59 changes: 38 additions & 21 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,7 @@
],
"responses": {
"200": {
"description": "list of feedback",
"schema": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/FeedbackModel"
}
},
"limit": {
"type": "integer"
},
"offset": {
"type": "integer"
}
}
}
"$ref": "#/responses/GetManyResponse"
}
}
},
Expand Down Expand Up @@ -417,6 +400,29 @@
"x-go-name": "Feedback",
"x-go-package": "TSS-microservices/core/models"
},
"GetManyResponseBody": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/FeedbackModel"
},
"x-go-name": "Data"
},
"limit": {
"type": "integer",
"format": "int64",
"x-go-name": "Limit"
},
"offset": {
"type": "integer",
"format": "int64",
"x-go-name": "Offset"
}
},
"x-go-package": "TSS-microservices/core/http/responses/feedback"
},
"NullTime": {
"description": "NullTime implements the [Scanner] interface so\nit can be used as a scan destination, similar to [NullString].",
"type": "object",
Expand Down Expand Up @@ -462,18 +468,23 @@
"additionalProperties": {
"type": "string"
},
"x-go-name": "PlaceHolder"
"x-go-name": "Placeholder"
},
"recipients": {
"type": "array",
"items": {
"type": "string"
},
"x-go-name": "Recipients"
"x-go-name": "Recipients",
"example": [
"[email protected]",
"[email protected]"
]
},
"subject": {
"type": "string",
"x-go-name": "Subject"
"x-go-name": "Subject",
"x-note": "All key must be capital the first character"
}
},
"x-go-package": "TSS-microservices/core/http/requests/hermes-forms"
Expand Down Expand Up @@ -532,6 +543,12 @@
}
},
"responses": {
"GetManyResponse": {
"description": "",
"schema": {
"$ref": "#/definitions/GetManyResponseBody"
}
},
"ValidationError": {
"description": "A ValidationError is an error that is used when the required input fails validation.",
"schema": {
Expand Down

0 comments on commit a949160

Please sign in to comment.