-
Notifications
You must be signed in to change notification settings - Fork 55
tool: add openapi tool #719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
cba5853 to
dba839e
Compare
| if !ok { | ||
| continue | ||
| } | ||
| switch param.Location { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里你收集了四种 params,但是后面只用到了 path params
| if param == nil { | ||
| continue | ||
| } | ||
| pv := param.Value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pv 也需要查一下 panic
|
|
||
| func (s *specProcessor) processOperations() error { | ||
| if len(s.doc.Servers) == 0 { | ||
| return fmt.Errorf("no server defined") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里有点严格了,根据规范,没提供 servers 的时候默认 / 就好,而且你下面默认只用第 0 个 servers 应该也不太合理。
https://swagger.io/docs/specification/v3_0/api-host-and-base-path/
| name: "create_toolset_ok_uri", | ||
| args: args{ | ||
| opts: []Option{ | ||
| WithSpecLoader(NewURILoader("https://petstore3.swagger.io/api/v3/openapi.json")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
测试建议不要依赖公网资源,否则 ci 不稳定。可以在本地做一个 testdata 文件
| } | ||
| } | ||
| } | ||
| o.responseParam = &APIParameter{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里构造了 responseParam,toolOutputSchema() 那边为什么不用呢?
| // openAPIToolSet is a set of tools. | ||
| type openAPIToolSet struct { | ||
| spec *specProcessor | ||
| name string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 name 可以考虑给一个默认值,目前默认为空的话,NamedToolSet 那边不会给 Tool 名加前缀。
| func makeRequestURL(endpoint *operationEndpoint, pathParams map[string]any) string { | ||
| endpointURL := endpoint.baseURL + endpoint.path | ||
| for arg, value := range pathParams { | ||
| endpointURL = strings.ReplaceAll(endpointURL, fmt.Sprintf("{%s}", arg), fmt.Sprintf("%v", value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里要用 url.URL / url.PathEscape 做路径和参数转义。
add openapi tool