Support NextJS 13 fetch options
Since NextJS fetch has been introduced.
There is no way yet for the generated code to input the cache and next.revalidate fetch's options.
Since next.revalidate and cache options aren't even part of OpenAPI.
I think we should introduce nextjs-fetch client.
Maybe something like
export class NextJSFetchHttpRequest extends BaseHttpRequest {
cache?: string;
revalidate?: number;
constructor(config: OpenAPIConfig) {
super(config);
}
public override request<T>(options: ApiRequestOptions): CancelablePromise<T> {
return __request(this.config, options); // TODO inject cache and revalidate
}
}
Or even better if we could add ApiRequest options which tie to each client.
For example, I could do something like this when I make an API request.
But only when I generate the code using nextjs-fetch client.
myOpenApi.getUsers({ cache: 'no-store' });
I faced the same issue and this is how i solved it for now
https://beta.nextjs.org/docs/api-reference/segment-config#dynamic
Needed this too. I forked it and added quick hacky support on branch nextjsfetch in my fork: https://github.com/ferdikoomen/openapi-typescript-codegen/compare/master...justin-calleja:openapi-typescript-codegen:nextjsfetch
Needed this too. I forked it and added quick hacky support on branch
nextjsfetchin my fork: master...justin-calleja:openapi-typescript-codegen:nextjsfetch
@justin-calleja I might be missing something obvious, but I'm trying to use your patch but can't figure out how to pass a cache option to my request... Could you give an example?
@fullyherge you first need to generate your TS by passing --client nextjs_fetch to the cli. Then, you should be able to pass in a second arg to your generated "SDK" which gets passed to the underlying fetch call - so you can pass:
{
next: { revalidate: 15 },
},
for e.g. and it should get passed to fetch