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

[client-fetch] Create const runtime object from enum strings #1683

Open
blouflashdb opened this issue Feb 7, 2025 · 1 comment
Open

[client-fetch] Create const runtime object from enum strings #1683

blouflashdb opened this issue Feb 7, 2025 · 1 comment

Comments

@blouflashdb
Copy link

blouflashdb commented Feb 7, 2025

From:

      "ResourceType": {
        "enum": [
          "Car",
          "Bike",
          "Truck"
        ],
        "type": "string"
      },

I would expect something like this:

export const ResourceType = {
    Car: 'Car',
    Bike: 'Bike',
    Truck: 'Truck'
} as const;
export type ResourceType = typeof ResourceType[keyof typeof ResourceType];

instead of:

export type ResourceType = "Car" | "Bike" | "Truck";

My config:

import { defineConfig } from "@hey-api/openapi-ts";

export default defineConfig({
  input: "./swagger.json",
  output: {
    lint: "eslint",
    path: "src/clients"
  },
  plugins: ["@hey-api/client-fetch"]
});
@mrlubos
Copy link
Member

mrlubos commented Feb 7, 2025

Thanks for the suggestion @blouflashdb! I assume the issue is if you pass a string somewhere the compiler will show errors despite passing the correct value?

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

2 participants