forked from loafle/openapi-generator-original
Compare commits
5 Commits
master
...
fix-oneof-
Author | SHA1 | Date | |
---|---|---|---|
|
66f8d15e75 | ||
|
b2e51982c0 | ||
|
01584fed76 | ||
|
19f307d6cd | ||
|
754207a636 |
@ -430,7 +430,7 @@ public class ModelUtils {
|
|||||||
* <p>
|
* <p>
|
||||||
* For example, an OpenAPI schema is considered an ObjectSchema in the following scenarios:
|
* For example, an OpenAPI schema is considered an ObjectSchema in the following scenarios:
|
||||||
* <p>
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* type: object
|
* type: object
|
||||||
* additionalProperties: false
|
* additionalProperties: false
|
||||||
* properties:
|
* properties:
|
||||||
@ -534,17 +534,17 @@ public class ModelUtils {
|
|||||||
* <p>
|
* <p>
|
||||||
* For example, an OpenAPI schema is considered a MapSchema in the following scenarios:
|
* For example, an OpenAPI schema is considered a MapSchema in the following scenarios:
|
||||||
* <p>
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* type: object
|
* type: object
|
||||||
* additionalProperties: true
|
* additionalProperties: true
|
||||||
*
|
* <p>
|
||||||
* type: object
|
* type: object
|
||||||
* additionalProperties:
|
* additionalProperties:
|
||||||
* type: object
|
* type: object
|
||||||
* properties:
|
* properties:
|
||||||
* code:
|
* code:
|
||||||
* type: integer
|
* type: integer
|
||||||
*
|
* <p>
|
||||||
* allOf:
|
* allOf:
|
||||||
* - $ref: '#/components/schemas/Class1'
|
* - $ref: '#/components/schemas/Class1'
|
||||||
* - $ref: '#/components/schemas/Class2'
|
* - $ref: '#/components/schemas/Class2'
|
||||||
@ -1935,7 +1935,7 @@ public class ModelUtils {
|
|||||||
private static void logWarnMessagesForIneffectiveValidations(Set<String> setValidations, Schema schema, Set<String> effectiveValidations) {
|
private static void logWarnMessagesForIneffectiveValidations(Set<String> setValidations, Schema schema, Set<String> effectiveValidations) {
|
||||||
setValidations.removeAll(effectiveValidations);
|
setValidations.removeAll(effectiveValidations);
|
||||||
setValidations.stream().forEach(validation -> {
|
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 schema Schema
|
||||||
* @param openAPI OpenAPI
|
* @param openAPI OpenAPI
|
||||||
*
|
|
||||||
* @return true if schema is null type
|
* @return true if schema is null type
|
||||||
*/
|
*/
|
||||||
public static boolean isNullTypeSchema(OpenAPI openAPI, Schema schema) {
|
public static boolean isNullTypeSchema(OpenAPI openAPI, Schema schema) {
|
||||||
@ -2260,11 +2259,14 @@ public class ModelUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// for `type: null`
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
} else { // 3.0.x or 2.x spec
|
} 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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2279,7 +2281,6 @@ public class ModelUtils {
|
|||||||
*
|
*
|
||||||
* @param schema Schema
|
* @param schema Schema
|
||||||
* @param openAPI OpenAPIs
|
* @param openAPI OpenAPIs
|
||||||
*
|
|
||||||
* @return true if schema is null type
|
* @return true if schema is null type
|
||||||
*/
|
*/
|
||||||
public static boolean isUnsupportedSchema(OpenAPI openAPI, Schema schema) {
|
public static boolean isUnsupportedSchema(OpenAPI openAPI, Schema schema) {
|
||||||
|
@ -497,9 +497,22 @@ public class ModelUtilsTest {
|
|||||||
|
|
||||||
schema = openAPI.getComponents().getSchemas().get("AnyOfTest");
|
schema = openAPI.getComponents().getSchemas().get("AnyOfTest");
|
||||||
assertFalse(ModelUtils.isNullTypeSchema(openAPI, schema));
|
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(1)));
|
||||||
assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(2)));
|
assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(2)));
|
||||||
assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(3)));
|
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
|
@Test
|
||||||
|
@ -58,7 +58,7 @@ components:
|
|||||||
$ref: '#/components/schemas/IntegerRef'
|
$ref: '#/components/schemas/IntegerRef'
|
||||||
number:
|
number:
|
||||||
anyOf:
|
anyOf:
|
||||||
- $ref: '#/components/schemas/Number'
|
- $ref: '#/components/schemas/StringRef'
|
||||||
AnyOfStringArrayOfString:
|
AnyOfStringArrayOfString:
|
||||||
anyOf:
|
anyOf:
|
||||||
- type: string
|
- type: string
|
||||||
@ -85,6 +85,8 @@ components:
|
|||||||
- $ref: '#/components/schemas/IntegerRef'
|
- $ref: '#/components/schemas/IntegerRef'
|
||||||
IntegerRef:
|
IntegerRef:
|
||||||
type: integer
|
type: integer
|
||||||
|
StringRef:
|
||||||
|
type: string
|
||||||
OneOfAnyType:
|
OneOfAnyType:
|
||||||
oneOf:
|
oneOf:
|
||||||
- type: object
|
- type: object
|
||||||
@ -94,3 +96,12 @@ components:
|
|||||||
- type: integer
|
- type: integer
|
||||||
- type: array
|
- type: array
|
||||||
items: {}
|
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