Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support of additional data type formats (#210)
- Loading branch information
Showing
4 changed files
with
203 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`template integration tests for additional formats of data types should generate DTO file with proper type classes 1`] = ` | ||
"package com.asyncapi.model; | ||
import javax.validation.constraints.*; | ||
import javax.validation.Valid; | ||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import java.util.List; | ||
import java.util.Objects; | ||
public class SongPayload { | ||
private @Valid java.util.UUID id; | ||
private @Valid String title; | ||
private @Valid String uri; | ||
private @Valid String email; | ||
/** | ||
* ID | ||
*/ | ||
@JsonProperty(\\"id\\") | ||
public java.util.UUID getId() { | ||
return id; | ||
} | ||
public void setId(java.util.UUID id) { | ||
this.id = id; | ||
} | ||
/** | ||
* Title of a song | ||
*/ | ||
@JsonProperty(\\"title\\") | ||
public String getTitle() { | ||
return title; | ||
} | ||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
/** | ||
* URI of a song | ||
*/ | ||
@JsonProperty(\\"uri\\") | ||
public String getUri() { | ||
return uri; | ||
} | ||
public void setUri(String uri) { | ||
this.uri = uri; | ||
} | ||
/** | ||
* Author email | ||
*/ | ||
@JsonProperty(\\"email\\") | ||
public String getEmail() { | ||
return email; | ||
} | ||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
SongPayload songPayload = (SongPayload) o; | ||
return | ||
Objects.equals(this.id, songPayload.id) && | ||
Objects.equals(this.title, songPayload.title) && | ||
Objects.equals(this.uri, songPayload.uri) && | ||
Objects.equals(this.email, songPayload.email); | ||
} | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, title, uri, email); | ||
} | ||
@Override | ||
public String toString() { | ||
return \\"class SongPayload {\\\\n\\" + | ||
\\" id: \\" + toIndentedString(id) + \\"\\\\n\\" + | ||
\\" title: \\" + toIndentedString(title) + \\"\\\\n\\" + | ||
\\" uri: \\" + toIndentedString(uri) + \\"\\\\n\\" + | ||
\\" email: \\" + toIndentedString(email) + \\"\\\\n\\" + | ||
\\"}\\"; | ||
} | ||
/** | ||
* Convert the given object to string with each line indented by 4 spaces (except the first line). | ||
*/ | ||
private String toIndentedString(Object o) { | ||
if (o == null) { | ||
return \\"null\\"; | ||
} | ||
return o.toString().replace(\\"\\\\n\\", \\"\\\\n \\"); | ||
} | ||
}" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const path = require('path'); | ||
const Generator = require('@asyncapi/generator'); | ||
const { readFile } = require('fs').promises; | ||
|
||
const MAIN_TEST_RESULT_PATH = path.join('tests', 'temp', 'integrationTestResult'); | ||
|
||
const generateFolderName = () => { | ||
// you always want to generate to new directory to make sure test runs in clear environment | ||
return path.resolve(MAIN_TEST_RESULT_PATH, Date.now().toString()); | ||
}; | ||
|
||
describe('template integration tests for additional formats of data types', () => { | ||
|
||
jest.setTimeout(30000); | ||
|
||
it('should generate DTO file with proper type classes', async() => { | ||
const outputDir = generateFolderName(); | ||
const params = {}; | ||
const kafkaExamplePath = './mocks/additional-type-formats.yml'; | ||
|
||
const generator = new Generator(path.normalize('./'), outputDir, { forceWrite: true, templateParams: params }); | ||
await generator.generateFromFile(path.resolve('tests', kafkaExamplePath)); | ||
|
||
const expectedFiles = [ | ||
'/src/main/java/com/asyncapi/model/SongPayload.java' | ||
]; | ||
for (const index in expectedFiles) { | ||
const file = await readFile(path.join(outputDir, expectedFiles[index]), 'utf8'); | ||
expect(file).toMatchSnapshot(); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
asyncapi: 2.0.0 | ||
info: | ||
title: Record Label Service | ||
version: 1.0.0 | ||
description: This service is in charge of processing music | ||
servers: | ||
production: | ||
url: 'my-kafka-hostname:9092' | ||
protocol: kafka | ||
description: Production Instance 1 | ||
channels: | ||
song.released: | ||
publish: | ||
message: | ||
$ref: '#/components/messages/song' | ||
subscribe: | ||
message: | ||
$ref: '#/components/messages/song' | ||
components: | ||
messages: | ||
song: | ||
payload: | ||
$id: SongPayload | ||
type: object | ||
properties: | ||
id: | ||
description: ID | ||
type: string | ||
format: uuid | ||
title: | ||
description: Title of a song | ||
type: string | ||
uri: | ||
description: URI of a song | ||
type: string | ||
format: uri | ||
email: | ||
description: Author email | ||
type: string | ||
format: email |