[TypeScript-Fetch] Generate oneOf schemas as type unions (#2617)

* Generate oneOf schemas as type unions for typescript-fetch

* Adjust oneOf imports to only include refs of oneOf
This commit is contained in:
Tim 2019-04-10 09:58:07 -07:00 committed by William Cheng
parent d63f4bc16a
commit 3036d8fd20
3 changed files with 31 additions and 0 deletions

View File

@ -165,6 +165,16 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
}
}
}
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;

View File

@ -0,0 +1,14 @@
{{#hasImports}}
import {
{{#imports}}
{{{.}}},
{{/imports}}
} from './';
{{/hasImports}}
/**
* @type {{classname}}{{#description}}
* {{{description}}}{{/description}}
* @export
*/
export type {{classname}} = {{#oneOf}}{{{.}}}{{^-last}} | {{/-last}}{{/oneOf}};

View File

@ -6,7 +6,14 @@
{{>modelEnum}}
{{/isEnum}}
{{^isEnum}}
{{#oneOf}}
{{#-first}}
{{>modelOneOf}}
{{/-first}}
{{/oneOf}}
{{^oneOf}}
{{>modelGeneric}}
{{/oneOf}}
{{/isEnum}}
{{/model}}
{{/models}}