Skip to content

Commit

Permalink
[TypeScript-Fetch] Generate oneOf schemas as type unions (#2617)
Browse files Browse the repository at this point in the history
* Generate oneOf schemas as type unions for typescript-fetch

* Adjust oneOf imports to only include refs of oneOf
  • Loading branch information
fantavlik authored and wing328 committed Apr 10, 2019
1 parent d63f4bc commit 3036d8f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
}
}
}
if (cm.oneOf.size() > 0) {
// For oneOfs only import $refs within the oneOf
TreeSet<String> oneOfRefs = new TreeSet<String>();
for (String im : cm.imports) {
if (cm.oneOf.contains(im)) {
oneOfRefs.add(im);
}
}
cm.imports = oneOfRefs;
}
}

return objs;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{#hasImports}}
import {
{{#imports}}
{{{.}}},
{{/imports}}
} from './';

{{/hasImports}}
/**
* @type {{classname}}{{#description}}
* {{{description}}}{{/description}}
* @export
*/
export type {{classname}} = {{#oneOf}}{{{.}}}{{^-last}} | {{/-last}}{{/oneOf}};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
{{>modelEnum}}
{{/isEnum}}
{{^isEnum}}
{{#oneOf}}
{{#-first}}
{{>modelOneOf}}
{{/-first}}
{{/oneOf}}
{{^oneOf}}
{{>modelGeneric}}
{{/oneOf}}
{{/isEnum}}
{{/model}}
{{/models}}

0 comments on commit 3036d8f

Please sign in to comment.