forked from loafle/openapi-generator-original
fix schema with just a description
This commit is contained in:
parent
61bdc6bf84
commit
754207a636
@ -430,7 +430,7 @@ public class ModelUtils {
|
||||
* <p>
|
||||
* For example, an OpenAPI schema is considered an ObjectSchema in the following scenarios:
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* type: object
|
||||
* additionalProperties: false
|
||||
* properties:
|
||||
@ -534,17 +534,17 @@ public class ModelUtils {
|
||||
* <p>
|
||||
* For example, an OpenAPI schema is considered a MapSchema in the following scenarios:
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* type: object
|
||||
* additionalProperties: true
|
||||
*
|
||||
* <p>
|
||||
* type: object
|
||||
* additionalProperties:
|
||||
* type: object
|
||||
* properties:
|
||||
* code:
|
||||
* type: integer
|
||||
*
|
||||
* <p>
|
||||
* allOf:
|
||||
* - $ref: '#/components/schemas/Class1'
|
||||
* - $ref: '#/components/schemas/Class2'
|
||||
@ -1935,7 +1935,7 @@ public class ModelUtils {
|
||||
private static void logWarnMessagesForIneffectiveValidations(Set<String> setValidations, Schema schema, Set<String> effectiveValidations) {
|
||||
setValidations.removeAll(effectiveValidations);
|
||||
setValidations.stream().forEach(validation -> {
|
||||
LOGGER.warn("Validation '" + validation + "' has no effect on schema '" + getType(schema) +"'. Ignoring!");
|
||||
LOGGER.warn("Validation '" + validation + "' has no effect on schema '" + getType(schema) + "'. Ignoring!");
|
||||
});
|
||||
}
|
||||
|
||||
@ -2216,7 +2216,6 @@ public class ModelUtils {
|
||||
*
|
||||
* @param schema Schema
|
||||
* @param openAPI OpenAPI
|
||||
*
|
||||
* @return true if schema is null type
|
||||
*/
|
||||
public static boolean isNullTypeSchema(OpenAPI openAPI, Schema schema) {
|
||||
@ -2260,11 +2259,14 @@ public class ModelUtils {
|
||||
}
|
||||
|
||||
// for `type: null`
|
||||
if (schema.getTypes() == null && schema.get$ref() == null) {
|
||||
if (schema.getTypes() == null && schema.get$ref() == null
|
||||
&& schema.getDescription() == null) { // ensure it's not schema with just a description
|
||||
return true;
|
||||
}
|
||||
} else { // 3.0.x or 2.x spec
|
||||
if ((schema.getType() == null || schema.getType().equals("null")) && schema.get$ref() == null) {
|
||||
if ((schema.getType() == null || schema.getType().equals("null"))
|
||||
&& schema.get$ref() == null
|
||||
&& schema.getDescription() == null) { // ensure it's not schema with just a description
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -2279,7 +2281,6 @@ public class ModelUtils {
|
||||
*
|
||||
* @param schema Schema
|
||||
* @param openAPI OpenAPIs
|
||||
*
|
||||
* @return true if schema is null type
|
||||
*/
|
||||
public static boolean isUnsupportedSchema(OpenAPI openAPI, Schema schema) {
|
||||
|
@ -497,9 +497,22 @@ public class ModelUtilsTest {
|
||||
|
||||
schema = openAPI.getComponents().getSchemas().get("AnyOfTest");
|
||||
assertFalse(ModelUtils.isNullTypeSchema(openAPI, schema));
|
||||
// first element (getAnyOf().get(0)) is a string. no need to test
|
||||
assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(1)));
|
||||
assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(2)));
|
||||
assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(3)));
|
||||
|
||||
schema = openAPI.getComponents().getSchemas().get("OneOfRef");
|
||||
assertFalse(ModelUtils.isNullTypeSchema(openAPI, schema));
|
||||
assertFalse(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getOneOf().get(0)));
|
||||
|
||||
schema = openAPI.getComponents().getSchemas().get("OneOfMultiRef");
|
||||
assertFalse(ModelUtils.isNullTypeSchema(openAPI, schema));
|
||||
assertFalse(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getOneOf().get(0)));
|
||||
assertFalse(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getOneOf().get(1)));
|
||||
|
||||
schema = openAPI.getComponents().getSchemas().get("JustDescription");
|
||||
assertFalse(ModelUtils.isNullTypeSchema(openAPI, schema));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -58,7 +58,7 @@ components:
|
||||
$ref: '#/components/schemas/IntegerRef'
|
||||
number:
|
||||
anyOf:
|
||||
- $ref: '#/components/schemas/Number'
|
||||
- $ref: '#/components/schemas/StringRef'
|
||||
AnyOfStringArrayOfString:
|
||||
anyOf:
|
||||
- type: string
|
||||
@ -85,6 +85,8 @@ components:
|
||||
- $ref: '#/components/schemas/IntegerRef'
|
||||
IntegerRef:
|
||||
type: integer
|
||||
StringRef:
|
||||
type: string
|
||||
OneOfAnyType:
|
||||
oneOf:
|
||||
- type: object
|
||||
@ -94,3 +96,12 @@ components:
|
||||
- type: integer
|
||||
- type: array
|
||||
items: {}
|
||||
OneOfRef:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/IntegerRef'
|
||||
OneOfMultiRef:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/IntegerRef'
|
||||
- $ref: '#/components/schemas/StringRef'
|
||||
JustDescription:
|
||||
Description: A schema with just description
|
||||
|
Loading…
x
Reference in New Issue
Block a user