Skip to content

Commit

Permalink
polymorphism java tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Jul 13, 2022
1 parent 305249e commit a24b14b
Show file tree
Hide file tree
Showing 9 changed files with 874 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,206 @@ public void testGeneratorServiceTypescriptAngular3() {
Assert.assertFalse(files.isEmpty());
}

/*
* testIssue605 testIssue612_CC27814 testIssue613_CC27916 testIssue613_CC27916
*
* to obtain a runnable server via jetty:run, in generated server code, replace the following files
* with the ones in src/test/resources/3_0_0/issue-605/sertemplate
*
* pom.xml
* web.xml
* RestApplication.java
* InventoryApi.java
*
*
*/
@Test
public void testIssue605() throws IOException {
String path = getTmpFolder().getAbsolutePath() + "/client";
path = new File("/dati/dev/progetti/swagger/issue-206/client").getAbsolutePath();
GenerationRequest request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.CLIENT)
.lang("java")
.spec(loadSpecAsNode("3_0_0/issue-605/swagger.yaml", true, false))
.options(
new Options()
.outputDir(path)
.library("resteasy")
.addAdditionalProperty("dateLibray", "time4j")

);
List<File> files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
System.out.println("Generated client in:\n" + path);
path = getTmpFolder().getAbsolutePath() + "/server";
path = new File("/dati/dev/progetti/swagger/issue-206/server").getAbsolutePath();
request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.SERVER)
.lang("jaxrs-resteasy")
.spec(loadSpecAsNode("3_0_0/issue-605/swagger.yaml", true, false))
.options(
new Options()
.outputDir(path)

);
files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
System.out.println("Generated server in:\n" + path);
}

@Test
public void testIssue612_CC27814() throws IOException {

String path = getTmpFolder().getAbsolutePath() + "/server";
path = new File("/dati/dev/progetti/swagger/CC-27814/server").getAbsolutePath();
GenerationRequest request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.SERVER)
.lang("jaxrs-resteasy")
.spec(loadSpecAsNode("3_0_0/issue-612/cc-27814.yaml", true, false))
.options(
new Options()
.outputDir(path)
);
List<File> files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
System.out.println("Generated server in:\n" + path);

path = getTmpFolder().getAbsolutePath() + "/client";
path = new File("/dati/dev/progetti/swagger/CC-27814/client").getAbsolutePath();
request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.CLIENT)
.lang("java")
.spec(loadSpecAsNode("3_0_0/issue-612/cc-27814.yaml", true, false))
.options(
new Options()
.outputDir(path)
.library("resteasy")
.addAdditionalProperty("dateLibray", "time4j")

);
files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
System.out.println("Generated client in:\n" + path);
}

@Test
public void testIssue613_CC27916() throws IOException {

String path = getTmpFolder().getAbsolutePath() + "/client";
path = new File("/dati/dev/progetti/swagger/CC-27986/client").getAbsolutePath();
GenerationRequest request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.CLIENT)
.lang("java")
.spec(loadSpecAsNode("3_0_0/issue-613/cc-27916.yaml", true, false))
.options(
new Options()
.outputDir(path)
);
List<File> files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
System.out.println("Generated client in:\n" + path);

path = getTmpFolder().getAbsolutePath() + "/server";
path = new File("/dati/dev/progetti/swagger/CC-27986/server").getAbsolutePath();
request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.SERVER)
.lang("jaxrs-resteasy")
.spec(loadSpecAsNode("3_0_0/issue-613/cc-27916.yaml", true, false))
.options(
new Options()
.outputDir(path)

);
files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
System.out.println("Generated server in:\n" + path);
}

@Test
public void testIssue613_605_612() throws IOException {

String path = getTmpFolder().getAbsolutePath() + "/client";
path = new File("/dati/dev/progetti/swagger/polycodegen/client").getAbsolutePath();
GenerationRequest request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.CLIENT)
.lang("java")
.spec(loadSpecAsNode("3_0_0/issue-605-612-613/swagger.yaml", true, false))
.options(
new Options()
.outputDir(path)
);
List<File> files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
System.out.println("Generated client in:\n" + path);

path = getTmpFolder().getAbsolutePath() + "/server";
path = new File("/dati/dev/progetti/swagger/polycodegen/server").getAbsolutePath();
request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.SERVER)
.lang("jaxrs-resteasy")
.spec(loadSpecAsNode("3_0_0/issue-605-612-613/swagger.yaml", true, false))
.options(
new Options()
.outputDir(path)

);
files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
System.out.println("Generated server in:\n" + path);
}

@Test
public void testIssue613_605_612_non_resteasy() throws IOException {

String path = getTmpFolder().getAbsolutePath() + "/clientdefault";
path = new File("/dati/dev/progetti/swagger/polycodegendefault/client").getAbsolutePath();
GenerationRequest request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.CLIENT)
.lang("java")
.spec(loadSpecAsNode("3_0_0/issue-605-612-613/swagger.yaml", true, false))
.options(
new Options()
.outputDir(path)
);
List<File> files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
System.out.println("Generated client in:\n" + path);

path = getTmpFolder().getAbsolutePath() + "/server";
path = new File("/dati/dev/progetti/swagger/polycodegendefault/serverdefault").getAbsolutePath();
request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.SERVER)
.lang("jaxrs-jersey")
.spec(loadSpecAsNode("3_0_0/issue-605-612-613/swagger.yaml", true, false))
.options(
new Options()
.outputDir(path)

);
files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
System.out.println("Generated server in:\n" + path);
}
protected static File getTmpFolder() {
try {
File outputFolder = Files.createTempFile("codegentest-", "-tmp").toFile();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
openapi: 3.0.1
info:
title: OpenAPI definition
version: v0
servers:
- url: http:https://localhost:8080
description: Generated server url
paths:
/list:
get:
tags:
- demo-controller
operationId: epList
responses:
'200':
description: OK
content:
'*/*':
schema:
type: array
items:
oneOf:
- $ref: '#/components/schemas/ClassA'
- $ref: '#/components/schemas/ClassB'
/c:
get:
tags:
- demo-controller
operationId: epC
responses:
'200':
description: OK
content:
'*/*':
schema:
oneOf:
- $ref: '#/components/schemas/ClassA'
- $ref: '#/components/schemas/ClassB'
/d:
get:
tags:
- demo-controller
operationId: epD
requestBody:
description: Inventory item to add
content:
application/json:
schema:
$ref: '#/components/schemas/ClassAorB'
responses:
'200':
description: OK
content:
'*/*':
schema:
oneOf:
- $ref: '#/components/schemas/ClassA'
- $ref: '#/components/schemas/ClassB'
'202':
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/ClassAorB'
/b:
get:
tags:
- demo-controller
operationId: epB
responses:
'200':
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/ClassB'
/a:
get:
tags:
- demo-controller
operationId: epA
responses:
'200':
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/ClassA'
components:
schemas:
ClassA:
required:
- bId
- type
type: object
allOf:
- $ref: '#/components/schemas/InterfaceC'
- type: object
properties:
onlyInA:
type: string
ClassB:
required:
- bId
- type
type: object
allOf:
- $ref: '#/components/schemas/InterfaceC'
InterfaceC:
type: object
properties:
currentTime:
type: string
type:
type: string
discriminator:
propertyName: type
ClassAorB:
discriminator:
propertyName: type
oneOf:
- $ref: '#/components/schemas/ClassA'
- $ref: '#/components/schemas/ClassB'
Loading

0 comments on commit a24b14b

Please sign in to comment.