Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit bb8c81f

Browse files
committed
#86, merge object properties & allOf properties
1 parent 674b1b8 commit bb8c81f

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

src/main/kotlin/io/openapiprocessor/core/converter/DataTypeConverter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ class DataTypeConverter(
277277
OffsetDateTimeDataType (constraints, schemaInfo.getDeprecated(),
278278
Documentation(description = schemaInfo.description))
279279
else ->
280-
throw UnknownDataTypeException(schemaInfo.getName(), schemaInfo.getType(),
281-
schemaInfo.getFormat())
280+
throw UnknownDataTypeException(
281+
schemaInfo.getName(), schemaInfo.getType(), schemaInfo.getFormat())
282282
}
283283
}
284284

src/main/kotlin/io/openapiprocessor/core/converter/SchemaInfo.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import io.openapiprocessor.core.support.capitalizeFirstChar
1515
* Helper for [DataTypeConverter]. Holds an OpenAPI schema with context information, e.g. name and
1616
* if this is an inline type with a generated name.
1717
*/
18-
class SchemaInfo(
18+
open class SchemaInfo(
1919
/**
2020
* Endpoint path.
2121
*/
@@ -79,8 +79,8 @@ class SchemaInfo(
7979
*
8080
* @return schema type
8181
*/
82-
override fun getType(): String {
83-
return schema?.getType()!!
82+
override fun getType(): String? {
83+
return schema?.getType()
8484
}
8585

8686
/**
@@ -238,6 +238,15 @@ class SchemaInfo(
238238
* iterate over composed items
239239
*/
240240
fun eachItemOf(action: (info: SchemaInfo) -> Unit) {
241+
if (schema?.getProperties()?.isNotEmpty() == true) {
242+
action(SchemaInfoAllOf(
243+
endpoint = endpoint,
244+
name = "${name}_${itemOf()!!.capitalizeFirstChar()}",
245+
schema = schema,
246+
resolver = resolver
247+
))
248+
}
249+
241250
schema?.getItems()?.forEachIndexed { index, schema ->
242251
action(SchemaInfo(
243252
endpoint = endpoint,
@@ -316,15 +325,15 @@ class SchemaInfo(
316325
}
317326

318327
override fun isArray(): Boolean {
319-
return schema?.getType().equals("array")
328+
return getType().equals("array")
320329
}
321330

322331
fun isObject(): Boolean {
323-
return schema?.getType().equals("object")
332+
return getType().equals("object")
324333
}
325334

326335
fun isComposedObject(): Boolean {
327-
return schema?.getType().equals("composed")
336+
return getType().equals("composed")
328337
}
329338

330339
fun isComposedAllOf(): Boolean {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2022 https://github.com/openapi-processor/openapi-processor-core
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.core.converter
7+
8+
import io.openapiprocessor.core.parser.RefResolver
9+
import io.openapiprocessor.core.parser.Schema
10+
11+
class SchemaInfoAllOf(
12+
endpoint: Endpoint,
13+
name: String,
14+
contentType: String = "",
15+
schema: Schema?,
16+
resolver: RefResolver
17+
) : SchemaInfo(endpoint, name, contentType, schema, resolver) {
18+
19+
override fun getType(): String {
20+
return "object"
21+
}
22+
23+
}

src/main/kotlin/io/openapiprocessor/core/converter/mapping/MappingSchema.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface MappingSchema {
1818
fun getName(): String
1919
fun getContentType(): String
2020

21-
fun getType(): String
21+
fun getType(): String?
2222
fun getFormat(): String?
2323

2424
fun isPrimitive(): Boolean

src/main/kotlin/io/openapiprocessor/core/converter/mapping/UnknownDataTypeException.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import java.lang.RuntimeException
2525
*/
2626
class UnknownDataTypeException(
2727
val name: String?,
28-
val type: String,
28+
val type: String?,
2929
var format: String?
3030
): RuntimeException() {
3131

src/testInt/groovy/io/openapiprocessor/core/TestSets.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class TestSets {
5252
'schema-composed',
5353
'schema-composed-allof',
5454
'schema-composed-allof-notype',
55+
'schema-composed-allof-properties',
5556
'schema-composed-nested'
5657
]
5758

0 commit comments

Comments
 (0)