Skip to content

Missing codes in the errors union #1820

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
pstachula-dev opened this issue Aug 5, 2024 · 3 comments · Fixed by #1937
Closed
1 task

Missing codes in the errors union #1820

pstachula-dev opened this issue Aug 5, 2024 · 3 comments · Fixed by #1937
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library

Comments

@pstachula-dev
Copy link

pstachula-dev commented Aug 5, 2024

Description

It seems that the library generated error types and returns only the first error code instead of the union for the other types. When we have declared other error codes for 401 and 404, only 401 is returned.

Reproduction

           200: {
                headers: {
                    [name: string]: unknown;
                };
                content: {
                    "application/json": components["schemas"]["CatFact"];
                };
            };

            /** @description error 401 */
            401: {
                headers: {
                    [name: string]: unknown;
                };
                content: {
                    "application/json": components["schemas"]["ErrorUnauthorized"];
                };
            };
            /** @description error 403 */
            403: {
                headers: {
                    [name: string]: unknown;
                };
                content: {
                    "application/json": components["schemas"]["ErrorForbidden"];
                };
            };
            /** @description not found */
            404: {
                headers: {
                    [name: string]: unknown;
                };
                content: {
                    "application/json": components["schemas"]["Error"];
                };
            };

Full schema: https://pastebin.com/aBhmzfE2

As far as I can see, the errors are sorted in ascending order and only the first one is taken into account, the others are omitted.
image

Expected result

Union of all errors 401, 403, 403...

Checklist

@pstachula-dev pstachula-dev added bug Something isn't working openapi-fetch Relevant to the openapi-fetch library labels Aug 5, 2024
@pstachula-dev
Copy link
Author

This looks like a intentional solution. 🤔

/**
 * Return first 5XX or 4XX response (in that order) from a Response Object Map
 */ 
export type ErrorResponse<T, Media extends MediaType = MediaType> = FilterKeys<

@stevegoossens
Copy link

This also bit me (first time user) when I have 200, 404, 500 responses, each with a different body schema. For unit testing a 404, I was wondering why the error type returned from the function matched the 500 schema.

Surely it would make more sense to union the error schemas (as suggested by this issue)?

@stevegoossens
Copy link

This issue appears to be a duplicate of #1723 in which there is more discussion and some proposed approaches to resolving the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants