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

Missing array types #196

Closed
jeffpyke opened this issue Apr 19, 2020 · 7 comments
Closed

Missing array types #196

jeffpyke opened this issue Apr 19, 2020 · 7 comments

Comments

@jeffpyke
Copy link

Some types are missing in Typescript output.
Example swagger 2.0 input:

definitions:
  MyObject:
    properties:
      foo:
        $ref: "#/definitions/FloatArray
  FloatArray:
    type: "array"
    items:
      type: "number"
      format: "float"

Output:

export interface MyObject {
  foo?: FloatArray;
}

The FloatArray definition is missing.

@drwpow
Copy link
Owner

drwpow commented Apr 21, 2020

@jeffpyke thanks for filing an issue! Yes that’s something being worked on for a 2.0 release of this library, which will be in beta soon.

You can preview an alpha build now with npx @manifoldco/swagger-to-ts@next ….

The short version is that 1.0 tried to be “too smart” and abstract too much, but it results in errors like you’re seeing. 2.0 is a rewrite that is “dumber” in the sense that it perfectly mirrors your schema (and the library itself is also easier to maintain). You can follow progress on the roadmap.

Hopefully it’ll be released soon! Also, if you find that the @next build doesn’t solve your problem, I’d love to get early feedback to make sure it does for the release (replying to this ticket is fine)

@jeffpyke
Copy link
Author

jeffpyke commented Apr 21, 2020

Thanks @DangoDev , I tried that and saw this error.

',' expected. (57:35)
"MyObject2": [object Object];

Please let me know if this is a known issue. If not I can provide a more detailed bug repro.

@drwpow
Copy link
Owner

drwpow commented Apr 22, 2020

Hm. I’m actually surprised you’re seeing that on the @next branch. Would you mind posting the full schema you’re using (or at least the part that errs)? Your example looks pretty similar to the test here which is passing currently: https://github.com/manifoldco/swagger-to-ts/blob/master/tests/v2/index.test.ts#L179

@jeffpyke
Copy link
Author

jeffpyke commented Apr 22, 2020

It's working now (I see next was updated, nice!) Thanks!

@jeffpyke
Copy link
Author

jeffpyke commented Apr 22, 2020

By the way, is there a way to remove the "definitions" namespace?

e.g.

definitions:
  MyObject:
    properties:
      foo:
        $ref: "#/definitions/FloatArray
  FloatArray:
    type: "array"
    items:
      type: "number"
      format: "float"

becomes

export interface definitions {
  MyObject: ...
}

preferred:

export interface MyObject: ...

@drwpow
Copy link
Owner

drwpow commented Apr 22, 2020

By the way, is there a way to remove the "definitions" namespace?

Good question! You can actually change the name with type aliasing. E.g.

import { definitions } from './my-schema';

export type MyObject = definitions;

Or

import { definitions as MyObject } from './my-schema';

Or you can even combine schemas if you have to manage multiple:

import { definitions as schema1 } from './schema1';
import { definitions as schema2 } from './schema2';

export interface MyObject {
  schema1: schema1;
  schema2: schema2;
}

@drwpow
Copy link
Owner

drwpow commented May 5, 2020

@manifoldco/swagger-to-ts@2.0.0 was released! 🎉 This is a library rewrite that fixes these issues and adds OpenAPI 3.0 support. With the tests added I believe this resolves the issue. If that’s not the case, please re-open, or file another issue. Thanks!

(I know this is a repeat message and you’ve already been pinged for this; I’m just repeating for archival purposes, for people that search closed issues)

@drwpow drwpow closed this as completed May 5, 2020
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