mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-06 10:35:25 +00:00
[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;
|
||||
|
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}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{#oneOf}}
|
||||
{{#-first}}
|
||||
{{>modelOneOf}}
|
||||
{{/-first}}
|
||||
{{/oneOf}}
|
||||
{{^oneOf}}
|
||||
{{>modelGeneric}}
|
||||
{{/oneOf}}
|
||||
{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
Loading…
Reference in New Issue
Block a user