Skip to content

Commit 3438969

Browse files
committed
fix: typo
1 parent d70b3fb commit 3438969

File tree

5 files changed

+62
-43
lines changed

5 files changed

+62
-43
lines changed

openapi/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (d *Document) build(p *message.Printer, lang language.Tag, filterTags []str
5050
Tags: tags,
5151
ExternalDocs: d.externalDocs.build(p),
5252

53-
XFavicon: d.favicon,
53+
XLogo: d.logo,
5454
XAssets: d.assetsURL,
5555
XLanguage: lang.String(),
5656
XModified: d.last.Format(time.RFC3339),

openapi/openapi.go

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type (
8888

8989
templateName string
9090
assetsURL string
91-
favicon string
91+
logo string
9292

9393
// 其它一些状态的设置
9494

@@ -98,20 +98,22 @@ type (
9898
s web.Server
9999
}
100100

101+
paths = orderedmap.OrderedMap[string, *renderer[pathItemRenderer]]
102+
101103
openAPIRenderer struct {
102-
OpenAPI string `json:"openapi" yaml:"openapi"`
103-
Info *infoRenderer `json:"info" yaml:"info"`
104-
Servers []*serverRenderer `json:"servers,omitempty" yaml:"servers,omitempty"`
105-
Paths *orderedmap.OrderedMap[string, *renderer[pathItemRenderer]] `json:"paths,omitempty" yaml:"paths,omitempty"`
106-
WebHooks *orderedmap.OrderedMap[string, *renderer[pathItemRenderer]] `json:"webhooks,omitempty" yaml:"webhooks,omitempty"`
107-
Components *componentsRenderer `json:"components,omitempty" yaml:"components,omitempty"`
108-
Security []*orderedmap.OrderedMap[string, []string] `json:"security,omitempty" yaml:"security,omitempty"`
109-
Tags []*tagRenderer `json:"tags,omitempty" yaml:"tags,omitempty"`
110-
ExternalDocs *externalDocsRenderer `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
104+
OpenAPI string `json:"openapi" yaml:"openapi"`
105+
Info *infoRenderer `json:"info" yaml:"info"`
106+
Servers []*serverRenderer `json:"servers,omitempty" yaml:"servers,omitempty"`
107+
Paths *paths `json:"paths,omitempty" yaml:"paths,omitempty"`
108+
WebHooks *paths `json:"webhooks,omitempty" yaml:"webhooks,omitempty"`
109+
Components *componentsRenderer `json:"components,omitempty" yaml:"components,omitempty"`
110+
Security []*orderedmap.OrderedMap[string, []string] `json:"security,omitempty" yaml:"security,omitempty"`
111+
Tags []*tagRenderer `json:"tags,omitempty" yaml:"tags,omitempty"`
112+
ExternalDocs *externalDocsRenderer `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
111113

112114
// 扩展内容
113115

114-
XFavicon string `json:"x-favicon,omitempty" yaml:"x-favicon,omitempty"`
116+
XLogo string `json:"x-logo,omitempty" yaml:"x-logo,omitempty"`
115117
XAssets string `json:"x-assets,omitempty" yaml:"x-assets,omitempty"`
116118
XLanguage string `json:"x-language,omitempty" yaml:"x-language,omitempty"`
117119
XModified string `json:"x-modified,omitempty" yaml:"x-modified,omitempty"`
@@ -315,10 +317,12 @@ type (
315317
Content map[string]*Schema // key = mimetype
316318
}
317319

320+
content = orderedmap.OrderedMap[string, *mediaTypeRenderer]
321+
318322
responseRenderer struct {
319323
Description string `json:"description" yaml:"description"`
320324
Headers *orderedmap.OrderedMap[string, *renderer[headerRenderer]] `json:"headers,omitempty" yaml:"headers,omitempty"`
321-
Content *orderedmap.OrderedMap[string, *mediaTypeRenderer] `json:"content,omitempty" yaml:"content,omitempty"`
325+
Content *content `json:"content,omitempty" yaml:"content,omitempty"`
322326
}
323327

324328
Request struct {
@@ -333,9 +337,9 @@ type (
333337
}
334338

335339
requestRenderer struct {
336-
Content *orderedmap.OrderedMap[string, *mediaTypeRenderer] `json:"content" yaml:"content"`
337-
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
338-
Description string `json:"description" yaml:"description"`
340+
Content *content `json:"content" yaml:"content"`
341+
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
342+
Description string `json:"description" yaml:"description"`
339343
}
340344

341345
Server struct {
@@ -344,10 +348,12 @@ type (
344348
Variables []*ServerVariable
345349
}
346350

351+
serverVars = orderedmap.OrderedMap[string, *serverVariableRenderer]
352+
347353
serverRenderer struct {
348-
URL string `json:"url" yaml:"url"`
349-
Description string `json:"description,omitempty" yaml:"description,omitempty"`
350-
Variables *orderedmap.OrderedMap[string, *serverVariableRenderer] `json:"variables,omitempty" yaml:"variables,omitempty"`
354+
URL string `json:"url" yaml:"url"`
355+
Description string `json:"description,omitempty" yaml:"description,omitempty"`
356+
Variables *serverVars `json:"variables,omitempty" yaml:"variables,omitempty"`
351357
}
352358

353359
ServerVariable struct {

openapi/option.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ func WithOptions(enable bool) Option {
3434
// assets 资源基地址,apidoc 的浏览工具一般都是在一个 html 文件中引入一些依赖文件,
3535
// assets 就是这些依赖文件的基地址,可是指向一个 CDN 的地址,比如 swagger 的
3636
// https://unpkg.com/[email protected]
37-
// favicon 图标,请使用 icon 或是 png 这种大部分浏览器都支持的图标格式,
38-
// 可以为空。尽量提供比较大的图标,可能会被用在除 favicon 之外的地方;
37+
// logo LOGO 图标,可能还会被用于 favicon 等功能,请确保格式能被正确处理,可以为空;
3938
//
4039
// NOTE: [github.com/issue9/webuse/openapi] 下实现了部分简单的模板。
41-
func WithHTML(tpl, assets, favicon string) Option {
40+
func WithHTML(tpl, assets, logo string) Option {
4241
return func(d *Document) {
4342
d.templateName = tpl
4443
d.assetsURL = assets
45-
d.favicon = favicon
44+
d.logo = logo
4645
}
4746
}
4847

@@ -148,7 +147,7 @@ func WithCookie(global bool, p ...*Parameter) Option {
148147
}
149148
}
150149

151-
// WithQuery 向 components/paramters 添加 InQuery 的对象
150+
// WithQuery 向 components/parameters 添加 InQuery 的对象
152151
//
153152
// p 要求必须指定 Ref.Ref。其它接口可以通过 ref 引用此对象。
154153
//
@@ -164,7 +163,7 @@ func WithQuery(p ...*Parameter) Option {
164163
}
165164
}
166165

167-
// WithPath 向 components/paramters 添加 InPath 的对象
166+
// WithPath 向 components/parameters 添加 InPath 的对象
168167
//
169168
// p 要求必须指定 Ref.Ref。其它接口可以通过 ref 引用此对象。
170169
//

openapi/option_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestWithHTML(t *testing.T) {
2121
d := New(ss, web.Phrase("desc"), WithHTML("tpl", "./dist", "./dist/favicon.png"))
2222
a.Equal(d.assetsURL, "./dist").
2323
Equal(d.templateName, "tpl").
24-
Equal(d.favicon, "./dist/favicon.png")
24+
Equal(d.logo, "./dist/favicon.png")
2525
}
2626

2727
func TestNewLicense(t *testing.T) {
@@ -60,6 +60,18 @@ func TestWithResponse(t *testing.T) {
6060
Equal(d.responses["500"], "500")
6161
}
6262

63+
func TestWithProblemResponse(t *testing.T) {
64+
a := assert.New(t, false)
65+
ss := newServer(a)
66+
67+
d := New(ss, web.Phrase("desc"), WithProblemResponse())
68+
a.NotNil(d).
69+
Length(d.responses, 2).
70+
Length(d.components.responses, 1).
71+
Equal(d.responses["4XX"], "problem").
72+
Equal(d.responses["5XX"], "problem")
73+
}
74+
6375
func TestWithMediaType(t *testing.T) {
6476
a := assert.New(t, false)
6577
ss := newServer(a)

openapi/schema.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,25 @@ type Schema struct {
6161
Enum []any
6262
}
6363

64+
type properties = orderedmap.OrderedMap[string, *renderer[schemaRenderer]]
65+
6466
type schemaRenderer struct {
65-
Type string `json:"type" yaml:"type"`
66-
XML *XML `json:"xml,omitempty" yaml:"xml,omitempty"`
67-
ExternalDocs *externalDocsRenderer `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
68-
Title string `json:"title,omitempty" yaml:"title,omitempty"`
69-
Description string `json:"description,omitempty" yaml:"description,omitempty"`
70-
AllOf []*renderer[schemaRenderer] `json:"allOf,omitempty" yaml:"allOf,omitempty"`
71-
OneOf []*renderer[schemaRenderer] `json:"oneOf,omitempty" yaml:"oneOf,omitempty"`
72-
AnyOf []*renderer[schemaRenderer] `json:"anyOf,omitempty" yaml:"anyOf,omitempty"`
73-
Format string `json:"format,omitempty" yaml:"format,omitempty"`
74-
Items *renderer[schemaRenderer] `json:"items,omitempty" yaml:"items,omitempty"`
75-
Properties *orderedmap.OrderedMap[string, *renderer[schemaRenderer]] `json:"properties,omitempty" yaml:"properties,omitempty"`
76-
AdditionalProperties *renderer[schemaRenderer] `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"`
77-
Required []string `json:"required,omitempty" yaml:"required,omitempty"`
78-
Minimum int `json:"minimum,omitempty" yaml:"minimum,omitempty"`
79-
Maximum int `json:"maximum,omitempty" yaml:"maximum,omitempty"`
80-
Enum []any `json:"enum,omitempty" yaml:"enum,omitempty"`
67+
Type string `json:"type" yaml:"type"`
68+
XML *XML `json:"xml,omitempty" yaml:"xml,omitempty"`
69+
ExternalDocs *externalDocsRenderer `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
70+
Title string `json:"title,omitempty" yaml:"title,omitempty"`
71+
Description string `json:"description,omitempty" yaml:"description,omitempty"`
72+
AllOf []*renderer[schemaRenderer] `json:"allOf,omitempty" yaml:"allOf,omitempty"`
73+
OneOf []*renderer[schemaRenderer] `json:"oneOf,omitempty" yaml:"oneOf,omitempty"`
74+
AnyOf []*renderer[schemaRenderer] `json:"anyOf,omitempty" yaml:"anyOf,omitempty"`
75+
Format string `json:"format,omitempty" yaml:"format,omitempty"`
76+
Items *renderer[schemaRenderer] `json:"items,omitempty" yaml:"items,omitempty"`
77+
Properties *properties `json:"properties,omitempty" yaml:"properties,omitempty"`
78+
AdditionalProperties *renderer[schemaRenderer] `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"`
79+
Required []string `json:"required,omitempty" yaml:"required,omitempty"`
80+
Minimum int `json:"minimum,omitempty" yaml:"minimum,omitempty"`
81+
Maximum int `json:"maximum,omitempty" yaml:"maximum,omitempty"`
82+
Enum []any `json:"enum,omitempty" yaml:"enum,omitempty"`
8183
}
8284

8385
func (d *Document) newSchema(t reflect.Type) *Schema {
@@ -98,7 +100,7 @@ func NewSchema(t reflect.Type, title, desc web.LocaleStringer) *Schema {
98100

99101
var timeType = reflect.TypeFor[time.Time]()
100102

101-
// d 仅用于查找其关联的 components/schema 中是否存在相同名称的对象,如果存在则直接生成引用对象。
103+
// d 仅用于查找其关联的 components/schemas 中是否存在相同名称的对象,如果存在则直接生成引用对象。
102104
//
103105
// desc 表示类型 t 的 Description 属性
104106
// rootName 根结构体的名称,主要是为了解决子元素又引用了根元素的类型引起的循环引用。

0 commit comments

Comments
 (0)