Skip to content
Merged
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
1 change: 1 addition & 0 deletions .generator/src/generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def cli(specs, output):
env.filters["docstring"] = formatter.docstring
env.filters["inline_docstring"] = formatter.inline_docstring
env.filters["un_parameterize_type"] = formatter.un_parameterize_type
env.filters["is_parameterized_type"] = formatter.is_parameterized_type

env.globals["enumerate"] = enumerate
env.globals["get_name"] = openapi.get_name
Expand Down
5 changes: 5 additions & 0 deletions .generator/src/generator/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ def un_parameterize_type(type):
return UN_PARAMETERIZE.sub("", type)


def is_parameterized_type(type):
"""Check if a type has generic parameters (e.g., List<String>)."""
return '<' in type and '>' in type


def format_value(value, quotes='"', schema=None, default_value=False, type_=None):
if schema:
if "enum" in schema and default_value:
Expand Down
14 changes: 10 additions & 4 deletions .generator/src/generator/templates/modelOneOf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ public class {{ name }} extends AbstractOpenApiSchema {
int match = 0;
JsonToken token = tree.traverse(jp.getCodec()).nextToken();
{%- for oneOf in model.oneOf %}
{%- set unParameterizedDataType = get_type(oneOf)|un_parameterize_type %}
// deserialize {{ unParameterizedDataType }}
{%- set parameterizedDataType = get_type(oneOf) %}
{%- set unParameterizedDataType = parameterizedDataType|un_parameterize_type %}
{%- set isParameterized = parameterizedDataType|is_parameterized_type %}
// deserialize {{ parameterizedDataType }}
try {
boolean attemptParsing = true;
// ensure that we respect type coercion as set on the client ObjectMapper
Expand All @@ -88,7 +90,11 @@ public class {{ name }} extends AbstractOpenApiSchema {
}
}
if (attemptParsing) {
{%- if isParameterized %}
tmp = tree.traverse(jp.getCodec()).readValueAs(new TypeReference<{{ parameterizedDataType }}>() {});
{%- else %}
tmp = tree.traverse(jp.getCodec()).readValueAs({{ unParameterizedDataType }}.class);
{%- endif %}
// TODO: there is no validation against JSON schema constraints
// (min, max, enum, pattern...), this does not perform a strict JSON
// validation, which means the 'match' count may be higher than it should be.
Expand All @@ -101,11 +107,11 @@ public class {{ name }} extends AbstractOpenApiSchema {
deserialized = tmp;
match++;
{% endif %}
log.log(Level.FINER, "Input data matches schema '{{ unParameterizedDataType }}'");
log.log(Level.FINER, "Input data matches schema '{{ parameterizedDataType }}'");
}
} catch (Exception e) {
// deserialization failed, continue
log.log(Level.FINER, "Input data does not match schema '{{ unParameterizedDataType }}'", e);
log.log(Level.FINER, "Input data does not match schema '{{ parameterizedDataType }}'", e);
}
{# #}
{%- endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public DistributionPointItem deserialize(JsonParser jp, DeserializationContext c
log.log(Level.FINER, "Input data does not match schema 'Double'", e);
}

// deserialize List
// deserialize List<Double>
try {
boolean attemptParsing = true;
// ensure that we respect type coercion as set on the client ObjectMapper
Expand All @@ -147,18 +147,18 @@ public DistributionPointItem deserialize(JsonParser jp, DeserializationContext c
}
}
if (attemptParsing) {
tmp = tree.traverse(jp.getCodec()).readValueAs(List.class);
tmp = tree.traverse(jp.getCodec()).readValueAs(new TypeReference<List<Double>>() {});
// TODO: there is no validation against JSON schema constraints
// (min, max, enum, pattern...), this does not perform a strict JSON
// validation, which means the 'match' count may be higher than it should be.
deserialized = tmp;
match++;

log.log(Level.FINER, "Input data matches schema 'List'");
log.log(Level.FINER, "Input data matches schema 'List<Double>'");
}
} catch (Exception e) {
// deserialization failed, continue
log.log(Level.FINER, "Input data does not match schema 'List'", e);
log.log(Level.FINER, "Input data does not match schema 'List<Double>'", e);
}

DistributionPointItem ret = new DistributionPointItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public SharedDashboardInvitesData deserialize(JsonParser jp, DeserializationCont
Level.FINER, "Input data does not match schema 'SharedDashboardInvitesDataObject'", e);
}

// deserialize List
// deserialize List<SharedDashboardInvitesDataObject>
try {
boolean attemptParsing = true;
// ensure that we respect type coercion as set on the client ObjectMapper
Expand All @@ -153,18 +153,24 @@ public SharedDashboardInvitesData deserialize(JsonParser jp, DeserializationCont
}
}
if (attemptParsing) {
tmp = tree.traverse(jp.getCodec()).readValueAs(List.class);
tmp =
tree.traverse(jp.getCodec())
.readValueAs(new TypeReference<List<SharedDashboardInvitesDataObject>>() {});
// TODO: there is no validation against JSON schema constraints
// (min, max, enum, pattern...), this does not perform a strict JSON
// validation, which means the 'match' count may be higher than it should be.
deserialized = tmp;
match++;

log.log(Level.FINER, "Input data matches schema 'List'");
log.log(
Level.FINER, "Input data matches schema 'List<SharedDashboardInvitesDataObject>'");
}
} catch (Exception e) {
// deserialization failed, continue
log.log(Level.FINER, "Input data does not match schema 'List'", e);
log.log(
Level.FINER,
"Input data does not match schema 'List<SharedDashboardInvitesDataObject>'",
e);
}

