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

Default response types (error) override response types #506

Closed
dudasaus opened this issue Apr 28, 2024 · 3 comments
Closed

Default response types (error) override response types #506

dudasaus opened this issue Apr 28, 2024 · 3 comments
Labels
bug 🔥 Something isn't working

Comments

@dudasaus
Copy link

Description

Including a default response type for errors (per Swagger recommendation overrides the type for specified status codes.

Example:

spec

paths:
  /templates/{id}:
    get:
      summary: Retrieve a Template
      description: Returns a given Template by ID
      parameters:
        - in: path
          name: id
          description: ID of Template to fetch
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Template response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Template'
        default:
          description: Not found error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

types.gen.ts

export type $OpenApiTs = {
  '/templates/{id}': {
    get: {
      req: {
        /**
         * ID of Template to fetch
         */
        id: string;
      };
      res: {
        /**
         * Not found error
         */
        200: Error;
      };
    };
  };
}

OpenAPI specification (optional)

paths:
  /templates/{id}:
    get:
      summary: Retrieve a Template
      description: Returns a given Template by ID
      parameters:
        - in: path
          name: id
          description: ID of Template to fetch
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Template response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Template'
        default:
          description: Not found error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

Configuration

// https://heyapi.vercel.app/openapi-ts/configuration.html
import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
  client: 'fetch',
  input: 'backend/backend-api.yaml',
  output: 'frontend/src/services/heyapi',
  format: 'prettier',
  services: {
    export: true,
    name: 'Name',
  },
  dryRun: false,
});

System information (optional)

$ npm -v
10.5.0

$ node -v
v18.18.0
@dudasaus dudasaus added the bug 🔥 Something isn't working label Apr 28, 2024
@mrlubos
Copy link
Contributor

mrlubos commented Apr 28, 2024

Hey @dudasaus, this will be fixed in the next release #500

@dudasaus
Copy link
Author

Awesome! 🥳

@jordanshatford
Copy link
Collaborator

@dudasaus please update to 0.43.0 of the package. The fix has just been released.

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

No branches or pull requests

3 participants