mnahkies / mnahkies/openapi-code-generator

Investigate being more lenient in handling allOf

Open
#311 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
34
Forks
8
Avg merge
20h 27m
Merged PRs (30d)
7

Description

Currently we take a pretty strict interpretation of allOf which means that constructs like the below don't work as a user might expect:

components:
  schemas:
    PartialObject:
      type: object
      properties:
        foo:
          type: string
        bar:
          type: number
    RequiredObject:
      allOf:
        - $ref: '#/components/schemas/PartialObject'
        - required:
          - foo
          - bar

Currently this ends up as {foo?: string, bar?: number} & {[key: string]: never} which isn't very useful, though fairly faithful to the specification ({foo?: string, bar?: number} & {foo: unknown, bar: unknown} might arguably be more accurate)

Other tooling such as swagger editor instead merges/flattens the schemas together, eg:

Image

We should investigate whether its possible to relax the rules a bit here, without compromising the ability to create types like Dog & Cat

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the PartialObject/RequiredObject example in the TypeScript generator and trace how allOf is currently represented. Compare the current intersection output with the flattened behavior described, while checking that Dog & Cat remains distinct; done means the feasibility and compatibility trade-offs are established.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
backend-api-design, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.