-
-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for additionalProperties (#272) #273
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7b10c94
feat: Add support for additionalProperties (#272)
JapuDCret 8345428
fix: Map imports (#272)
JapuDCret fba26f7
fix: Allow additionalProperties=false (#272)
JapuDCret 3fa7e8b
test: Extend test case for boolean (#272)
JapuDCret df823ae
test: Extend test case for oneOf (#272)
JapuDCret 04d2fa5
rework: Remove else-branch to check value (#272)
JapuDCret 2eaaa3f
Merge branch 'master' into master
Tenischev 88faa64
Merge remote-tracking branch 'origin/master' into pr/273
Tenischev e1034c3
update from master, fix order of imports and tests
Tenischev bffdcd5
fix case when `additionalProperties = true`
Tenischev File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
|
@@ -17,7 +17,15 @@ | |
public class {{schemaName | camelCase | upperFirst}} { | ||
{% for propName, prop in schema.properties() %} | ||
{%- set isRequired = propName | isRequired(schema.required()) %} | ||
{%- if prop.type() === 'object' %} | ||
{%- if prop.additionalProperties() %} | ||
{%- if prop.additionalProperties().type() === 'object' %} | ||
Tenischev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private @Valid Map<String, {{prop.additionalProperties().uid() | camelCase | upperFirst}}> {{propName | camelCase}}; | ||
{%- elif prop.additionalProperties().format() %} | ||
private @Valid Map<String, {{prop.additionalProperties().format() | toJavaType | toClass}}> {{propName | camelCase}}; | ||
{%- else %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. additionalProperties could be boolean Unable to call |
||
private @Valid Map<String, {{prop.additionalProperties().type() | toJavaType | toClass}}> {{propName | camelCase}}; | ||
{%- endif %} | ||
{%- elif prop.type() === 'object' %} | ||
private @Valid {{prop.uid() | camelCase | upperFirst}} {{propName | camelCase}}; | ||
{%- elif prop.type() === 'array' %} | ||
{%- if prop.items().type() === 'object' %} | ||
|
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,212 @@ | ||
// 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 SongMetaData { | ||
|
||
private @Valid Map<String, String> tags; | ||
|
||
private @Valid Map<String, Long> stats; | ||
|
||
private @Valid Map<String, Interpret> interprets; | ||
|
||
|
||
|
||
|
||
|
||
/** | ||
* Tags | ||
*/ | ||
@JsonProperty(\\"tags\\") | ||
public Map<String, String> getTags() { | ||
return tags; | ||
} | ||
|
||
public void setTags(Map<String, String> tags) { | ||
this.tags = tags; | ||
} | ||
|
||
|
||
/** | ||
* Stats | ||
*/ | ||
@JsonProperty(\\"stats\\") | ||
public Map<String, Long> getStats() { | ||
return stats; | ||
} | ||
|
||
public void setStats(Map<String, Long> stats) { | ||
this.stats = stats; | ||
} | ||
|
||
|
||
/** | ||
* Interprets | ||
*/ | ||
@JsonProperty(\\"interprets\\") | ||
public Map<String, Interpret> getInterprets() { | ||
return interprets; | ||
} | ||
|
||
public void setInterprets(Map<String, Interpret> interprets) { | ||
this.interprets = interprets; | ||
} | ||
|
||
@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.tags, songPayload.tags) && | ||
Objects.equals(this.stats, songPayload.stats) && | ||
Objects.equals(this.interprets, songPayload.interprets); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(tags, stats, interprets); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return \\"class SongPayload {\\\\n\\" + | ||
|
||
\\" tags: \\" + toIndentedString(tags) + \\"\\\\n\\" + | ||
\\" stats: \\" + toIndentedString(stats) + \\"\\\\n\\" + | ||
\\" interprets: \\" + toIndentedString(interprets) + \\"\\\\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 \\"); | ||
} | ||
}" | ||
`; | ||
|
||
exports[`template integration tests for map format should generate DTO file with proper map types 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 SongMetaData { | ||
|
||
private @Valid Map<String, String> tags; | ||
|
||
private @Valid Map<String, Long> stats; | ||
|
||
private @Valid Map<String, Interpret> interprets; | ||
|
||
|
||
|
||
|
||
/** | ||
* Tags | ||
*/ | ||
@JsonProperty(\\"tags\\") | ||
public Object getTags() { | ||
return tags; | ||
} | ||
|
||
public void setTags(Object tags) { | ||
this.tags = tags; | ||
} | ||
|
||
|
||
/** | ||
* Stats | ||
*/ | ||
@JsonProperty(\\"stats\\") | ||
public Object getStats() { | ||
return stats; | ||
} | ||
|
||
public void setStats(Object stats) { | ||
this.stats = stats; | ||
} | ||
|
||
|
||
/** | ||
* Interprets | ||
*/ | ||
@JsonProperty(\\"interprets\\") | ||
public Map<String, Interpret> getInterprets() { | ||
return interprets; | ||
} | ||
|
||
public void setInterprets(Map<String, Interpret> interprets) { | ||
this.interprets = interprets; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
SongMetaData songMetaData = (SongMetaData) o; | ||
return | ||
Objects.equals(this.tags, songMetaData.tags) && | ||
Objects.equals(this.stats, songMetaData.stats) && | ||
Objects.equals(this.interprets, songMetaData.interprets); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(tags, stats, interprets); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return \\"class SongMetaData {\\\\n\\" + | ||
|
||
\\" tags: \\" + toIndentedString(tags) + \\"\\\\n\\" + | ||
\\" stats: \\" + toIndentedString(stats) + \\"\\\\n\\" + | ||
\\" interprets: \\" + toIndentedString(interprets) + \\"\\\\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 map format', () => { | ||
|
||
jest.setTimeout(30000); | ||
|
||
it('should generate DTO file with proper map types', async() => { | ||
const outputDir = generateFolderName(); | ||
const params = {}; | ||
const mapFormatExamplePath = './mocks/map-format.yml'; | ||
|
||
const generator = new Generator(path.normalize('./'), outputDir, { forceWrite: true, templateParams: params }); | ||
await generator.generateFromFile(path.resolve('tests', mapFormatExamplePath)); | ||
|
||
const expectedFiles = [ | ||
'/src/main/java/com/asyncapi/model/SongMetaData.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,45 @@ | ||
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.metadata: | ||
publish: | ||
message: | ||
$ref: '#/components/messages/metadata' | ||
Tenischev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
subscribe: | ||
message: | ||
$ref: '#/components/messages/metadata' | ||
components: | ||
messages: | ||
metadata: | ||
payload: | ||
$id: SongMetaData | ||
type: object | ||
properties: | ||
tags: | ||
description: Tags | ||
additionalProperties: | ||
type: string | ||
stats: | ||
description: Stats | ||
additionalProperties: | ||
type: integer | ||
format: int64 | ||
interprets: | ||
description: Interprets | ||
additionalProperties: | ||
$ref: '#/components/schemas/Interpret' | ||
schemas: | ||
Interpret: | ||
type: object | ||
properties: | ||
name: | ||
description: Interpret name | ||
type: string |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
additionalProperties could be boolean
true
|false
. This else will lead to strange consequence