43 lines
908 B
Go
43 lines
908 B
Go
// Package api_doc ...
|
|
//
|
|
// Description : api_doc ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 2024-07-19 11:45
|
|
package api_doc
|
|
|
|
import (
|
|
"errors"
|
|
"git.zhangdeman.cn/gateway/api-doc/define"
|
|
"git.zhangdeman.cn/zhangdeman/serialize"
|
|
)
|
|
|
|
// ParseOpenapi3 解析openapi文档
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 21:02 2025/2/25
|
|
func ParseOpenapi3(docUrl string, docContent string) (*define.OpenapiDoc, error) {
|
|
var (
|
|
docRes define.OpenapiDoc
|
|
err error
|
|
docByte []byte
|
|
)
|
|
|
|
if len(docContent) < 2 {
|
|
if len(docUrl) == 0 {
|
|
return nil, errors.New("doc url and doc content all empty")
|
|
}
|
|
if docByte, err = serialize.File.ReadFromRemote(docUrl); nil != err {
|
|
return nil, err
|
|
}
|
|
} else {
|
|
docByte = []byte(docContent)
|
|
}
|
|
if err = serialize.JSON.UnmarshalWithNumber(docByte, &docRes); nil != err {
|
|
return nil, err
|
|
}
|
|
return &docRes, nil
|
|
}
|