Skip to content

Commit fa2b575

Browse files
authored
[Bug] [Java] Remove raw type compilation warnings when generating using jersey2 or jersey3 (#19033)
* Add type annotations to raw types for jersey2 and jersey3 templates * Update samples * Add type parameters to anyof_model.mustache and oneof_model.mustache --------- Co-authored-by: Kasper S. Nielsen <kasper.s.nielsen@secata.com>
1 parent 53f1094 commit fa2b575

64 files changed

Lines changed: 176 additions & 176 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/resources/Java/libraries/jersey2/AbstractOpenApiSchema.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public abstract class AbstractOpenApiSchema {
3535
*
3636
* @return an instance of the actual schema/object
3737
*/
38-
public abstract Map<String, GenericType> getSchemas();
38+
public abstract Map<String, GenericType<?>> getSchemas();
3939

4040
/**
4141
* Get the actual instance

modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
824824
return formatDate((Date) param);
825825
} {{#jsr310}}else if (param instanceof OffsetDateTime) {
826826
return formatOffsetDateTime((OffsetDateTime) param);
827-
} {{/jsr310}}else if (param instanceof Collection) {
827+
} {{/jsr310}}else if (param instanceof Collection<?>) {
828828
StringBuilder b = new StringBuilder();
829-
for(Object o : (Collection)param) {
829+
for(Object o : (Collection<?>)param) {
830830
if(b.length() > 0) {
831831
b.append(',');
832832
}
@@ -852,9 +852,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
852852
// preconditions
853853
if (name == null || name.isEmpty() || value == null) return params;
854854
855-
Collection valueCollection;
856-
if (value instanceof Collection) {
857-
valueCollection = (Collection) value;
855+
Collection<?> valueCollection;
856+
if (value instanceof Collection<?>) {
857+
valueCollection = (Collection<?>) value;
858858
} else {
859859
params.add(new Pair(name, parameterToString(value)));
860860
return params;

modules/openapi-generator/src/main/resources/Java/libraries/jersey2/JSON.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ public class JSON implements ContextResolver<ObjectMapper> {
191191
visitedClasses.add(modelClass);
192192

193193
// Traverse the oneOf/anyOf composed schemas.
194-
Map<String, GenericType> descendants = modelDescendants.get(modelClass);
194+
Map<String, GenericType<?>> descendants = modelDescendants.get(modelClass);
195195
if (descendants != null) {
196-
for (GenericType childType : descendants.values()) {
196+
for (GenericType<?> childType : descendants.values()) {
197197
if (isInstanceOf(childType.getRawType(), inst, visitedClasses)) {
198198
return true;
199199
}
@@ -210,7 +210,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
210210
/**
211211
* A map of oneOf/anyOf descendants for each model class.
212212
*/
213-
private static Map<Class<?>, Map<String, GenericType>> modelDescendants = new HashMap<>();
213+
private static Map<Class<?>, Map<String, GenericType<?>>> modelDescendants = new HashMap<>();
214214

215215
/**
216216
* Register a model class discriminator.
@@ -230,7 +230,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
230230
* @param modelClass the model class
231231
* @param descendants a map of oneOf/anyOf descendants.
232232
*/
233-
public static void registerDescendants(Class<?> modelClass, Map<String, GenericType> descendants) {
233+
public static void registerDescendants(Class<?> modelClass, Map<String, GenericType<?>> descendants) {
234234
modelDescendants.put(modelClass, descendants);
235235
}
236236

modules/openapi-generator/src/main/resources/Java/libraries/jersey2/anyof_model.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
9999
}
100100

101101
// store a list of schema names defined in anyOf
102-
public static final Map<String, GenericType> schemas = new HashMap<>();
102+
public static final Map<String, GenericType<?>> schemas = new HashMap<>();
103103

104104
public {{classname}}() {
105105
super("anyOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
@@ -144,7 +144,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
144144
}
145145

146146
@Override
147-
public Map<String, GenericType> getSchemas() {
147+
public Map<String, GenericType<?>> getSchemas() {
148148
return {{classname}}.schemas;
149149
}
150150

modules/openapi-generator/src/main/resources/Java/libraries/jersey2/oneof_model.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
169169
}
170170

171171
// store a list of schema names defined in oneOf
172-
public static final Map<String, GenericType> schemas = new HashMap<>();
172+
public static final Map<String, GenericType<?>> schemas = new HashMap<>();
173173

174174
public {{classname}}() {
175175
super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
@@ -218,7 +218,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
218218
}
219219

220220
@Override
221-
public Map<String, GenericType> getSchemas() {
221+
public Map<String, GenericType<?>> getSchemas() {
222222
return {{classname}}.schemas;
223223
}
224224

modules/openapi-generator/src/main/resources/Java/libraries/jersey3/AbstractOpenApiSchema.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public abstract class AbstractOpenApiSchema {
3535
*
3636
* @return an instance of the actual schema/object
3737
*/
38-
public abstract Map<String, GenericType> getSchemas();
38+
public abstract Map<String, GenericType<?>> getSchemas();
3939

4040
/**
4141
* Get the actual instance

modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
824824
return formatDate((Date) param);
825825
} {{#jsr310}}else if (param instanceof OffsetDateTime) {
826826
return formatOffsetDateTime((OffsetDateTime) param);
827-
} {{/jsr310}}else if (param instanceof Collection) {
827+
} {{/jsr310}}else if (param instanceof Collection<?>) {
828828
StringBuilder b = new StringBuilder();
829-
for(Object o : (Collection)param) {
829+
for(Object o : (Collection<?>)param) {
830830
if(b.length() > 0) {
831831
b.append(',');
832832
}
@@ -852,9 +852,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
852852
// preconditions
853853
if (name == null || name.isEmpty() || value == null) return params;
854854
855-
Collection valueCollection;
856-
if (value instanceof Collection) {
857-
valueCollection = (Collection) value;
855+
Collection<?> valueCollection;
856+
if (value instanceof Collection<?>) {
857+
valueCollection = (Collection<?>) value;
858858
} else {
859859
params.add(new Pair(name, parameterToString(value)));
860860
return params;

modules/openapi-generator/src/main/resources/Java/libraries/jersey3/JSON.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ public class JSON implements ContextResolver<ObjectMapper> {
191191
visitedClasses.add(modelClass);
192192

193193
// Traverse the oneOf/anyOf composed schemas.
194-
Map<String, GenericType> descendants = modelDescendants.get(modelClass);
194+
Map<String, GenericType<?>> descendants = modelDescendants.get(modelClass);
195195
if (descendants != null) {
196-
for (GenericType childType : descendants.values()) {
196+
for (GenericType<?> childType : descendants.values()) {
197197
if (isInstanceOf(childType.getRawType(), inst, visitedClasses)) {
198198
return true;
199199
}
@@ -210,7 +210,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
210210
/**
211211
* A map of oneOf/anyOf descendants for each model class.
212212
*/
213-
private static Map<Class<?>, Map<String, GenericType>> modelDescendants = new HashMap<>();
213+
private static Map<Class<?>, Map<String, GenericType<?>>> modelDescendants = new HashMap<>();
214214

215215
/**
216216
* Register a model class discriminator.
@@ -230,7 +230,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
230230
* @param modelClass the model class
231231
* @param descendants a map of oneOf/anyOf descendants.
232232
*/
233-
public static void registerDescendants(Class<?> modelClass, Map<String, GenericType> descendants) {
233+
public static void registerDescendants(Class<?> modelClass, Map<String, GenericType<?>> descendants) {
234234
modelDescendants.put(modelClass, descendants);
235235
}
236236

modules/openapi-generator/src/main/resources/Java/libraries/jersey3/anyof_model.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
9999
}
100100

101101
// store a list of schema names defined in anyOf
102-
public static final Map<String, GenericType> schemas = new HashMap<>();
102+
public static final Map<String, GenericType<?>> schemas = new HashMap<>();
103103

104104
public {{classname}}() {
105105
super("anyOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
@@ -144,7 +144,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
144144
}
145145

146146
@Override
147-
public Map<String, GenericType> getSchemas() {
147+
public Map<String, GenericType<?>> getSchemas() {
148148
return {{classname}}.schemas;
149149
}
150150

modules/openapi-generator/src/main/resources/Java/libraries/jersey3/oneof_model.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
169169
}
170170

171171
// store a list of schema names defined in oneOf
172-
public static final Map<String, GenericType> schemas = new HashMap<>();
172+
public static final Map<String, GenericType<?>> schemas = new HashMap<>();
173173

174174
public {{classname}}() {
175175
super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
@@ -218,7 +218,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
218218
}
219219

220220
@Override
221-
public Map<String, GenericType> getSchemas() {
221+
public Map<String, GenericType<?>> getSchemas() {
222222
return {{classname}}.schemas;
223223
}
224224

0 commit comments

Comments
 (0)