contiamo / restful-react

A consistent, declarative way of interacting with RESTful backends, featuring code-generation from Swagger and OpenAPI specs 🔥
MIT License
1.87k stars 109 forks source link

support enum on type number #368

Closed abonifacio closed 3 years ago

abonifacio commented 3 years ago

Why

Given the following spec

description: A representation of a floor of a bus.
title: Floor
type: object
properties:
  level:
    description: The floor number.
    enum:
      - 1
      - 2
    type: number

I would like the type to be generated as

interface Floor {
  level: 1 | 2;
}

Additional question: I don't use React but this is the best library I found to generate type from OpenAPI specs, is there a plan to split this library into type generation & react related stuff?

netlify[bot] commented 3 years ago

👷 Deploy request for restful-react accepted.

🔨 Explore the source changes: 049ac1aa27611252be47756f1191e307bbccc41f

🔍 Inspect the deploy log: https://app.netlify.com/sites/restful-react/deploys/60f06742aa46980007e48fa9

micha-f commented 3 years ago

@abonifacio We use this library in many places without react (e.g. in many nodejs services). Have you seen the skipReact option in the config? https://github.com/contiamo/restful-react#only-generating-custom-code-no-react-hookscomponents . If you don't specify a custom generator, it will only output types.

abonifacio commented 3 years ago

@micha-f yeah totally! I'm using skipReact and everything works beautifully. I was just thinking that maybe if you split the library

  1. It will be simpler for non React users (less dependencies, less documentation, less intimidating to contribute)
  2. You can give it a more catchy name, currently the name doesn't imply that you can generate types from OpenAPI!
micha-f commented 3 years ago

You are right, the name does not communicate very well that this project can do quite a bit more these days. It started out as a project to make interacting with REST APIs from react more comfortable. Then @fabien0102 got to work and added all of this awesome OpenAPI stuff 🤷 . As it powers almost every service / UI we put into production it should be pretty well-tested and capable by now. @fabien0102 certainly had the ambition to make this the best library to generate types from specs 🙂 .

Not sure we can change the project structure without much effort at this point though. Let's see what @fabien0102 thinks.

In the meantime - this PR looks good 👍 .