openapi generating feature

This commit is contained in:
John Guo
2021-10-06 15:24:01 +08:00
parent 18ede3ae1f
commit 4a1a8c9fc5
2 changed files with 17 additions and 2 deletions

View File

@ -80,6 +80,7 @@ const (
TagNamePath = `path`
TagNameMethod = `method`
TagNameIn = `in`
TagNameMime = `mime`
)
var (

View File

@ -136,7 +136,14 @@ func (oai *OpenApiV3) addPath(in addPathInput) error {
}
)
// Supported mime types of request.
for _, v := range oai.Config.ReadContentTypes {
var (
contentTypes = oai.Config.ReadContentTypes
tagMimeValue = gmeta.Get(inputObject.Interface(), TagNameMime).String()
)
if tagMimeValue != "" {
contentTypes = gstr.SplitAndTrim(tagMimeValue, ",")
}
for _, v := range contentTypes {
requestBody.Content[v] = MediaType{
Schema: &SchemaRef{
Ref: inputStructTypeName,
@ -178,7 +185,14 @@ func (oai *OpenApiV3) addPath(in addPathInput) error {
}
}
// Supported mime types of response.
for _, v := range oai.Config.WriteContentTypes {
var (
contentTypes = oai.Config.ReadContentTypes
tagMimeValue = gmeta.Get(outputObject.Interface(), TagNameMime).String()
)
if tagMimeValue != "" {
contentTypes = gstr.SplitAndTrim(tagMimeValue, ",")
}
for _, v := range contentTypes {
response.Content[v] = MediaType{
Schema: &SchemaRef{
Ref: outputStructTypeName,