增加数据结构属性定义

This commit is contained in:
白茶清欢 2024-07-19 21:34:12 +08:00
parent dde8315404
commit 11bf768221

View File

@ -13,11 +13,21 @@ package define
//
// Date : 12:16 2024/7/19
type OpenapiDoc struct {
Openapi string `json:"openapi" required:"true"` // 必选. 这个字符串必须是开放 API 规范版本号提到的符合语义化版本号规范的版本号。openapi字段应该被工具或者客户端用来解释 OpenAPI 文档.
Info *Info `json:"info,omitempty" required:"true"` // 必选。此字段提供 API 相关的元数据。相关工具可能需要这个字段。
Servers []*ServerItem `json:"servers"` // 服务环境
Tags []*TagItem `json:"tags"` // 全部标签列表
Paths map[string]*PathConfig `json:"paths"` // 接口路径 -> 接口请求方法 -> 具体配置
Openapi string `json:"openapi" required:"true"` // 必选. 这个字符串必须是开放 API 规范版本号提到的符合语义化版本号规范的版本号。openapi字段应该被工具或者客户端用来解释 OpenAPI 文档.
Info *Info `json:"info,omitempty" required:"true"` // 必选。此字段提供 API 相关的元数据。相关工具可能需要这个字段。
Servers []*ServerItem `json:"servers"` // 服务环境
Components *Components `json:"components,omitempty"` // 数据结构
Tags []*TagItem `json:"tags"` // 全部标签列表
Paths map[string]*PathConfig `json:"paths"` // 接口路径 -> 接口请求方法 -> 具体配置
}
// Components 数据结构定义
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 21:22 2024/7/19
type Components struct {
Schemas map[string]*Schema `json:"schemas"` // 数据结构定义
}
// PathConfig ...
@ -125,15 +135,16 @@ type Schema struct {
//
// Date : 17:05 2024/7/19
type Property struct {
Type string `json:"type"` // 数据类型, swagger本身的定义
Format string `json:"format"` // 对应编程语言中的数据类型描述
Default any `json:"default"` // 默认值 : 不同于 JSON Schema这个值必须符合定义与相同级别的 Schema 对象 中定义的类型,比如 type 是 string那么 default 可以是 "foo" 但不能是 1。
Description string `json:"description"` // 数据描述, CommonMark syntax可以被用来呈现富文本格式.
AllOf []*PropertyXOf `json:"allOf,omitempty"` // type 是一个对象, allOf 指向对象描述
OneOf []*PropertyXOf `json:"oneOf,omitempty"` // type 是一个对象, allOf 指向对象描述
AnyOf []*PropertyXOf `json:"anyOf,omitempty"` // type 是一个对象, allOf 指向对象描述
Items *PropertyXOf `json:"items,omitempty"` // items 必须存在如果 type 的值是 array。
Properties map[string]*Property `json:"properties,omitempty"` // type = object 时, 定义对象属性
Type string `json:"type"` // 数据类型, swagger本身的定义
Format string `json:"format"` // 对应编程语言中的数据类型描述
Default any `json:"default"` // 默认值 : 不同于 JSON Schema这个值必须符合定义与相同级别的 Schema 对象 中定义的类型,比如 type 是 string那么 default 可以是 "foo" 但不能是 1。
Description string `json:"description"` // 数据描述, CommonMark syntax可以被用来呈现富文本格式.
AllOf []*PropertyXOf `json:"allOf,omitempty"` // type 是一个对象, allOf 指向对象描述
OneOf []*PropertyXOf `json:"oneOf,omitempty"` // type 是一个对象, allOf 指向对象描述
AnyOf []*PropertyXOf `json:"anyOf,omitempty"` // type 是一个对象, allOf 指向对象描述
Items *PropertyXOf `json:"items,omitempty"` // items 必须存在如果 type 的值是 array。
AdditionalProperties *PropertyXOf `json:"additionalProperties,omitempty"` // additionalProperties 是一个用于描述模型中包含未在属性列表中定义的额外属性的选项。它允许接受任意的一个或多个键值对。它的作用是为了在模型定义中包含未知或动态属性。通常,在设计 API 时,我们无法预先知道 API 用户会传递什么样的额外属性,这时就可以使用 additionalProperties 功能来灵活地处理这些未知属性。
Properties map[string]*Property `json:"properties,omitempty"` // type = object 时, 定义对象属性
}
// PropertyXOf ...