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

Generated functions only support one of the major content-types per enpoint. #369

Open
ehvattum opened this issue Jan 18, 2023 · 0 comments

Comments

@ehvattum
Copy link
Contributor

Given the api spec at https://gist.github.com/ehvattum/e7fdc53bda8a3d03556c0c649cdef7c9,

Oazapftz will generate an api client that looks like:

export function getPdfOrJson(opts?: Oazapfts.RequestOpts) {
    return oazapfts.fetchJson<{
        status: 200;
        data: Blob;
    } | {
        status: 404;
        data: {
            "error-message"?: string;
        };
    }>("/pdf-or-json", {
        ...opts
    });
}

It will as shown above select the fetchJson function as the wrapper. and that wrapper has poor handling if a Blob is ever returned.

This seems like a systematic bug, where the fetch-wrapper selected tests for JSON compatibility in any of the content-types for any of the response objects defined for an endpoint.
The bug manifests in https://github.com/oazapfts/oazapfts/blob/main/src/codegen/generate.ts#L689, where it selects the response type.

Ideally, the generated code should be wrapped with code that can handle all defined content types, and not default to the JSON compatible one as long as any response is JSON compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant