Skip to content

Expose the logic computing finalUrl #1161

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

Closed
1 task done
ysulyma opened this issue Jun 9, 2023 · 4 comments
Closed
1 task done

Expose the logic computing finalUrl #1161

ysulyma opened this issue Jun 9, 2023 · 4 comments
Labels
enhancement New feature or request openapi-fetch Relevant to the openapi-fetch library PRs welcome PRs are welcome to solve this issue!

Comments

@ysulyma
Copy link

ysulyma commented Jun 9, 2023

Description

I would like to remove hardcoded API routes from my code, and use this library instead. I no longer need these routes for the fetchers, but I still need them for testing code. Proposal is to export the internal logic for computing finalUrl.

Proposal

import fetchMock from "fetch-mock-jest";
import createClient from "openapi-fetch";

import { paths } from "./v1"; // (generated from openapi-typescript)

const { route } = createClient<paths>({ baseUrl: "https://myapi.dev/v1/" });

fetchMock.once(
  // "https://myapi.dev/v1/post/my-post?version=2"
  route("/post/{post_id}", {
    path: { post_id: "my-post" },
    query: { version: 2 },
  }),
  { /* ... */ }
);

Checklist

@ysulyma ysulyma added enhancement New feature or request PRs welcome PRs are welcome to solve this issue! openapi-fetch Relevant to the openapi-fetch library labels Jun 9, 2023
@drwpow
Copy link
Contributor

drwpow commented Jun 12, 2023

I’d be fine with exposing this under a named import, e.g. import { createFinalUrl } from 'openapi-fetch. Probably for most peoples’ testing purposes they’d probably still need to maintain their own testing utility functions for their setup (e.g. which mocking tool they use), but I agree it’d be annoying to have to monitor parity with openapi-fetch’s implementation detail of how a URL is created.

@ysulyma
Copy link
Author

ysulyma commented Jun 12, 2023

@drwpow if this is exposed on the return of createClient, then it can include baseUrl in the output. Or would you prefer an API like createFinalUrl(url, {baseUrl, path, query})?

@drwpow
Copy link
Contributor

drwpow commented Jun 12, 2023

Something like the latter, as this is probably more for testing purposes than anything else. And in that light, a more functionally-pure utility like your suggestion would be easier to deal with in general

@drwpow drwpow mentioned this issue Jun 16, 2023
3 tasks
@drwpow
Copy link
Contributor

drwpow commented Jun 16, 2023

This should be exposed now in 0.3.0.

@drwpow drwpow closed this as completed Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request openapi-fetch Relevant to the openapi-fetch library PRs welcome PRs are welcome to solve this issue!
Projects
None yet
Development

No branches or pull requests

2 participants