-
Notifications
You must be signed in to change notification settings - Fork 153
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
fix(tools): openapi fixing and adding example #279
base: main
Are you sure you want to change the base?
Conversation
So far some fixes are in commits:
|
cf44945
to
984871a
Compare
984871a
to
b3d48c7
Compare
Using the github OpenAPI schema from https://github.com/github/rest-api-description/blob/main/descriptions/api.github.com/api.github.com.json causes this error. |
Try to find some smaller API or use it's subset. |
I was looking for some downloadable api schema from a site and downloading it in the sample but I couldn't find a good site that provides the api schema file and not required an API key or an access token for some of the API calls. |
src/tools/openapi.ts
Outdated
this.url = options.url; | ||
this.apiKey = options.apiKey; | ||
this.httpProxyUrl = options.httpProxyUrl; |
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.
Wrong. You don't need to set those properties because they are already set in this.options
src/tools/openapi.ts
Outdated
apiKey: undefined, | ||
httpProxyUrl: this.httpProxyUrl, | ||
url: this.url, |
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.
Remove because they are already propagated from ...super.createSnapshot()
b5b822f
to
df841c3
Compare
src/tools/openapi.ts
Outdated
const headers: { [key: string]: string } = { Accept: "application/json" }; | ||
if (this.apiKey) { | ||
headers["Authorization"] = `Bearer ${this.apiKey}`; | ||
if (this.options.apiKey) { | ||
headers["Authorization"] = `Bearer ${this.options.apiKey}`; | ||
} |
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.
create body in advance, pass it to the emitter
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.
I'm not sure what to do here. Would you explain a little more? Thanks!
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.
const options = {
...this.option.fetchOptions,
body: !isEmpty(input.body) ? input.body : undefined,
method: input.method.toLowerCase(),
headers: { Accept: "application/json", ...this.option.fetchOptions?.headers, },
}
await this.emitter.emit("beforeFetch", { url, optionsl });
try {
const response = await fetch(
url.toString(),
options,
);
const text = await response.text();
const output = new OpenAPIToolOutput(response.status, response.statusText, text);
await this.emitter.emit("afterFetch", { data: output, url });
return output;
}
and change type of fetchOptions
from any
to RequestInit
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.
Thanks!!
src/tools/openapi.ts
Outdated
if (this.apiKey) { | ||
headers["Authorization"] = `Bearer ${this.apiKey}`; | ||
if (this.options.apiKey) { | ||
headers["Authorization"] = `Bearer ${this.options.apiKey}`; |
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.
We can eliminate the 'apiKey' and the 'httpProxyUrl' parameters and allow the user to provide fetch options in the constructor. This solution will be more flexible.
) { | ||
let path: string = input.path || ""; | ||
const url = new URL(this.openApiSchema.servers[0].url); | ||
const url = new URL(this.options.url || this.openApiSchema.servers[0].url); |
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.
The 'url' parameter is a duplication of the openApiSchema.servers.url parameter which is required in the constructor. Remove this check in the constructor and either make the URL parameter required or check that at least one of the server's definitions is present.
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.
The servers
object seems optional. https://swagger.io/specification/
src/tools/openapi.ts
Outdated
@@ -30,15 +30,20 @@ import { ValueError } from "@/errors.js"; | |||
import { SchemaObject } from "ajv"; | |||
import { parse } from "yaml"; | |||
import { isEmpty } from "remeda"; | |||
import { HttpsProxyAgent } from "https-proxy-agent"; | |||
import fetch from "node-fetch"; | |||
|
|||
export interface OpenAPIToolOptions extends BaseToolOptions { | |||
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' and the 'description' are still not propagated to the object.
df841c3
to
fe50de0
Compare
Signed-off-by: Akihiko Kuroda <[email protected]>
fe50de0
to
1c17d17
Compare
Which issue(s) does this pull-request address?
Closes: #275
Description
Checklist
yarn lint
oryarn lint:fix
yarn format
oryarn format:fix
yarn test:unit
yarn test:e2e