Skip to content

Commit 4f04d09

Browse files
newtorka-d
andauthored
feat(openapi-generator): Allow for primitives in anyOf/oneOf component schema definitions (#681)
Co-authored-by: Alexander Dümont <[email protected]>
1 parent 0763a59 commit 4f04d09

File tree

21 files changed

+827
-18
lines changed

21 files changed

+827
-18
lines changed

datamodel/openapi/openapi-api-sample/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@
125125
<pojoBuildMethodName />
126126
<pojoConstructorVisibility>protected</pojoConstructorVisibility>
127127
<useOneOfInterfaces>true</useOneOfInterfaces>
128+
<useOneOfCreators>true</useOneOfCreators>
128129
<enumUnknownDefaultCase>true</enumUnknownDefaultCase>
129130
</additionalProperties>
131+
<enableOneOfAnyOfGeneration>true</enableOneOfAnyOfGeneration>
130132
</configuration>
131133
</plugin>
132134
<!-- Enable formatter to always run on the generated code -->

datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/AllOf.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public class AllOf
4545
@JsonProperty( "color" )
4646
private String color;
4747

48+
@JsonProperty( "flavor" )
49+
private FantaFlavor flavor;
50+
4851
@JsonAnySetter
4952
@JsonAnyGetter
5053
private final Map<String, Object> cloudSdkCustomFields = new LinkedHashMap<>();
@@ -164,6 +167,42 @@ public void setColor( @Nullable final String color )
164167
this.color = color;
165168
}
166169

