Skip to content

Adding oneOf with discriminator property support #741

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

Merged
merged 2 commits into from
Dec 22, 2021
Merged

Adding oneOf with discriminator property support #741

merged 2 commits into from
Dec 22, 2021

Conversation

sjoerdmulder
Copy link

Continuation of #645 but in a cleaned branch...

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 Jun 12, 2021

Codecov Report

Merging #741 (f69bdf0) into master (1508588) will increase coverage by 3.16%.
The diff coverage is 96.29%.

❗ Current head f69bdf0 differs from pull request most recent head d82f3eb. Consider uploading reports for the commit d82f3eb to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #741      +/-   ##
==========================================
+ Coverage   87.49%   90.65%   +3.16%     
==========================================
  Files         109      109              
  Lines        1599     1552      -47     
  Branches      311      304       -7     
==========================================
+ Hits         1399     1407       +8     
+ Misses        200      145      -55     
Impacted Files Coverage Δ
src/utils/discriminator.ts 95.00% <95.00%> (ø)
src/openApi/v3/parser/getModel.ts 100.00% <100.00%> (+0.84%) ⬆️
src/openApi/v3/parser/getModelProperties.ts 100.00% <100.00%> (ø)
src/openApi/v3/parser/getModelComposition.ts 76.19% <0.00%> (-20.69%) ⬇️
src/utils/getOpenApiSpec.ts 81.25% <0.00%> (-18.75%) ⬇️
src/openApi/v3/parser/getContent.ts 58.82% <0.00%> (-10.41%) ⬇️
src/utils/writeClientCore.ts 61.53% <0.00%> (-2.75%) ⬇️
src/index.ts 80.00% <0.00%> (-0.77%) ⬇️
src/openApi/v2/parser/getModel.ts 98.88% <0.00%> (-0.05%) ⬇️
src/utils/writeClient.ts 96.29% <0.00%> (ø)
... and 46 more

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 1508588...d82f3eb. Read the comment docs.

@aperkaz
Copy link

aperkaz commented Oct 28, 2021

@sjoerdmulder @ferdikoomen I am looking forward to this update, is there anything that can be done to get it down to develop?

@sjoerdmulder
Copy link
Author

@ferdikoomen I have updated the branch to be based on latest master

@ferdikoomen ferdikoomen merged commit e694589 into ferdikoomen:master Dec 22, 2021
@sjoerdmulder sjoerdmulder deleted the feature/discriminator branch December 22, 2021 18:23
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.

3 participants