feat: 支持设置公共的请求参数
This commit is contained in:
@@ -63,3 +63,25 @@ func WithSecurity(securityTable *openapi3.SecuritySchemes) OptionFunc {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithCommonParameter 设置公共请求蚕食
|
||||
func WithCommonParameter(commonParameterTable *openapi3.ParametersMap) OptionFunc {
|
||||
return func(t *openapi3.T) {
|
||||
if nil == commonParameterTable {
|
||||
return
|
||||
}
|
||||
if nil == t.Components {
|
||||
t.Components = &openapi3.Components{}
|
||||
}
|
||||
if nil == t.Components.Parameters {
|
||||
t.Components.Parameters = make(map[string]*openapi3.ParameterRef)
|
||||
}
|
||||
// 不要直接复制, 逐个设置, 可以重复调用, 后面的会覆盖前面的
|
||||
for k, v := range *commonParameterTable {
|
||||
if nil == v {
|
||||
continue
|
||||
}
|
||||
t.Components.Parameters[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user