Skip to content
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 10 commits into from
Oct 11, 2023
10 changes: 9 additions & 1 deletion filters/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ const filter = module.exports;
const _ = require('lodash');

function defineType(prop, propName) {
if (prop.type() === 'object') {
if (prop.additionalProperties()) {
Tenischev marked this conversation as resolved.
Show resolved Hide resolved
if (prop.additionalProperties().type() === 'object') {
return 'Map<String, ' + _.upperFirst(_.camelCase(prop.additionalProperties().uid())) + '>';
} else if (prop.additionalProperties().format()) {
return 'Map<String, ' + toClass(toJavaType(prop.additionalProperties().format())) + '>';
} else if (prop.additionalProperties().type()) {
return 'Map<String, ' + toClass(toJavaType(prop.additionalProperties().type())) + '>';
}
} else if (prop.type() === 'object') {
return _.upperFirst(_.camelCase(prop.uid()));
} else if (prop.type() === 'array') {
if (prop.items().type() === 'object') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import javax.validation.Valid;

import java.util.Objects;
import java.util.List;
import java.util.Map;
import java.util.Objects;

{% if message.description() or message.examples()%}/**{% for line in message.description() | splitByLines %}
* {{ line | safe}}{% endfor %}{% if message.examples() %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.List;
import java.util.Map;
import java.util.Objects;

{% if schema.description() or schema.examples() %}/**{% for line in schema.description() | splitByLines %}
Expand All @@ -17,7 +18,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}};
{%- elif prop.additionalProperties().type() %}
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' %}
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/additional-formats.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.List;
import java.util.Map;
import java.util.Objects;


Expand Down
4 changes: 3 additions & 1 deletion tests/__snapshots__/kafka.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.List;
import java.util.Map;
import java.util.Objects;


Expand Down Expand Up @@ -250,8 +251,9 @@ exports[`template integration tests for generated files using the generator and

import javax.validation.Valid;

import java.util.Objects;
import java.util.List;
import java.util.Map;
import java.util.Objects;


public class LightMeasured {
Expand Down