增加单元测试
This commit is contained in:
parent
d0d751b44f
commit
c7765d57c1
@ -39,9 +39,9 @@ type PathItemConfig struct {
|
|||||||
Post *PathItemOperationConfig `json:"post"` // 定义适用于此路径的 POST 操作。
|
Post *PathItemOperationConfig `json:"post"` // 定义适用于此路径的 POST 操作。
|
||||||
Delete *PathItemOperationConfig `json:"delete"` // DELETE
|
Delete *PathItemOperationConfig `json:"delete"` // DELETE
|
||||||
Options *PathItemOperationConfig `json:"options"` // 定义适用于此路径的 OPTIONS 操作。
|
Options *PathItemOperationConfig `json:"options"` // 定义适用于此路径的 OPTIONS 操作。
|
||||||
Head string `json:"head"` // 定义适用于此路径的 HEAD 操作。
|
Head *PathItemOperationConfig `json:"head"` // 定义适用于此路径的 HEAD 操作。
|
||||||
Patch string `json:"patch"` // 定义适用于此路径的 PATCH 操作。
|
Patch *PathItemOperationConfig `json:"patch"` // 定义适用于此路径的 PATCH 操作。
|
||||||
Trace string `json:"trace"` // 定义适用于此路径的 TRACE 操作。
|
Trace *PathItemOperationConfig `json:"trace"` // 定义适用于此路径的 TRACE 操作。
|
||||||
Parameters []*PathConfigParameter `json:"parameters"` // 参数列表, 对于所有请求生效
|
Parameters []*PathConfigParameter `json:"parameters"` // 参数列表, 对于所有请求生效
|
||||||
}
|
}
|
||||||
|
|
||||||
|
237
parser_test.go
Normal file
237
parser_test.go
Normal file
@ -0,0 +1,237 @@
|
|||||||
|
// Package api_doc ...
|
||||||
|
//
|
||||||
|
// Description : api_doc ...
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 2024-07-19 17:52
|
||||||
|
package api_doc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"git.zhangdeman.cn/gateway/api-doc/define"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Test_parser_Openapi3 测试数据结构定义正确性
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// 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"
|
||||||
|
}`
|
||||||
|
var data define.OpenapiDoc
|
||||||
|
err := json.Unmarshal([]byte(testData), &data)
|
||||||
|
if nil != err {
|
||||||
|
fmt.Println("解析失败 : " + err.Error())
|
||||||
|
} else {
|
||||||
|
fmt.Println("解析成功")
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user