Skip to content

Commit

Permalink
Issue 223 (#224)
Browse files Browse the repository at this point in the history
Relax validation such that schemas that make use of allOf oneOf or anyOf may be declared as type object.
  • Loading branch information
cjbooms authored Jul 18, 2023
1 parent d9d52ff commit a45f785
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/com/cjbooms/fabrikt/model/SourceApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ data class SourceApi(
val schemaErrors = api.schemas.entries.fold(emptyList<ValidationError>()) { errors, entry ->
val name = entry.key
val schema = entry.value
if (schema.type == OasType.Object.type && (
if (schema.type == OasType.Object.type && schema.properties?.isNotEmpty() == true && (
schema.oneOfSchemas?.isNotEmpty() == true ||
schema.allOfSchemas?.isNotEmpty() == true ||
schema.anyOfSchemas?.isNotEmpty() == true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ object KaizenParserExtensions {

fun Schema.toMapValueClassName() = safeName().toMapValueClassName()

fun Schema.isSchemaLess() = isObjectType() && properties?.isEmpty() == true
fun Schema.isSchemaLess() = isObjectType() && properties?.isEmpty() == true && (
oneOfSchemas?.isNotEmpty() != true &&
allOfSchemas?.isNotEmpty() != true &&
anyOfSchemas?.isNotEmpty() != true
)

fun Schema.isSimpleMapDefinition() = hasAdditionalProperties() && properties?.isEmpty() == true

Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/examples/anyOfOneOfAllOf/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ components:
type: integer

ComplexParent:
required:
- top_level_prop
type: object
allOf:
- $ref: '#/components/schemas/ContainsNestedOneOf'
- $ref: '#/components/schemas/ContainsNestedAnyOf'
Expand Down

0 comments on commit a45f785

Please sign in to comment.