Skip to content
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

feat: add ofetch http client #696

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

samydoesit
Copy link

This pull request introduces a new feature to the swagger-typescript-api, allowing users to generate a HTTP client utilizing the unjs/ofetch library for making HTTP requests. This is facilitated through the use of the --ofetch command-line flag. The addition of ofetch support is aimed at providing developers with more choices for their HTTP client library, especially in projects where ofetch is already in use or preferred.

There may be areas of improvement or alternative approaches that could improve the implementation or usefulness of the feature. I'm open to any feedback, suggestions or contributions from the community to further refine this feature and would greatly appreciate it. :)

@samydoesit samydoesit force-pushed the add-ofetch-http-client branch from 8fb9a1a to 92f3a6d Compare March 27, 2024 22:11
@smorimoto smorimoto added the enhancement New feature or request label Jun 27, 2024
@smorimoto smorimoto requested a review from js2me June 27, 2024 22:57
@productdevbook
Copy link

What do I need to do to use it now?

@samydoesit samydoesit force-pushed the add-ofetch-http-client branch 3 times, most recently from 4e2a0af to ed6bc4f Compare November 10, 2024 01:43
@samydoesit
Copy link
Author

Hi i've updated the branch to the latest version and created an npm package with the changes.
You can install it using: npm i @samydoesit/swagger-typescript-api

await generateApi({
      fileName: "schema",
      input: path.resolve(import.meta.dirname, "schema.json"),
      output: tmpdir,
      silent: true,
      generateClient: true,
      httpClientType: "ofetch",
    });

(Please take a look at the test files for usage examples.)

I couldn't get the CLI to work for now.

@samydoesit samydoesit force-pushed the add-ofetch-http-client branch from ed6bc4f to 0d17423 Compare November 11, 2024 21:45
@smorimoto smorimoto requested a review from Copilot December 28, 2024 17:32

Choose a reason for hiding this comment

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

Copilot reviewed 9 out of 12 changed files in this pull request and generated no comments.

Files not reviewed (3)
  • templates/base/http-clients/ofetch-http-client.ejs: Language not supported
  • templates/default/procedure-call.ejs: Language not supported
  • README.md: Evaluated as low risk
Comments suppressed due to low confidence (2)

tests/spec/ofetch/basic.test.ts:10

  • [nitpick] The variable name 'tmpdir' could be more descriptive. Consider renaming it to 'temporaryDirectory'.
let tmpdir = "";

index.ts:324

  • The nested ternary operator for httpClientType assignment is confusing and could lead to unintended behavior. Consider simplifying it for better readability and maintainability.
httpClientType: args["http-client"] || args.axios ? HTTP_CLIENT.AXIOS : args.ofetch ? HTTP_CLIENT.OFETCH : HTTP_CLIENT.FETCH,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants