Skip to content

Commit 9bfb6dd

Browse files
authored
Merge pull request #49 from openapi-processor/allof-type-less
handle type less schemas, resolve #48
2 parents 6a9313b + 734d70e commit 9bfb6dd

File tree

12 files changed

+174
-23
lines changed

12 files changed

+174
-23
lines changed

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/converter/DataTypeConverter.kt

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,7 @@ package io.openapiprocessor.core.converter
1818

1919
import io.openapiprocessor.core.converter.mapping.*
2020
import io.openapiprocessor.core.model.DataTypes
21-
import io.openapiprocessor.core.model.datatypes.ArrayDataType
22-
import io.openapiprocessor.core.model.datatypes.BooleanDataType
23-
import io.openapiprocessor.core.model.datatypes.ComposedObjectDataType
24-
import io.openapiprocessor.core.model.datatypes.DataTypeConstraints
25-
import io.openapiprocessor.core.model.datatypes.LocalDateDataType
26-
import io.openapiprocessor.core.model.datatypes.MappedCollectionDataType
27-
import io.openapiprocessor.core.model.datatypes.MappedDataType
28-
import io.openapiprocessor.core.model.datatypes.MappedMapDataType
29-
import io.openapiprocessor.core.model.datatypes.ObjectDataType
30-
import io.openapiprocessor.core.model.datatypes.DataType
31-
import io.openapiprocessor.core.model.datatypes.DoubleDataType
32-
import io.openapiprocessor.core.model.datatypes.FloatDataType
33-
import io.openapiprocessor.core.model.datatypes.IntegerDataType
34-
import io.openapiprocessor.core.model.datatypes.LongDataType
35-
import io.openapiprocessor.core.model.datatypes.OffsetDateTimeDataType
36-
import io.openapiprocessor.core.model.datatypes.LazyDataType
37-
import io.openapiprocessor.core.model.datatypes.StringDataType
38-
import io.openapiprocessor.core.model.datatypes.StringEnumDataType
21+
import io.openapiprocessor.core.model.datatypes.*
3922
import java.util.*
4023

