Comments (5)
You can find explanation in docs.
The docs seem to say that what @Meyzz was looking for can no longer be achieved... am I misunderstanding? I would also like to reference interfaces by name.
from openapi-typescript.
@Meyzz if you're just looking for fewer keystrokes, here's what I came up with:
in a .d.ts
file:
import { components } from 'your-module';
declare global {
type Schemas = components['schemas'];
}
Usage: const foo: Schemas['Foo'] = makeFoo();
in a different file without having to import anything.
from openapi-typescript.
You can find explanation in docs.
https://github.com/manifoldco/swagger-to-ts#no-wrappers
from openapi-typescript.
Yes that’s correct—with 2.0 the option to remove wrappers was removed. It made the library overly-complicated to maintain when your schema can be transformed. It’s your schema! The types should match reality.
As referenced in the README, I’d recommend just creating shorthand types where needed to reduce typing.
from openapi-typescript.
It feels quite non-typescript'y to have to write even Schemas['Foo']
. Feels like everything in components['schemas']
should be directly importable/referenceable. If you have to use a nested structure for accessing paths/methods etc. and other more complicated/niche bits, that's fine.
The types should match reality.
The types do match reality. Nesting them does not feel like it matches reality though. If I have a type Foo
shouldn't I be able to just do import { Foo } from './schema.ts';
?
@drwpow
from openapi-typescript.
Related Issues (20)
- Response types from openapi-fetch ignore null values
- Multiple security schemes not supported
- With React Query: Invariant: headers() expects to have requestAsyncStorage, none available. HOT 6
- `--properties-required-by-default` and `--default-non-nullable` flags do not work HOT 3
- Nested object's properties are mapped to unknown, but in OpenAPI they are typed correctly HOT 3
- "AdditionalProperties" reflects onto existing properties and causes TypeScript compile errors HOT 1
- Issues with references (`$ref`) resolution HOT 2
- Error with negative numbers in enums HOT 2
- Allow for custom types in path params serialization (and maybe other places serialization too)
- Types derived for oneOf construct result in TS2502 error HOT 7
- Uncaught error when body is `undefined` in request init HOT 6
- 'path' does not exist in type '{ query?: Record<string, unknown> | undefined; }' HOT 4
- issue on - generate client when yaml has mutiple same external ref
- Generate subset of schema HOT 5
- Deduplicate enums
- `type: object` generating `Record<string, never>` HOT 1
- Throw error on error and data property be defined HOT 3
- [v7] transform + nullable issue with Identifier with Node.js API HOT 1
- Is there a plan to support cookie parameters? HOT 2
- discriminator mapping ignored when using allOf with oneOf HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openapi-typescript.