更新单元测试
This commit is contained in:
parent
93316f739f
commit
6642b9bcef
213
parser_test.go
213
parser_test.go
@ -11,6 +11,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.zhangdeman.cn/gateway/api-doc/define"
|
||||
"os"
|
||||
"os/user"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -20,215 +22,10 @@ import (
|
||||
//
|
||||
// Date : 17:55 2024/7/19
|
||||
func Test_parser_Openapi3(t *testing.T) {
|
||||
testData := `{
|
||||
"openapi": "3.0.1",
|
||||
"info": {
|
||||
"title": "测试",
|
||||
"description": "测试",
|
||||
"contact": {
|
||||
"name": "白茶",
|
||||
"url": "http://www.baidu.com",
|
||||
"email": "go@email.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "Apache-2.0",
|
||||
"url": "https://www.apache.org/licenses/LICENSE-2.0.txt"
|
||||
},
|
||||
"version": ""
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "http://www.baidu.com/"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/test": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"测试接口生成"
|
||||
],
|
||||
"summary": "测试接口",
|
||||
"description": "测试接口",
|
||||
"requestBody": {
|
||||
"description": "参数结构",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/test.jsonBody"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "返回数据",
|
||||
"content": {
|
||||
"*/*": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/test.200.output"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-codegen-request-body-name": "jsonBody"
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"object_map": {
|
||||
"type": "object"
|
||||
},
|
||||
"test.200.output": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"nick_name": {
|
||||
"type": "string",
|
||||
"description": "姓名"
|
||||
},
|
||||
"obj": {
|
||||
"type": "object",
|
||||
"description": "测试返回生成map",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/object_map"
|
||||
}
|
||||
]
|
||||
},
|
||||
"person": {
|
||||
"type": "object",
|
||||
"description": "参数描述",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/test.200.output.person"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"format": "map[string]any"
|
||||
},
|
||||
"test.200.output.person": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"nick_name": {
|
||||
"type": "string",
|
||||
"description": "昵称"
|
||||
}
|
||||
},
|
||||
"format": "map[string]any"
|
||||
},
|
||||
"test.jsonBody": {
|
||||
"required": [
|
||||
"age",
|
||||
"name"
|
||||
],
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"age": {
|
||||
"type": "integer",
|
||||
"description": "年龄"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "姓名"
|
||||
},
|
||||
"obj": {
|
||||
"type": "object",
|
||||
"description": "测试global_map",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/object_map"
|
||||
}
|
||||
]
|
||||
},
|
||||
"person": {
|
||||
"type": "object",
|
||||
"description": "参数描述",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/test.jsonBody.person"
|
||||
}
|
||||
]
|
||||
},
|
||||
"test_list": {
|
||||
"type": "array",
|
||||
"description": "参数描述",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/test.jsonBody.test_list.item"
|
||||
}
|
||||
}
|
||||
},
|
||||
"format": "map[string]any"
|
||||
},
|
||||
"test.jsonBody.person": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"job": {
|
||||
"type": "object",
|
||||
"description": "参数描述",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/test.jsonBody.person.job"
|
||||
}
|
||||
]
|
||||
},
|
||||
"sex": {
|
||||
"type": "string",
|
||||
"description": "性别"
|
||||
}
|
||||
},
|
||||
"format": "map[string]any"
|
||||
},
|
||||
"test.jsonBody.person.job": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"list": {
|
||||
"type": "array",
|
||||
"description": "性别",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"type": "integer",
|
||||
"description": "测试工作"
|
||||
},
|
||||
"year": {
|
||||
"type": "array",
|
||||
"description": "年份",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"format": "map[string]any"
|
||||
},
|
||||
"test.jsonBody.test_list.item": {
|
||||
"required": [
|
||||
"age",
|
||||
"name"
|
||||
],
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"age": {
|
||||
"type": "integer",
|
||||
"description": "年龄"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "年龄"
|
||||
}
|
||||
},
|
||||
"format": "map[string]any"
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-original-swagger-version": "2.0"
|
||||
}`
|
||||
current, _ := user.Current()
|
||||
byteData, _ := os.ReadFile(current.HomeDir + "/Downloads/test-openapi-doc.json")
|
||||
var data define.OpenapiDoc
|
||||
err := json.Unmarshal([]byte(testData), &data)
|
||||
err := json.Unmarshal(byteData, &data)
|
||||
if nil != err {
|
||||
fmt.Println("解析失败 : " + err.Error())
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user