GithubHelp home page GithubHelp logo

types-generator's People

Contributors

antoniomastellone avatar dependabot[bot] avatar gabrimcnab avatar zi avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

manhp-codeleap

types-generator's Issues

Some required patches don't get applied

I'm using this library against https://api.musement.com/swagger_3.4.0.json and heavily relying on --patchSource option to patch the original swagger definition and manually set the required props.

I found out that a few entities don't receive the required attributes specified in the patch file:

Patch file

"CartItemMusementGiftbox": {
  "required": ["type", "product"]
},

Output

export type CartItemMusementGiftbox = CartItem & {
  type?: "musement-giftbox",
  product?: Giftbox
} & {};

It seems to happen with types declared as union of other types.
I noticed that the declaration shows and extra & {} appended at the and of it. Could it be that the patch gets applied to this empty object type?

Error on enum string contain single quote

eg: if enum contain single quote in it's body => when pass to prettier => it should be error

From openApi:
eg: enum : [
"this is normal",
"but this's why cause error" # => this will cause error on parser
]

Support Swagger's "additionalProperties" keyword for object with dynamic keys

In an OpenAPI document, when an object has some dynamic keys, it's declared like so:

someObject:
  type: object
  additionalProperties:
    type: string

Currently, the additionalProperties keyword is ignored, and the Typescript type is generated in this way:

someObject: {}

If you are using typescript-eslint > v5.0.0, this will raise an error, because the empty object literal syntax is banned, as it is considered unsafe. Instead we should use:

someObject: Record<string, string>

In addition to the example shown above, there are other use cases for additionalProperties:

someObject:
  type: object
  additionalProperties: true

If the dictionary values can be of any type (aka free-form object) --> Record<string, unknown>

someObject:
  type: object
  additionalProperties:
    $ref: '#/components/schemas/Message'

Instead of using an inline schema, additionalProperties can $ref another schema

someObject:
  type: object
  properties:
    default:
      type: string
  required:
    - default
  additionalProperties:
    type: string

When a dictionary has some fixed properties, and some dynamic ones.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.