Skip to content

Conversation

@wangxuw
Copy link
Contributor

@wangxuw wangxuw commented Nov 20, 2025

add openapi tool

@wangxuw wangxuw changed the title feat: openapi tool tool: add openapi tool Nov 21, 2025
if !ok {
continue
}
switch param.Location {
Copy link
Contributor

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
Copy link
Contributor

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")
Copy link
Contributor

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")),
Copy link
Contributor

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{
Copy link
Contributor

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
Copy link
Contributor

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里要用 url.URL / url.PathEscape 做路径和参数转义。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants