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 required at higher level for allOf and oneOf #364

Closed abonifacio closed 3 years ago

abonifacio commented 3 years ago

Why

Given the following spec

components:
  schemas:
    User:
      type: object
      properties:
        name:
          type: string
        email:
          type: string
    RegisteredUser:
      type: object
      allOf:
        - $ref: "#/components/schemas/User"
      required:
        - name
        - email

Resulting types are

interface User {
  name?: string;
  email?: string;
}
type RegisteredUser = User;

With this change, resulting types are

type Require<T,R extends keyof T> = T & Required<Pick<T, R>>;
interface User {
  name?: string;
  email?: string;
}
type RegisteredUser = Require<User, "name" | "email">;

This adds a helper type (Require<T,R extends keyof T>) to make it more readable, otherwise the output would be

type RegisteredUser = User & Required<Pick<User,  "name" | "email">>;
netlify[bot] commented 3 years ago

:construction_worker: Deploy request for restful-react accepted.

:hammer: Explore the source changes: 250441370d5284f0784c52e4ee8973e26ba5df69

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