forked from loafle/openapi-generator-original
[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:
parent
d63f4bc16a
commit
3036d8fd20
@ -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;
|
return objs;
|
||||||
|
14
modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache
vendored
Normal file
14
modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{{#hasImports}}
|
||||||
|
import {
|
||||||
|
{{#imports}}
|
||||||
|
{{{.}}},
|
||||||
|
{{/imports}}
|
||||||
|
} from './';
|
||||||
|
|
||||||
|
{{/hasImports}}
|
||||||
|
/**
|
||||||
|
* @type {{classname}}{{#description}}
|
||||||
|
* {{{description}}}{{/description}}
|
||||||
|
* @export
|
||||||
|
*/
|
||||||
|
export type {{classname}} = {{#oneOf}}{{{.}}}{{^-last}} | {{/-last}}{{/oneOf}};
|
@ -6,7 +6,14 @@
|
|||||||
{{>modelEnum}}
|
{{>modelEnum}}
|
||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
{{^isEnum}}
|
{{^isEnum}}
|
||||||
|
{{#oneOf}}
|
||||||
|
{{#-first}}
|
||||||
|
{{>modelOneOf}}
|
||||||
|
{{/-first}}
|
||||||
|
{{/oneOf}}
|
||||||
|
{{^oneOf}}
|
||||||
{{>modelGeneric}}
|
{{>modelGeneric}}
|
||||||
|
{{/oneOf}}
|
||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
{{/model}}
|
{{/model}}
|
||||||
{{/models}}
|
{{/models}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user