mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-10-13 16:03:43 +00:00
[3.1] Fixed lack of check for booleanSchemaValue
(#21742)
* [3.1] Fixed lack of check for ´booleanSchemaValue` * [3.1] Fixed `isMapSchema`
This commit is contained in:
parent
eae5088f7c
commit
27d3c6f326
@ -559,7 +559,9 @@ public class ModelUtils {
|
||||
}
|
||||
|
||||
// additionalProperties explicitly set to false
|
||||
if (schema.getAdditionalProperties() instanceof Boolean && Boolean.FALSE.equals(schema.getAdditionalProperties())) {
|
||||
if ((schema.getAdditionalProperties() instanceof Boolean && Boolean.FALSE.equals(schema.getAdditionalProperties())) ||
|
||||
(schema.getAdditionalProperties() instanceof Schema && Boolean.FALSE.equals(((Schema) schema.getAdditionalProperties()).getBooleanSchemaValue()))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -808,7 +810,13 @@ public class ModelUtils {
|
||||
(null != schema.getProperties() && !schema.getProperties().isEmpty()) &&
|
||||
// no additionalProperties is set
|
||||
(schema.getAdditionalProperties() == null ||
|
||||
(schema.getAdditionalProperties() instanceof Boolean && !(Boolean) schema.getAdditionalProperties()));
|
||||
// additionalProperties is boolean and set to false
|
||||
(schema.getAdditionalProperties() instanceof Boolean && !(Boolean) schema.getAdditionalProperties()) ||
|
||||
// additionalProperties is a schema with its boolean value set to false
|
||||
(schema.getAdditionalProperties() instanceof Schema &&
|
||||
((Schema) schema.getAdditionalProperties()).getBooleanSchemaValue() != null &&
|
||||
!((Schema) schema.getAdditionalProperties()).getBooleanSchemaValue())
|
||||
);
|
||||
}
|
||||
|
||||
public static boolean hasValidation(Schema sc) {
|
||||
@ -2422,7 +2430,7 @@ public class ModelUtils {
|
||||
* For example, a schema that only has a `description` without any `properties` or `$ref` defined.
|
||||
*
|
||||
* @param schema the schema
|
||||
* @return if the schema is only metadata and not an actual type
|
||||
* @return if the schema is only metadata and not an actual type
|
||||
*/
|
||||
public static boolean isMetadataOnlySchema(Schema schema) {
|
||||
return !(schema.get$ref() != null ||
|
||||
|
@ -353,6 +353,9 @@ public class ModelUtilsTest {
|
||||
Assert.assertNull(anyof1Property.getType());
|
||||
Assert.assertTrue(ModelUtils.hasAnyOf(anyof1Property));
|
||||
Assert.assertTrue(ModelUtils.isAnyOf(anyof1Property));
|
||||
|
||||
Schema objectSchema = ModelUtils.getSchema(openAPI, "ObjectSchema");
|
||||
Assert.assertFalse(ModelUtils.isMapSchema(objectSchema));
|
||||
}
|
||||
|
||||
// 3.1 spec tests
|
||||
@ -392,7 +395,7 @@ public class ModelUtilsTest {
|
||||
Assert.assertTrue(ModelUtils.isAnyOf(anyof2));
|
||||
|
||||
Schema objectSchema = ModelUtils.getSchema(openAPI, "ObjectSchema");
|
||||
Assert.assertTrue(ModelUtils.isMapSchema(objectSchema));
|
||||
Assert.assertFalse(ModelUtils.isMapSchema(objectSchema));
|
||||
|
||||
Schema complexComposedSchema = ModelUtils.getSchema(openAPI, "ComplexComposedSchema");
|
||||
Assert.assertTrue(ModelUtils.isComplexComposedSchema(complexComposedSchema));
|
||||
@ -641,4 +644,35 @@ public class ModelUtilsTest {
|
||||
assertFalse(ModelUtils.isUnsupportedSchema(openAPI, (Schema) property2.getProperties().get("condition")));
|
||||
assertFalse(ModelUtils.isUnsupportedSchema(openAPI, (Schema) property2.getProperties().get("purpose")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModelWithPropertiesOnly() {
|
||||
// Schema with no properties
|
||||
Schema testSchema = new ObjectSchema().properties(null);
|
||||
assertFalse(ModelUtils.isModelWithPropertiesOnly(testSchema));
|
||||
|
||||
// Schema with properties
|
||||
testSchema.setProperties(Map.of("foo", new Schema()));
|
||||
assertTrue(ModelUtils.isModelWithPropertiesOnly(testSchema));
|
||||
|
||||
// Explicitly no additional properties
|
||||
testSchema.setAdditionalProperties(false);
|
||||
assertTrue(ModelUtils.isModelWithPropertiesOnly(testSchema));
|
||||
|
||||
// With additional properties
|
||||
testSchema.setAdditionalProperties(true);
|
||||
assertFalse(ModelUtils.isModelWithPropertiesOnly(testSchema));
|
||||
|
||||
// Additional properties is a schema set to false
|
||||
testSchema.setAdditionalProperties(new Schema().booleanSchemaValue(false));
|
||||
assertTrue(ModelUtils.isModelWithPropertiesOnly(testSchema));
|
||||
|
||||
// Additional properties is a schema set to true
|
||||
testSchema.setAdditionalProperties(new Schema().booleanSchemaValue(true));
|
||||
assertFalse(ModelUtils.isModelWithPropertiesOnly(testSchema));
|
||||
|
||||
// Additional properties is a custom schema
|
||||
testSchema.setAdditionalProperties(new Schema().type("string"));
|
||||
assertFalse(ModelUtils.isModelWithPropertiesOnly(testSchema));
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,14 @@ components:
|
||||
oneOf:
|
||||
- type: string
|
||||
- type: integer
|
||||
ObjectSchema:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
address:
|
||||
type: string
|
||||
anyof1:
|
||||
anyOf:
|
||||
- type: string
|
||||
|
Loading…
x
Reference in New Issue
Block a user