Skip to content
Open
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
17 changes: 14 additions & 3 deletions .generator/src/generator/templates/modelOneOf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public class {{ name }} extends AbstractOpenApiSchema {
{%- set parameterizedDataType = get_type(oneOf) %}
{%- set unParameterizedDataType = parameterizedDataType|un_parameterize_type %}
{%- set isParameterized = parameterizedDataType|is_parameterized_type %}
{%- set isModelMember = not oneOf|is_primitive and not unParameterizedDataType|lower|is_java_base_type and "enum" not in oneOf %}
{%- set isComposedMember = "oneOf" in oneOf or "anyOf" in oneOf %}
{%- set isModelListMember = "items" in oneOf and oneOf.get("items")|is_model and not oneOf|is_primitive %}
// deserialize {{ parameterizedDataType }}
try {
boolean attemptParsing = true;
Expand All @@ -108,12 +111,20 @@ public class {{ name }} extends AbstractOpenApiSchema {
// 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.
{%- if not oneOf|is_primitive and not unParameterizedDataType|lower|is_java_base_type and "enum" not in oneOf %}
if (!(({{ unParameterizedDataType }})tmp).unparsed) {
{%- if isModelMember %}
if (!(({{ unParameterizedDataType }}) tmp).unparsed
{%- if isComposedMember %}
{#- unmatched oneOf doesn't propagate to "tmp.unparsed": we aim
for today's client to be forward-compatible with future oneOf
branches. But a oneOf branch that it itself a oneOf? We _must_
respect the nested oneOf's `unparsed` or the oneOf branch will
always match. #}
&& !((({{ unParameterizedDataType }}) tmp).getActualInstance() instanceof UnparsedObject)
{%- endif %}) {
deserialized = tmp;
match++;
}
{%- elif "items" in oneOf and oneOf.get("items")|is_model and not oneOf|is_primitive %}
{%- elif isModelListMember %}
{%- set itemsDataType = get_type(oneOf.get("items")) %}
// keep the matched list, but propagate 'unparsed' from any invalid item
boolean itemsUnparsed = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ public CIAppCreatePipelineEventRequestAttributesResource deserialize(
// 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.
if (!((CIAppPipelineEventPipeline) tmp).unparsed) {
if (!((CIAppPipelineEventPipeline) tmp).unparsed
&& !(((CIAppPipelineEventPipeline) tmp).getActualInstance()
instanceof UnparsedObject)) {
deserialized = tmp;
match++;
}
Expand Down Expand Up @@ -214,7 +216,8 @@ public CIAppCreatePipelineEventRequestAttributesResource deserialize(
// 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.
if (!((CIAppPipelineEventJob) tmp).unparsed) {
if (!((CIAppPipelineEventJob) tmp).unparsed
&& !(((CIAppPipelineEventJob) tmp).getActualInstance() instanceof UnparsedObject)) {
deserialized = tmp;
match++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public UpsertCatalogEntityRequest deserialize(JsonParser jp, DeserializationCont
// 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.
if (!((EntityV3) tmp).unparsed) {
if (!((EntityV3) tmp).unparsed
&& !(((EntityV3) tmp).getActualInstance() instanceof UnparsedObject)) {
deserialized = tmp;
match++;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-Present Datadog, Inc.
*/

package com.datadog.api.client.v2.api;

import static com.datadog.api.World.fromJSON;
import static org.junit.Assert.assertEquals;

import com.datadog.api.client.v2.model.CIAppCreatePipelineEventRequestAttributesResource;
import com.datadog.api.client.v2.model.CIAppPipelineEventFinishedJob;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;

public class CIAppPipelineEventJobTest extends V2APITest {

private static ObjectMapper objectMapper;

@Override
public String getTracingEndpoint() {
return "ci-app";
}

@BeforeClass
public static void initApi() {
objectMapper = generalApiUnitTestClient.getJSON().getMapper();
}

@Test
public void testDeserializeNestedOneOfJob() throws JsonProcessingException {
String body =
"{\"end\":\"2023-01-01T12:00:01+00:00\",\"id\":\"job-id\",\"level\":\"job\",\"name\":\"job-name\",\"pipeline_name\":\"my-pipeline\",\"pipeline_unique_id\":\"pipeline-unique-id\",\"start\":\"2023-01-01T12:00:00+00:00\",\"status\":\"success\",\"url\":\"https://example.com/job\"}";
CIAppCreatePipelineEventRequestAttributesResource res =
fromJSON(objectMapper, CIAppCreatePipelineEventRequestAttributesResource.class, body);

CIAppPipelineEventFinishedJob finishedJob =
res.getCIAppPipelineEventJob().getCIAppPipelineEventFinishedJob();
assertEquals("job-id", finishedJob.getId());
}
}
Loading