170+
/**
171+
* Set the flavor of this {@link AllOf} instance and return the same instance.
172+
*
173+
* @param flavor
174+
* The flavor of this {@link AllOf}
175+
* @return The same instance of this {@link AllOf} class
176+
*/
177+
@Nonnull
178+
public AllOf flavor( @Nullable final FantaFlavor flavor )
179+
{
180+
this.flavor = flavor;
181+
return this;
182+
}
183+
184+
/**
185+
* Get flavor
186+
*
187+
* @return flavor The flavor of this {@link AllOf} instance.
188+
*/
189+
@Nonnull
190+
public FantaFlavor getFlavor()
191+
{
192+
return flavor;
193+
}
194+
195+
/**
196+
* Set the flavor of this {@link AllOf} instance.
197+
*
198+
* @param flavor
199+
* The flavor of this {@link AllOf}
200+
*/
201+
public void setFlavor( @Nullable final FantaFlavor flavor )
202+
{
203+
this.flavor = flavor;
204+
}
205+
167206
/**
168207
* Get the names of the unrecognizable properties of the {@link AllOf}.
169208
*
@@ -223,13 +262,14 @@ public boolean equals( @Nullable final java.lang.Object o )
223262
return Objects.equals(this.cloudSdkCustomFields, allOf.cloudSdkCustomFields)
224263
&& Objects.equals(this.sodaType, allOf.sodaType)
225264
&& Objects.equals(this.caffeine, allOf.caffeine)
226-
&& Objects.equals(this.color, allOf.color);
265+
&& Objects.equals(this.color, allOf.color)
266+
&& Objects.equals(this.flavor, allOf.flavor);
227267
}
228268

229269
@Override
230270
public int hashCode()
231271
{
232-
return Objects.hash(sodaType, caffeine, color, cloudSdkCustomFields);
272+
return Objects.hash(sodaType, caffeine, color, flavor, cloudSdkCustomFields);
233273
}
234274

235275
@Override
@@ -241,6 +281,7 @@ public String toString()
241281
sb.append(" sodaType: ").append(toIndentedString(sodaType)).append("\n");
242282
sb.append(" caffeine: ").append(toIndentedString(caffeine)).append("\n");
243283
sb.append(" color: ").append(toIndentedString(color)).append("\n");
284+
sb.append(" flavor: ").append(toIndentedString(flavor)).append("\n");
244285
cloudSdkCustomFields
245286
.forEach(( k, v ) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n"));
246287
sb.append("}");

datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/AnyOf.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public class AnyOf
4545
@JsonProperty( "color" )
4646
private String color;
4747

48+
@JsonProperty( "flavor" )
49+
private FantaFlavor flavor;
50+
4851
@JsonAnySetter
4952
@JsonAnyGetter
5053
private final Map<String, Object> cloudSdkCustomFields = new LinkedHashMap<>();
@@ -164,6 +167,42 @@ public void setColor( @Nullable final String color )
164167
this.color = color;
165168
}
166169

170+
/**
171+
* Set the flavor of this {@link AnyOf} instance and return the same instance.
172+
*
173+
* @param flavor
174+
* The flavor of this {@link AnyOf}
175+
* @return The same instance of this {@link AnyOf} class
176+
*/
177+
@Nonnull
178+
public AnyOf flavor( @Nullable final FantaFlavor flavor )
179+
{
180+
this.flavor = flavor;
181+
return this;
182+
}
183+
184+
/**
185+
* Get flavor
186+
*
187+
* @return flavor The flavor of this {@link AnyOf} instance.
188+
*/
189+
@Nonnull
190+
public FantaFlavor getFlavor()
191+
{
192+
return flavor;
193+
}
194+
195+
/**
196+
* Set the flavor of this {@link AnyOf} instance.
197+
*
198+
* @param flavor
199+
* The flavor of this {@link AnyOf}
200+
*/
201+
public void setFlavor( @Nullable final FantaFlavor flavor )
202+
{
203+
this.flavor = flavor;
204+
}
205+
167206
/**
168207
* Get the names of the unrecognizable properties of the {@link AnyOf}.
169208
*
@@ -223,13 +262,14 @@ public boolean equals( @Nullable final java.lang.Object o )
223262
return Objects.equals(this.cloudSdkCustomFields, anyOf.cloudSdkCustomFields)
224263
&& Objects.equals(this.sodaType, anyOf.sodaType)
225264
&& Objects.equals(this.caffeine, anyOf.caffeine)
226-
&& Objects.equals(this.color, anyOf.color);
265+
&& Objects.equals(this.color, anyOf.color)
266+
&& Objects.equals(this.flavor, anyOf.flavor);
227267
}
228268

229269
@Override
230270
public int hashCode()
231271
{
232-
return Objects.hash(sodaType, caffeine, color, cloudSdkCustomFields);
272+
return Objects.hash(sodaType, caffeine, color, flavor, cloudSdkCustomFields);
233273
}
234274

235275
@Override
@@ -241,6 +281,7 @@ public String toString()
241281
sb.append(" sodaType: ").append(toIndentedString(sodaType)).append("\n");
242282
sb.append(" caffeine: ").append(toIndentedString(caffeine)).append("\n");
243283
sb.append(" color: ").append(toIndentedString(color)).append("\n");
284+
sb.append(" flavor: ").append(toIndentedString(flavor)).append("\n");
244285
cloudSdkCustomFields
245286
.forEach(( k, v ) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n"));
246287
sb.append("}");

datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/Fanta.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class Fanta implements OneOf, OneOfWithDiscriminator, OneOfWithDiscrimina
4242
@JsonProperty( "color" )
4343
private String color;
4444

45+
@JsonProperty( "flavor" )
46+
private FantaFlavor flavor;
47+
4548
@JsonAnySetter
4649
@JsonAnyGetter
4750
private final Map<String, Object> cloudSdkCustomFields = new LinkedHashMap<>();
@@ -125,6 +128,42 @@ public void setColor( @Nullable final String color )
125128
this.color = color;
126129
}
127130

131+
/**
132+
* Set the flavor of this {@link Fanta} instance and return the same instance.
133+
*
134+
* @param flavor
135+
* The flavor of this {@link Fanta}
136+
* @return The same instance of this {@link Fanta} class
137+
*/
138+
@Nonnull
139+
public Fanta flavor( @Nullable final FantaFlavor flavor )
140+
{
141+
this.flavor = flavor;
142+
return this;
143+
}
144+
145+
/**
146+
* Get flavor
147+
*
148+
* @return flavor The flavor of this {@link Fanta} instance.
149+
*/
150+
@Nonnull
151+
public FantaFlavor getFlavor()
152+
{
153+
return flavor;
154+
}
155+
156+
/**
157+
* Set the flavor of this {@link Fanta} instance.
158+
*
159+
* @param flavor
160+
* The flavor of this {@link Fanta}
161+
*/
162+
public void setFlavor( @Nullable final FantaFlavor flavor )
163+
{
164+
this.flavor = flavor;
165+
}
166+
128167
/**
129168
* Get the names of the unrecognizable properties of the {@link Fanta}.
130169
*
@@ -183,13 +222,14 @@ public boolean equals( @Nullable final java.lang.Object o )
183222
final Fanta fanta = (Fanta) o;
184223
return Objects.equals(this.cloudSdkCustomFields, fanta.cloudSdkCustomFields)
185224
&& Objects.equals(this.sodaType, fanta.sodaType)
186-
&& Objects.equals(this.color, fanta.color);
225+
&& Objects.equals(this.color, fanta.color)
226+
&& Objects.equals(this.flavor, fanta.flavor);
187227
}
188228

189229
@Override
190230
public int hashCode()
191231
{
192-
return Objects.hash(sodaType, color, cloudSdkCustomFields);
232+
return Objects.hash(sodaType, color, flavor, cloudSdkCustomFields);
193233
}
194234

195235
@Override
@@ -200,6 +240,7 @@ public String toString()
200240
sb.append("class Fanta {\n");
201241
sb.append(" sodaType: ").append(toIndentedString(sodaType)).append("\n");
202242
sb.append(" color: ").append(toIndentedString(color)).append("\n");
243+
sb.append(" flavor: ").append(toIndentedString(flavor)).append("\n");
203244
cloudSdkCustomFields
204245
.forEach(( k, v ) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n"));
205246
sb.append("}");
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved.
3+
*/
4+
5+
/*
6+
* SodaStore API
7+
* API for managing soda products and orders in SodaStore.
8+
*
9+
*
10+
*
11+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
12+
* https://openapi-generator.tech
13+
* Do not edit the class manually.
14+
*/
15+
16+
package com.sap.cloud.sdk.datamodel.openapi.sample.model;
17+
18+
import javax.annotation.Nonnull;
19+
20+
import com.fasterxml.jackson.annotation.JsonCreator;
21+
import com.fasterxml.jackson.annotation.JsonValue;
22+
23+
/**
24+
* FantaFlavor
25+
*/
26+
public interface FantaFlavor
27+
{
28+
/**
29+
* Helper class to create a Integer that implements {@link FantaFlavor}.
30+
*/
31+
record InnerInteger(@com.fasterxml.jackson.annotation.JsonValue @Nonnull Integer value) implements FantaFlavor {}
32+
33+
/**
34+
* Creator to enable deserialization of a Integer.
35+
*
36+
* @param val
37+
* the value to use
38+
* @return a new instance of {@link InnerInteger}.
39+
*/
40+
@com.fasterxml.jackson.annotation.JsonCreator
41+
@Nonnull
42+
static InnerInteger create( @Nonnull final Integer val )
43+
{
44+
return new InnerInteger(val);
45+
}
46+
47+
/**
48+
* Helper class to create a FantaFlavorOneOf that implements {@link FantaFlavor}.
49+
*/
50+
record InnerFantaFlavorOneOf(@com.fasterxml.jackson.annotation.JsonValue @Nonnull FantaFlavorOneOf value) implements FantaFlavor {}
51+
52+
/**
53+
* Creator to enable deserialization of a FantaFlavorOneOf.
54+
*
55+
* @param val
56+
* the value to use
57+
* @return a new instance of {@link InnerFantaFlavorOneOf}.
58+
*/
59+
@com.fasterxml.jackson.annotation.JsonCreator
60+
@Nonnull
61+
static InnerFantaFlavorOneOf create( @Nonnull final FantaFlavorOneOf val )
62+
{
63+
return new InnerFantaFlavorOneOf(val);
64+
}
65+
66+
/**
67+
* Helper class to create a String that implements {@link FantaFlavor}.
68+
*/
69+
record InnerString(@com.fasterxml.jackson.annotation.JsonValue @Nonnull String value) implements FantaFlavor {}
70+
71+
/**
72+
* Creator to enable deserialization of a String.
73+
*
74+
* @param val
75+
* the value to use
76+
* @return a new instance of {@link InnerString}.
77+
*/
78+
@com.fasterxml.jackson.annotation.JsonCreator
79+
@Nonnull
80+
static InnerString create( @Nonnull final String val )
81+
{
82+
return new InnerString(val);
83+
}
84+
85+
}

0 commit comments

Comments
 (0)