astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)
openapi-zod-client.vercel.app
824 stars 90 forks source link

Add option to export `endpoints` by default. #81

Closed ivenuss closed 1 year ago

ivenuss commented 1 year ago

Hi,

I would like to configure the axiosConfig, but I'm not able to do that without touching the generated file, which I don't want to. I want to keep it as source of truth to prevent future overrides.

This the solution that I came up with, but requires exporting the endpoints variable. Is there any better solution?

import { Zodios } from '@zodios/core';
import { ZodiosHooks } from '@zodios/react';
import { endpoints } from './generated'; // Not possible

const baseUrl = 'url';

const zodios = new Zodios(baseUrl, endpoints, {
  axiosConfig: {  ...  }
});

export const api = new ZodiosHooks('api', zodios);
astahmer commented 1 year ago

-t, --template <path> Template path for the handlebars template that will be used to generate the output

const endpoints = api.api; // a bit weird name clash here 🤷



![Screenshot 2023-01-30 at 09 51 21](https://user-images.githubusercontent.com/47224540/215430435-d600fe21-cb2b-4ecb-964a-97a29c387b60.png)

- finally, we could just add an option for the 3rd arg in the exported fn `createApiClient`

![Screenshot 2023-01-30 at 09 52 35](https://user-images.githubusercontent.com/47224540/215430718-105e0b51-15c1-4703-838a-be6adaef0f46.png)
astahmer commented 1 year ago

3rd arg for createApiClient just merged in 1.5.3

ivenuss commented 1 year ago

Glad to hear that the new createApiClient comes with this option. This totally solves my problem.

Thanks!