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

[typescript-angular] "type": "number" references BigDecimal, which is never generated #336

Closed
wtho opened this issue Mar 25, 2019 · 8 comments

Comments

@wtho
Copy link

wtho commented Mar 25, 2019

Issue

When generating (v3.0.5) using

java -jar \
  -DsupportsES6=true \
  swagger-codegen.jar generate \
  -l typescript-angular \
  -i schema.json \
  -o src/app/generated/

and the schema (swagger: 2.0) contains a field

{
  "someField": {
    "type": "number"
  }
}

it generates this model:

import { BigDecimal } from './bigDecimal';

export interface AbonnementTypVO { 
  someField: BigDecimal;
}

The problem is, that the file bigDecimal.ts is never created.

If the schema contains

{
  "someOtherField": {
    "type" : "integer",
    "format" : "int64"
  }
}

it renders someOtherField: number;

@wtho
Copy link
Author

wtho commented Mar 25, 2019

The current workaround from my side was to create bigDecimal.ts with

export type BigDecimal = number;

which is quite annoying to do every time.

@wtho
Copy link
Author

wtho commented Mar 26, 2019

So in JS/TS there are no native solutions for arbitrary-precision decimal arithmetic, but there are e. g. these libraries to achieve it:

(At least for big.js) There are also corresponding typings in DefinitelyTyped/types.

If you don't like to include any of them or implement BigDecimal in JS/TS on swagger's side, it does not make much sense to use some sort of BigDecimal in JS/TS. In that case number should work just fine.

Are there swagger guidelines on type projections to other languages?

If there is a consent how to handle this and someone points me on the right code locations I'm happy to create a PR. With the current setup and the missing BigDecimal this generator is not usable.

@HugoMario
Copy link
Contributor

hi @wtho, this issue has been fixed, for latest releases, mapping BigDecimal to number. going to close issue, but please let me know if you still get the issue.

@itbrandonsilva
Copy link

itbrandonsilva commented Jan 24, 2020

I've run into this issue myself. A generated model attempts to import BigDecimal in a way similar to @wtho initial example does, but the file is missing. In my case, I'm using the generic javascript generator, not typescript-angular, so let me know if it's preferred for me to create a new issue.

Using the latest build available to me at the moment:
https://oss.sonatype.org/content/repositories/snapshots/io/swagger/codegen/v3/swagger-codegen-cli/3.0.17-SNAPSHOT/swagger-codegen-cli-3.0.17-20200123.095202-4-javadoc.jar.

Edit: I'm fairly new to these tools, and I've realized that this isn't as issue for the swagger-codegen repo, so my report may be misplaced. I can see here that the type mappings defined in this lib don't correlate with my experience.

@AmazingTurtle
Copy link

AmazingTurtle commented Mar 14, 2020

@HugoMario is there any difference between swagger-codegen-cli and swagger-codegen-cli-v3? I tried latest, 3.0.18 and unstable on swagger-codegen-cli-v3 and BigDecimal is still poppin' up. Also I am using the javascript generator.

More specifically when I'm using swagger-codegen-cli:latest instead, I get this one
missing swagger input or config!
edit: I get the above error because swagger-codegen-cli uses v2 by default and that doesn't support OpenAPI v3 (which I am using)

@HugoMario
Copy link
Contributor

@itbrandonsilva @AmazingTurtle
going to check this issue, thanks for letting me know

@HugoMario
Copy link
Contributor

hey @itbrandonsilva @AmazingTurtle

Can you please try with 3.0.20 version

@AmazingTurtle
Copy link

@HugoMario I can confirm, BigDecimal is gone by now with the 3.0.20 version. Thanks for the fix

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

4 participants