Skip to content

Commit

Permalink
Enable use of oneOf in additional properties (#117)
Browse files Browse the repository at this point in the history
* Enable use of oneOf in additional properties

* comment out test debug line
  • Loading branch information
cjbooms authored Mar 7, 2022
1 parent b977caa commit bdbb2a3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/main/kotlin/com/cjbooms/fabrikt/model/OasType.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.cjbooms.fabrikt.model

import com.cjbooms.fabrikt.util.KaizenParserExtensions.isEnumDefinition
import com.cjbooms.fabrikt.util.KaizenParserExtensions.isSimpleMapDefinition
import com.cjbooms.fabrikt.util.KaizenParserExtensions.isSimpleOneOfAnyDefinition
import com.cjbooms.fabrikt.util.KaizenParserExtensions.isMapTypeAdditionalProperties
import com.cjbooms.fabrikt.util.KaizenParserExtensions.isSchemaLess
import com.cjbooms.fabrikt.util.KaizenParserExtensions.isSimpleMapDefinition
import com.cjbooms.fabrikt.util.KaizenParserExtensions.isSimpleOneOfAnyDefinition
import com.cjbooms.fabrikt.util.KaizenParserExtensions.isTypedAdditionalProperties
import com.cjbooms.fabrikt.util.KaizenParserExtensions.isUnknownAdditionalProperties
import com.cjbooms.fabrikt.util.KaizenParserExtensions.isUntypedAdditionalProperties
Expand Down Expand Up @@ -72,10 +72,10 @@ sealed class OasType(
isEnumDefinition() -> Specialization.ENUM
isMapTypeAdditionalProperties(oasKey) -> Specialization.TYPED_MAP_ADDITIONAL_PROPERTIES
isSimpleMapDefinition() -> Specialization.MAP
isSimpleOneOfAnyDefinition() -> Specialization.ONE_OF_ANY
isTypedAdditionalProperties(oasKey) -> Specialization.TYPED_OBJECT_ADDITIONAL_PROPERTIES
isUntypedAdditionalProperties(oasKey) -> Specialization.UNTYPED_OBJECT_ADDITIONAL_PROPERTIES
isUnknownAdditionalProperties(oasKey) -> Specialization.UNKNOWN_ADDITIONAL_PROPERTIES
isSimpleOneOfAnyDefinition() -> Specialization.ONE_OF_ANY
isSchemaLess() -> Specialization.UNTYPED_OBJECT
else -> Specialization.NONE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class ModelGeneratorTest {
MutableSettings.updateSettings(setOf(CodeGenerationType.HTTP_MODELS), emptySet(), emptySet(), emptySet())
}

// @Test
// fun `debug single test`() = `correct models are generated for different OpenApi Specifications`("insert test case")

@ParameterizedTest
@MethodSource("testCases")
fun `correct models are generated for different OpenApi Specifications`(testCaseName: String) {
Expand Down
12 changes: 11 additions & 1 deletion src/test/resources/examples/anyOfOneOfAllOf/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,14 @@ components:
$ref: '#/components/schemas/AnyValue'

AnyValue:
description: Tests support for https://swagger.io/docs/specification/data-models/data-types/#any
description: Tests support for https://swagger.io/docs/specification/data-models/data-types/#any

OneOfAdditionalProps:
type: object
properties:
second_nested_any_of_prop:
type: string
additionalProperties:
oneOf:
- $ref: '#/components/schemas/FirstOneB'
- $ref: '#/components/schemas/SecondOneB'
22 changes: 22 additions & 0 deletions src/test/resources/examples/anyOfOneOfAllOf/models/Models.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package examples.anyOfOneOfAllOf.models

import com.fasterxml.jackson.annotation.JsonAnyGetter
import com.fasterxml.jackson.annotation.JsonAnySetter
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonProperty
import java.math.BigDecimal
import kotlin.Any
import kotlin.String
import kotlin.collections.Map
import kotlin.collections.MutableMap

data class ComplexParent(
@param:JsonProperty("oneOf")
Expand Down Expand Up @@ -59,6 +64,23 @@ data class MoreNesting(
val moreNestedPropOne: String? = null
)

data class OneOfAdditionalProps(
@param:JsonProperty("second_nested_any_of_prop")
@get:JsonProperty("second_nested_any_of_prop")
val secondNestedAnyOfProp: String? = null
) {
@get:JsonIgnore
val properties: MutableMap<String, Any> = mutableMapOf()

@JsonAnyGetter
fun get(): Map<String, Any> = properties

@JsonAnySetter
fun set(name: String, value: Any) {
properties[name] = value
}
}

data class SecondAnyA(
@param:JsonProperty("second_nested_any_of_prop")
@get:JsonProperty("second_nested_any_of_prop")
Expand Down

0 comments on commit bdbb2a3

Please sign in to comment.