OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript-rxjs] Nested oneOf in allOf not generated - but can be correctly generated if nested inside oneOf

Open
#15,821 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Generating TS type when the yaml defines a "oneOf" nested inside an "allOf" does not generate the correct type. Generation misses out the oneOf completely.

Strangely, if you nest the whole object inside a "oneOf" the generator will then generate the nested oneOf type correctly. See below for examples.

openapi-generator version

6.6.0 (latest)

OpenAPI declaration file content or url

See failing spec here, oneOf nested inside allOf:
https://gist.github.com/LeoCie/1985bee1f2d69cb56734f25c4486bc86

Produces TS type:

import type {
    CommonBlock,
} from './';

export type OrdinaryDetailBlock = CommonBlock;

though I would expect:

import type {
    CommonBlock, OrdinaryDetailBlockOneOf 
} from './';
export type OrdinaryDetailBlock = CommonBlock & OrdinaryDetailBlockOneOf ;

and

import type {
    BlockA, BlockB
} from './';
export type OrdinaryDetailBlockOneOf = BlockA | BlockB

See spec here where I nest the whole type inside a oneOf:
https://gist.github.com/LeoCie/3bc37916208219cc537d5d2f96fc12e0

Produces correct TS types:

export type OrdinaryDetailBlock = OrdinaryDetailBlockOneOf

export type OrdinaryDetailBlockOneOf = CommonBlock & OrdinaryDetailBlockOneOfAllOf;

export type OrdinaryDetailBlockOneOfAllOf = BlockA | BlockB;
Generation Details

Generating typescript-rxjs types.

Steps to reproduce

Download gist above, run generator with typescript-rxjs.

Suggest a fix

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 with the two linked gist specifications and run the typescript-rxjs generator as described to compare nested oneOf handling under allOf. Trace the generator path that produces OrdinaryDetailBlock and add a regression test; done means the generated types include the expected intersection and union types for both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.