Repository: openapi-ts/openapi-typescript

Issue #1723: Union type for `error` disappears in typescript-fetch v0.10
Created: 2024-06-24T01:37:03Z
Description
The union type for the error object returned by fetch has changed in typescript-fetch v0.10 and later versions.
Reproduction
I updated typescript-fetch to v0.10.1.
After the update, the type inference for the error object returned by fetch changed as follows:
Before v0.9.7

const error: { message: string } | Record<string, never> | undefined

v0.10.0 and Later

const error: { message: string } | undefined

OpenAPI YAML
I change the error response based on the type of error. For example, in the case of a 404 error, only a message is returned. For a 422 error, error messages are returned for each field.
# Partial YAML
      responses:
        '404':
          description: NotFound
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                required:
                  - message
        '422':
          description: Bad parameters
          content:
            application/json:
              schema:
                title: ''
                type: object
                properties:
                  errors:
                    type: object
                    properties: {}
                required:
                  - errors
Expected result
It would be great if the error type could be the same as in previous versions:
const error: { message: string } | Record<string, never> | undefined
Checklist

 I’m willing to open a PR (see CONTRIBUTING.md)

Duplicate issue #1820: Missing codes in the errors union
Created: 2024-08-05T08:25:44Z
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.

Expected result
Union of all errors 401, 403, 403...
Checklist

 I’m willing to open a PR (see CONTRIBUTING.md)

Closing comment (2024-08-08T02:12:37Z): This issue appears to be a duplicate of #1723 in which there is more discussion and some proposed approaches to resolving the problem.