Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ import { {{classname}} } from '{{filename}}';
* {{{.}}}
*/
{{/description}}
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{#isAlias}}{{>modelAlias}}{{/isAlias}}{{^isAlias}}{{#taggedUnions}}{{>modelTaggedUnion}}{{/taggedUnions}}{{^taggedUnions}}{{#oneOf}}{{#-first}}{{>modelOneOf}}{{/-first}}{{/oneOf}}{{^oneOf}}{{>modelGeneric}}{{/oneOf}}{{/taggedUnions}}{{/isAlias}}{{/isEnum}}
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{#isAlias}}{{>modelAlias}}{{/isAlias}}{{^isAlias}}{{#taggedUnions}}{{>modelTaggedUnion}}{{/taggedUnions}}{{^taggedUnions}}{{#oneOf}}{{#-first}}{{>modelOneOf}}{{/-first}}{{/oneOf}}{{^oneOf}}{{#hasVars}}{{>modelGeneric}}{{/hasVars}}{{^hasVars}}{{#anyOf}}{{#-first}}{{>modelAnyOf}}{{/-first}}{{/anyOf}}{{^anyOf}}{{>modelGeneric}}{{/anyOf}}{{/hasVars}}{{/oneOf}}{{/taggedUnions}}{{/isAlias}}{{/isEnum}}
{{/model}}
{{/models}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {{classname}}{{#description}}
* {{{.}}}{{/description}}
* @export
*/
export type {{classname}} = {{#anyOf}}{{{.}}}{{^-last}} | {{/-last}}{{/anyOf}};
Original file line number Diff line number Diff line change
Expand Up @@ -724,4 +724,30 @@ public void testHttpResourceSkipsAnOperationWhoseNameIsTaken() throws IOExceptio
TestUtils.assertFileContains(service, "public getPetResourceResource(options?: ApiHttpResourceOptions<string>)");
TestUtils.assertFileNotContains(service, "public getPetResource(options?: ApiHttpResourceOptions<string>)");
}

@Test
public void testAnyOfOfPrimitivesGeneratesUnionType() throws IOException {
Path spec = Files.createTempFile("anyof-primitives", ".yaml");
spec.toFile().deleteOnExit();
Files.writeString(spec, String.join("\n",
"openapi: 3.0.0",
"info: {title: anyof, version: 1.0.0}",
"paths: {}",
"components:",
" schemas:",
" Foo:",
" type: object",
" properties:",
" bar: {anyOf: [{type: number}, {type: string}]}",
" pet: {anyOf: [{$ref: '#/components/schemas/Cat'}, {$ref: '#/components/schemas/Dog'}]}",
" Cat: {type: object, properties: {meow: {type: boolean}}}",
" Dog: {type: object, properties: {bark: {type: boolean}}}",
""));

File output = generateAngular(spec.toString(), new HashMap<>());

TestUtils.assertFileContains(Paths.get(output + "/model/fooBar.ts"), "export type FooBar = number | string;");
// anyOf of objects keeps merged interface
TestUtils.assertFileContains(Paths.get(output + "/model/fooPet.ts"), "export interface FooPet {");
}
}
Loading