SharedDashboardInvitesData ret = new SharedDashboardInvitesData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public ActionQuerySpecInputs deserialize(JsonParser jp, DeserializationContext c
log.log(Level.FINER, "Input data does not match schema 'String'", e);
}

// deserialize Map
// deserialize Map<String, Object>
try {
boolean attemptParsing = true;
// ensure that we respect type coercion as set on the client ObjectMapper
Expand All @@ -146,18 +146,19 @@ public ActionQuerySpecInputs deserialize(JsonParser jp, DeserializationContext c
}
}
if (attemptParsing) {
tmp = tree.traverse(jp.getCodec()).readValueAs(Map.class);
tmp =
tree.traverse(jp.getCodec()).readValueAs(new TypeReference<Map<String, Object>>() {});
// TODO: there is no validation against JSON schema constraints
// (min, max, enum, pattern...), this does not perform a strict JSON
// validation, which means the 'match' count may be higher than it should be.
deserialized = tmp;
match++;

log.log(Level.FINER, "Input data matches schema 'Map'");
log.log(Level.FINER, "Input data matches schema 'Map<String, Object>'");
}
} catch (Exception e) {
// deserialization failed, continue
log.log(Level.FINER, "Input data does not match schema 'Map'", e);
log.log(Level.FINER, "Input data does not match schema 'Map<String, Object>'", e);
}

ActionQuerySpecInputs ret = new ActionQuerySpecInputs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public CIAppCreatePipelineEventRequestDataSingleOrArray deserialize(
e);
}

// deserialize List
// deserialize List<CIAppCreatePipelineEventRequestData>
try {
boolean attemptParsing = true;
// ensure that we respect type coercion as set on the client ObjectMapper
Expand All @@ -165,18 +165,24 @@ public CIAppCreatePipelineEventRequestDataSingleOrArray deserialize(
}
}
if (attemptParsing) {
tmp = tree.traverse(jp.getCodec()).readValueAs(List.class);
tmp =
tree.traverse(jp.getCodec())
.readValueAs(new TypeReference<List<CIAppCreatePipelineEventRequestData>>() {});
// TODO: there is no validation against JSON schema constraints
// (min, max, enum, pattern...), this does not perform a strict JSON
// validation, which means the 'match' count may be higher than it should be.
deserialized = tmp;
match++;

log.log(Level.FINER, "Input data matches schema 'List'");
log.log(
Level.FINER, "Input data matches schema 'List<CIAppCreatePipelineEventRequestData>'");
}
} catch (Exception e) {
// deserialization failed, continue
log.log(Level.FINER, "Input data does not match schema 'List'", e);
log.log(
Level.FINER,
"Input data does not match schema 'List<CIAppCreatePipelineEventRequestData>'",
e);
}

CIAppCreatePipelineEventRequestDataSingleOrArray ret =
Expand Down
Loading