Comments (10)
I would also be interested in this fix.
from openapi-typescript.
npm i @manifoldco/swagger-to-ts@next
fails with
npx: installed 73 in 3.025s
Cannot find module 'prettier'
I was able to get it running via cloning and building it myself and using cli.js directly though.
First thing I noticed - it no longer crashes on names like "MyData 'id' Data" in swagger.json and even properly escapes it in generated schema! I never bothered to report this issue and renamed those manually instead - glad to see it working OOTB now. :)
I take it --nowrapper option is gone? Is there a better way to export naked types then making wrapper around generated schema with:
import { definitions } from './schema.d';
export type MyShallowType1 = definitions['MyShallowType1'];
export type MyShallowType2 = definitions['MyShallowType2'];
I'm sure there should be, but I couldn't quite think of one from the top of my head. 🤔
Nested refs work great now! Great job, @DangoDev 👍🏻
from openapi-typescript.
Thanks so much for the well-written issue and test code! I think I know where the problem lies; we had a similar problem with camelCasing. Basically, the code is “two-tiered” in a sense. The higher tier sets up the scanner based on the entry level, and differs a tiny bit in logic from the lower, recursive tier that crawls the tree. I think refs
are just being handled properly in the top tier, but not the lower tier.
I should be able to patch this soon. Sorry for the delay on this.
from openapi-typescript.
Due to some problems with the way this library handles refs, and in preparation for Swagger v3, I’m working on v2 of this library. Could you do me a favor and try the v2 branch (npm i @manifoldco/swagger-to-ts@next
or npx @manifoldco/swagger-to-ts@next …
)?
I believe this should fix the nested refs problem, but the generated types will be slightly different from v1 (better, IMO).
Feedback/thoughts welcome here as well on the new format (even though the PR is closed I’d gladly accept feedback you have): #178
from openapi-typescript.
I take it --nowrapper option is gone?
Yes. Actually yeah your example works. The style was heavily-influenced by https://graphql-code-generator.com/ which I use a lot. I’ve found that for most deeply-nested paths I just assign a type
to it if I need to reuse it, or just write the whole thing out if I only need it once. It’s a little awkward, but only as awkward as your Swagger schema in the first place.
Sorry I should have mentioned I wrote a draft for a migration guide in #178 that explains why and gives an example:
Wrappers
The --wrapper
CLI flag was removed because it was awkward having to manage part of your TypeScript definition in a CLI flag. In v2, the decision was made to have you compose your wrapper in your code:
import { components as Schema1 } from './generated/schema-1.ts';
import { components as Schema2 } from './generated/schema-2.ts';
declare namespace OpenAPI3 {
export Schema1;
export Schema2;
}
from openapi-typescript.
npm i @manifoldco/swagger-to-ts@next fails with
npx: installed 73 in 3.025s
Cannot find module 'prettier'
Ah good catch. That probably just got accidentally moved to devDeps
. I’ll release a new version fixing that in a bit
from openapi-typescript.
Deployed a new version @next
, and I was able to run it locally. Hopefully that fixes the problem!
from openapi-typescript.
I have a problem with @next
version which is currently 2.0.0-alpha.1.
> npx @manifoldco/swagger-to-ts swagger.json --nowrapper -o src/generated/swagger.d.ts
',' expected. (31:25)
Error point to this line
"ExecutorTask": [object >O<bject];
I cannot understand what the problem is, but would like to be helpful.
from openapi-typescript.
@RinatGumarov does it work if you drop the --nowrapper
option?
If not are you able to post the schema you’re using?
from openapi-typescript.
Just released @manifoldco/[email protected]
to npm, which is a library rewrite that adds OpenAPI 3.0 support and fixes issues following $ref
s. Please give it a try! And please open up another issue if this isn’t resolved.
from openapi-typescript.
Related Issues (20)
- Cannot find name 'HeadersInit'. HOT 4
- Headers lost in fetch request when using BUN HOT 1
- Problem after using ver 7 with generated types for mapping of discriminator HOT 5
- CLI option to validate existing file HOT 4
- bug: request body fields with default values are treated as required HOT 4
- Bug: references to nested properties in schemas generate invalid types
- Error saving output on windows with full file paths instead of relative
- Setup section in npm and the docs are not similar HOT 3
- Types are not enforced with typescript `5.5.3` HOT 6
- Generates invalid types when API paths are nested HOT 3
- Inject option dropped in v7 HOT 1
- Document for conditional authentication failed. HOT 1
- transform function changing objects to not-nullable no longer working in v7 HOT 3
- openapi-fetch: example for extending api client methods HOT 2
- Undefined properties on body object are not flagged if required fields are filled in
- Support cookie parameters
- Default values override "required" state in output types HOT 2
- params always required HOT 1
- Consider using codegen instead of generics HOT 5
- Problem using --array-length when minItems equals to maxItems HOT 1
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.