forked from loafle/openapi-generator-original
[OpenAPI 3.1] Avoid NPE when handling prefixItems (#19735)
* avoid npe when handling prefixItems in 3.1 spec * update samples
This commit is contained in:
parent
60d0888898
commit
d7ac1e4337
@ -1280,6 +1280,9 @@ public class OpenAPINormalizer {
|
|||||||
Schema updatedItems = normalizeSchema(schema.getItems(), visitedSchemas);
|
Schema updatedItems = normalizeSchema(schema.getItems(), visitedSchemas);
|
||||||
as.setItems(updatedItems);
|
as.setItems(updatedItems);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// when items is not defined, default to any type
|
||||||
|
as.setItems(new Schema());
|
||||||
}
|
}
|
||||||
|
|
||||||
return as;
|
return as;
|
||||||
|
@ -600,6 +600,11 @@ public class OpenAPINormalizerTest {
|
|||||||
assertEquals(((Schema) schema5.getProperties().get("arrayOfStrings")).getItems().getType(), null);
|
assertEquals(((Schema) schema5.getProperties().get("arrayOfStrings")).getItems().getType(), null);
|
||||||
assertEquals(((Schema) schema5.getProperties().get("arrayOfStrings")).getItems().getTypes().contains("string"), true);
|
assertEquals(((Schema) schema5.getProperties().get("arrayOfStrings")).getItems().getTypes().contains("string"), true);
|
||||||
|
|
||||||
|
Schema schema7 = openAPI.getComponents().getSchemas().get("ArrayWithPrefixItems");
|
||||||
|
assertEquals(((Schema) schema7.getProperties().get("with_prefixitems")).getItems(), null);
|
||||||
|
assertNotEquals(((Schema) schema7.getProperties().get("with_prefixitems")).getPrefixItems(), null);
|
||||||
|
assertEquals(((Schema) schema7.getProperties().get("without_items")).getItems(), null);
|
||||||
|
|
||||||
Map<String, String> inputRules = Map.of("NORMALIZE_31SPEC", "true");
|
Map<String, String> inputRules = Map.of("NORMALIZE_31SPEC", "true");
|
||||||
OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer(openAPI, inputRules);
|
OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer(openAPI, inputRules);
|
||||||
openAPINormalizer.normalize();
|
openAPINormalizer.normalize();
|
||||||
@ -622,6 +627,11 @@ public class OpenAPINormalizerTest {
|
|||||||
assertEquals(((Schema) schema6.getProperties().get("arrayOfStrings")).getItems().getTypes().contains("string"), true);
|
assertEquals(((Schema) schema6.getProperties().get("arrayOfStrings")).getItems().getTypes().contains("string"), true);
|
||||||
assertEquals(((Schema) schema6.getProperties().get("arrayOfStrings")).getItems().getType(), "string");
|
assertEquals(((Schema) schema6.getProperties().get("arrayOfStrings")).getItems().getType(), "string");
|
||||||
assertEquals(((Schema) schema6.getProperties().get("arrayOfStrings")).getType(), "array");
|
assertEquals(((Schema) schema6.getProperties().get("arrayOfStrings")).getType(), "array");
|
||||||
|
|
||||||
|
Schema schema8 = openAPI.getComponents().getSchemas().get("ArrayWithPrefixItems");
|
||||||
|
assertNotEquals(((Schema) schema8.getProperties().get("with_prefixitems")).getItems(), null);
|
||||||
|
assertEquals(((Schema) schema8.getProperties().get("with_prefixitems")).getPrefixItems(), null);
|
||||||
|
assertNotEquals(((Schema) schema8.getProperties().get("without_items")).getItems(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -30,7 +30,20 @@ components:
|
|||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
Bar:
|
Bar:
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: '#/components/schemas/Foo'
|
- $ref: '#/components/schemas/Foo'
|
||||||
|
ArrayWithPrefixItems:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
with_prefixitems:
|
||||||
|
type: array
|
||||||
|
prefixItems:
|
||||||
|
- type: number
|
||||||
|
title: Longitude
|
||||||
|
- type: number
|
||||||
|
title: Latitude
|
||||||
|
maxItems: 2
|
||||||
|
minItems: 2
|
||||||
|
without_items:
|
||||||
|
type: array
|
||||||
|
@ -1099,9 +1099,7 @@ components:
|
|||||||
ref_array_prefix_items:
|
ref_array_prefix_items:
|
||||||
description: |
|
description: |
|
||||||
An item that was added to the queue.
|
An item that was added to the queue.
|
||||||
items:
|
items: {}
|
||||||
description: TODO default missing array inner type to string
|
|
||||||
type: string
|
|
||||||
maxItems: 5
|
maxItems: 5
|
||||||
minItems: 3
|
minItems: 3
|
||||||
type: array
|
type: array
|
||||||
@ -1112,9 +1110,7 @@ components:
|
|||||||
ArrayPrefixItems:
|
ArrayPrefixItems:
|
||||||
description: |
|
description: |
|
||||||
An item that was added to the queue.
|
An item that was added to the queue.
|
||||||
items:
|
items: {}
|
||||||
description: TODO default missing array inner type to string
|
|
||||||
type: string
|
|
||||||
maxItems: 5
|
maxItems: 5
|
||||||
minItems: 3
|
minItems: 3
|
||||||
type: array
|
type: array
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|------------ | ------------- | ------------- | -------------|
|
|------------ | ------------- | ------------- | -------------|
|
||||||
|**anyTypeProperty** | **Object** | | [optional] |
|
|**anyTypeProperty** | **Object** | | [optional] |
|
||||||
|**arrayProp** | **List<String>** | test array in 3.1 spec | [optional] |
|
|**arrayProp** | **List<String>** | test array in 3.1 spec | [optional] |
|
||||||
|**refArrayPrefixItems** | **List<String>** | An item that was added to the queue. | [optional] |
|
|**refArrayPrefixItems** | **List<Object>** | An item that was added to the queue. | [optional] |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public class AnyTypeTest {
|
|||||||
|
|
||||||
public static final String SERIALIZED_NAME_REF_ARRAY_PREFIX_ITEMS = "ref_array_prefix_items";
|
public static final String SERIALIZED_NAME_REF_ARRAY_PREFIX_ITEMS = "ref_array_prefix_items";
|
||||||
@SerializedName(SERIALIZED_NAME_REF_ARRAY_PREFIX_ITEMS)
|
@SerializedName(SERIALIZED_NAME_REF_ARRAY_PREFIX_ITEMS)
|
||||||
private List<String> refArrayPrefixItems = new ArrayList<>();
|
private List<Object> refArrayPrefixItems = new ArrayList<>();
|
||||||
|
|
||||||
public AnyTypeTest() {
|
public AnyTypeTest() {
|
||||||
}
|
}
|
||||||
@ -114,12 +114,12 @@ public class AnyTypeTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public AnyTypeTest refArrayPrefixItems(List<String> refArrayPrefixItems) {
|
public AnyTypeTest refArrayPrefixItems(List<Object> refArrayPrefixItems) {
|
||||||
this.refArrayPrefixItems = refArrayPrefixItems;
|
this.refArrayPrefixItems = refArrayPrefixItems;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AnyTypeTest addRefArrayPrefixItemsItem(String refArrayPrefixItemsItem) {
|
public AnyTypeTest addRefArrayPrefixItemsItem(Object refArrayPrefixItemsItem) {
|
||||||
if (this.refArrayPrefixItems == null) {
|
if (this.refArrayPrefixItems == null) {
|
||||||
this.refArrayPrefixItems = new ArrayList<>();
|
this.refArrayPrefixItems = new ArrayList<>();
|
||||||
}
|
}
|
||||||
@ -132,11 +132,11 @@ public class AnyTypeTest {
|
|||||||
* @return refArrayPrefixItems
|
* @return refArrayPrefixItems
|
||||||
*/
|
*/
|
||||||
@javax.annotation.Nullable
|
@javax.annotation.Nullable
|
||||||
public List<String> getRefArrayPrefixItems() {
|
public List<Object> getRefArrayPrefixItems() {
|
||||||
return refArrayPrefixItems;
|
return refArrayPrefixItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRefArrayPrefixItems(List<String> refArrayPrefixItems) {
|
public void setRefArrayPrefixItems(List<Object> refArrayPrefixItems) {
|
||||||
this.refArrayPrefixItems = refArrayPrefixItems;
|
this.refArrayPrefixItems = refArrayPrefixItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,14 +24,14 @@ pub enum NumericEnumTesting {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for NumericEnumTesting {
|
impl std::fmt::Display for NumericEnumTesting {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
write!(f, "{}", match self {
|
||||||
Self::Variant0 => String::from("0"),
|
Self::Variant0 => "0",
|
||||||
Self::Variant1 => String::from("1"),
|
Self::Variant1 => "1",
|
||||||
Self::Variant2 => String::from("2"),
|
Self::Variant2 => "2",
|
||||||
Self::Variant3 => String::from("3"),
|
Self::Variant3 => "3",
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Default for NumericEnumTesting {
|
impl Default for NumericEnumTesting {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user