Skip to content

Adding oneOf with discriminator property support #645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 0 commits into from
Closed

Adding oneOf with discriminator property support #645

wants to merge 0 commits into from

Conversation

sjoerdmulder
Copy link

First of all awesome project!

Currently it seems there is no support for discriminators from the V3 spec in the generator.

This PR adds some preliminary support so that instead of:

export type ModelCircle = {
    kind: string;
    radius?: number;
}
export type ModelSquare = {
    kind: string;
    sideLength?: number;
}
export type Shape = Circle | Square;

It generates (not the the kind: string is replaced)

export type ModelCircle = {
    kind: 'circle';
    radius?: number;
}
export type ModelSquare = {
    kind: 'square';
    sideLength?: number;
}
export type Shape = Circle | Square;

Added some tests as well, let me know what you think!

@codecov
Copy link

codecov bot commented Apr 8, 2021

Codecov Report

Merging #645 (517408d) into master (19c171b) will increase coverage by 0.08%.
The diff coverage is 96.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #645      +/-   ##
==========================================
+ Coverage   90.57%   90.65%   +0.08%     
==========================================
  Files         108      109       +1     
  Lines        1528     1552      +24     
  Branches      298      304       +6     
==========================================
+ Hits         1384     1407      +23     
- Misses        144      145       +1     
Impacted Files Coverage Δ
src/utils/discriminator.ts 95.00% <95.00%> (ø)
src/openApi/v3/parser/getModel.ts 100.00% <100.00%> (ø)
src/openApi/v3/parser/getModelProperties.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 19c171b...517408d. Read the comment docs.

@ferdikoomen
Copy link
Owner

@sjoerdmulder Sorry for the late reply, I was away due to a covid infection. Thanks for the PR, looks good! I will do some quick tests and if it looks good, then will merge it today

@sjoerdmulder
Copy link
Author

sjoerdmulder commented Apr 27, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants