openapi types #2231
openapi types
#2231
-
What would you like to discuss?hey so I wanted to see if anyone using got has figured out a solution to have the response be typed from an openapi doc? Checklist
|
Beta Was this translation helpful? Give feedback.
Answered by
sindresorhus
Oct 11, 2025
Replies: 1 comment
-
|
Got doesn't have built-in OpenAPI type generation, but you can combine it with tools like import got from 'got';
import type { paths } from './generated/api'; // Generated from your OpenAPI spec
type GetUserResponse = paths['/users/{id}']['get']['responses']['200']['content']['application/json'];
const user = await got('https://api.example.com/users/123').json<GetUserResponse>();
// Now `user` is fully typed based on your OpenAPI spec
console.log(user.name); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sindresorhus
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got doesn't have built-in OpenAPI type generation, but you can combine it with tools like
openapi-typescriptto get typed responses: