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

Commit 4f15a45

Browse files
committed
id/type split (result wrapper), #65
1 parent 3aea93b commit 4f15a45

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed
Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,33 @@
11
/*
2-
* Copyright 2020 the original authors
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
2+
* Copyright 2020 https://github.com/openapi-processor/openapi-processor-core
3+
* PDX-License-Identifier: Apache-2.0
154
*/
165

176
package io.openapiprocessor.core.model.datatypes
187

198
/**
209
* Result data type wrapper. Assumes a single generic parameter.
21-
*
22-
* @author Martin Hauner
2310
*/
2411
class ResultDataType(
25-
26-
private val type: String,
12+
private val name: String,
2713
private val pkg: String,
2814
private val dataType: DataType
29-
3015
): DataType {
3116

32-
// todo multi check inside?
3317
override fun getName(): String {
34-
return "$type<${dataType.getName()}>"
18+
return "$name<${dataType.getName()}>"
19+
}
20+
21+
override fun getTypeName(): String {
22+
return "$name<${dataType.getTypeName()}>"
3523
}
3624

3725
override fun getPackageName(): String {
3826
return pkg
3927
}
4028

4129
override fun getImports(): Set<String> {
42-
return setOf("${getPackageName()}.$type") + dataType.getImports()
30+
return setOf("${getPackageName()}.$name") + dataType.getImports()
4331
}
4432

4533
/**
@@ -48,11 +36,11 @@ class ResultDataType(
4836
* @return type with ? as the generic parameter
4937
*/
5038
fun getNameMulti(): String {
51-
return "$type<?>"
39+
return "$name<?>"
5240
}
5341

5442
fun getImportsMulti(): Set<String> {
55-
return setOf("${getPackageName()}.$type")
43+
return setOf("${getPackageName()}.$name")
5644
}
5745

5846
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2021 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+
import io.kotest.core.spec.style.StringSpec
9+
import io.kotest.data.blocking.forAll
10+
import io.kotest.data.row
11+
import io.kotest.matchers.shouldBe
12+
13+
class ResultDataTypeSpec : StringSpec({
14+
15+
"uses id name and type name of item" {
16+
val ndt = ResultDataType("Result", "wrap",
17+
ObjectDataType(DataTypeName("Foo", "FooX"), "pkg", linkedMapOf())
18+
)
19+
20+
ndt.getName() shouldBe "Result<Foo>"
21+
ndt.getTypeName() shouldBe "Result<FooX>"
22+
}
23+
24+
"should create import with type name" {
25+
forAll(row("Foo", "Foo"), row("Fooo", "FoooX")) { id, type ->
26+
val ndt = ResultDataType("Result", "wrap",
27+
ObjectDataType(DataTypeName(id, type), "pkg")
28+
)
29+
ndt.getImports() shouldBe setOf(
30+
"wrap.Result",
31+
"pkg.$type"
32+
)
33+
}
34+
}
35+
36+
})

0 commit comments

Comments
 (0)