Skip to content

Exposing directly components types #2265

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

Open
1 task done
Aschen opened this issue Apr 27, 2025 · 1 comment
Open
1 task done

Exposing directly components types #2265

Aschen opened this issue Apr 27, 2025 · 1 comment
Labels
enhancement New feature or request openapi-ts Relevant to the openapi-typescript library

Comments

@Aschen
Copy link

Aschen commented Apr 27, 2025

Description

Hello !

First, thanks for your work here people, I really like having strong typing from backend to the frontend and your libraries are perfect for this 👌

At my work, we did a small additionnal wrapper that rewrite part of the types so we can access them directly like "natural" types instead of having to use the nested access through components["schemas"]["MyApiType"]

// Before
import { components } from './openapi-types'

function foobar(person: components["schemas"]["Person"]) {
  // ...
}

// After
import { Person } from './openapi-types'`

function foobar(person: Person) {
  // ...
}

I was thinking about opening a PR here to add an option to generate types from components like this but I wanted your opinion on it first.

Extra

@Aschen Aschen added enhancement New feature or request openapi-ts Relevant to the openapi-typescript library labels Apr 27, 2025
@duncanbeevers
Copy link
Contributor

Thanks for the suggestion @Aschen.
This is a common request, but it's difficult to come up with a scheme that exposes top-level components in a way that satisfies everyone. It's possible (easy even) to have components whose names are not valid JS identifiers, and it's also not uncommon to run into cases where several exported things (such as component schemas and enums) end up colliding in the types namespace.

For 8.x we're looking at providing APIs to serve as extension points for use cases like these, including functions for translating component schema names to JS identifiers; this is on our radar, however it is unlikely that this feature will make it to 7.x or 8.x in the form proposed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

No branches or pull requests

2 participants