4124
/**
@@ -79,8 +62,11 @@ class DataTypeConverter(
7962
} else if (schemaInfo.isObject ()) {
8063
result = createObjectDataType (schemaInfo, dataTypes)
8164

65+
} else if (schemaInfo.isTypeLess()) {
66+
result = createNoDataType(schemaInfo, dataTypes)
67+
8268
} else {
83-
result = createSimpleDataType (schemaInfo, dataTypes)
69+
result = createSimpleDataType(schemaInfo, dataTypes)
8470
}
8571

8672
pop()
@@ -255,6 +241,19 @@ class DataTypeConverter(
255241
}
256242
}
257243

244+
private fun createNoDataType(schemaInfo: SchemaInfo, dataTypes: DataTypes): DataType {
245+
val constraints = DataTypeConstraints(
246+
nullable = schemaInfo.getNullable(),
247+
required = schemaInfo.getRequired()
248+
)
249+
250+
return NoDataType(
251+
schemaInfo.getName(),
252+
constraints = constraints,
253+
deprecated = schemaInfo.getDeprecated()
254+
)
255+
}
256+
258257
private fun isSupportedFormat(format: String?): Boolean {
259258
if(format == null)
260259
return false

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/converter/SchemaInfo.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class SchemaInfo(
274274
}
275275

276276
override fun isPrimitive(): Boolean {
277-
return listOf("boolean", "int", "number", "string").contains(schema?.getType())
277+
return listOf("boolean", "integer", "number", "string").contains(schema?.getType())
278278
}
279279

280280
override fun isArray(): Boolean {
@@ -289,6 +289,10 @@ class SchemaInfo(
289289
return schema?.getType().equals("composed")
290290
}
291291

292+
fun isTypeLess(): Boolean {
293+
return schema?.getType() == null
294+
}
295+
292296
fun isRefObject(): Boolean {
293297
return schema?.getRef() != null
294298
}

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/model/datatypes/ComposedObjectDataType.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class ComposedObjectDataType(
4646

4747
override fun getReferencedImports(): Set<String> {
4848
return items
49+
.filterIsInstance<ObjectDataType>()
4950
.map { it.getImports() }
5051
.flatten()
5152
.toSet()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright © 2020 https://github.com/openapi-processor/openapi-processor-core
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.core.model.datatypes
7+
8+
class NoDataType(
9+
10+
private val type: String,
11+
constraints: DataTypeConstraints? = null,
12+
deprecated: Boolean = false
13+
14+
): DataTypeBase(constraints, deprecated) {
15+
16+
override fun getName(): String {
17+
return type
18+
}
19+
20+
override fun getPackageName(): String {
21+
return "io.openapiprocessor.leaked"
22+
}
23+
24+
}
25+
26+

openapi-processor-core/src/testInt/groovy/com/github/hauner/openapi/processor/core/ProcessorPendingTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ import org.junit.runner.RunWith
2525
import org.junit.runners.Parameterized
2626
import spock.lang.Ignore
2727

28-
@Ignore
28+
//@Ignore
2929
@RunWith(Parameterized)
3030
class ProcessorPendingTest extends ProcessorTestBase {
3131

3232
@Parameterized.Parameters(name = "{0}")
3333
static Collection<TestSet> sources () {
3434
return [
35-
new TestSet(name: 'schema-composed-allof', processor: new TestProcessor(), parser: ParserType.SWAGGER),
36-
new TestSet(name: 'schema-composed-allof', processor: new TestProcessor(), parser: ParserType.OPENAPI4J)
35+
new TestSet(name: 'schema-composed-allof-notype', processor: new TestProcessor(), parser: ParserType.SWAGGER),
36+
new TestSet(name: 'schema-composed-allof-notype', processor: new TestProcessor(), parser: ParserType.OPENAPI4J)
3737
]
3838
}
3939

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
items:
2+
- generated/api/Api.java
3+
- generated/model/Foo.java
4+
- generated/model/AllOfNoTypeResponse200.java
5+
- generated/model/AllOfNoTypeResponse200Foo.java
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* This class is auto generated by https://github.com/hauner/openapi-processor-core.
3+
* TEST ONLY.
4+
*/
5+
6+
package generated.api;
7+
8+
import annotation.Mapping;
9+
import generated.model.AllOfNoTypeResponse200;
10+
11+
public interface Api {
12+
13+
@Mapping("/all-of-no-type")
14+
AllOfNoTypeResponse200 getAllOfNoType();
15+
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* This class is auto generated by https://github.com/hauner/openapi-processor-core.
3+
* TEST ONLY.
4+
*/
5+
6+
package generated.model;
7+
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
10+
public class AllOfNoTypeResponse200 {
11+
12+
@JsonProperty("foo")
13+
private AllOfNoTypeResponse200Foo foo;
14+
15+
public AllOfNoTypeResponse200Foo getFoo() {
16+
return foo;
17+
}
18+
19+
public void setFoo(AllOfNoTypeResponse200Foo foo) {
20+
this.foo = foo;
21+
}
22+
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* This class is auto generated by https://github.com/hauner/openapi-processor-core.
3+
* TEST ONLY.
4+
*/
5+
6+
package generated.model;
7+
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
10+
public class AllOfNoTypeResponse200Foo {
11+
12+
@JsonProperty("foo")
13+
private String foo;
14+
15+
public String getFoo() {
16+
return foo;
17+
}
18+
19+
public void setFoo(String foo) {
20+
this.foo = foo;
21+
}
22+
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* This class is auto generated by https://github.com/hauner/openapi-processor-core.
3+
* TEST ONLY.
4+
*/
5+
6+
package generated.model;
7+
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
10+
public class Foo {
11+
12+
@JsonProperty("foo")
13+
private String foo;
14+
15+
public String getFoo() {
16+
return foo;
17+
}
18+
19+
public void setFoo(String foo) {
20+
this.foo = foo;
21+
}
22+
23+
}

0 commit comments

Comments
 (0)