feat: 支持设置公共的请求参数

This commit is contained in:
2026-01-07 12:35:43 +08:00
parent 55238e0de8
commit 7de0c874c6
3 changed files with 43 additions and 0 deletions

View File

@@ -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
}
}
}