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

Commit 64a9049

Browse files
committed
#55, want http method to find mapping
1 parent 6277fdc commit 64a9049

File tree

8 files changed

+68
-43
lines changed

8 files changed

+68
-43
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class ApiConverter(
109109

110110
private fun collectParameters(parameters: List<Parameter>, ep: Endpoint, dataTypes: DataTypes, resolver: RefResolver) {
111111
parameters.forEach { parameter ->
112-
ep.parameters.add (createParameter (ep.path, parameter, dataTypes, resolver))
112+
ep.parameters.add (createParameter (ep, parameter, dataTypes, resolver))
113113
}
114114

115115
val addMappings = mappingFinder.findEndpointAddParameterTypeMappings (ep.path)
@@ -125,7 +125,7 @@ class ApiConverter(
125125

126126
requestBody.getContent().forEach { contentType, mediaType ->
127127
val info = SchemaInfo(
128-
ep.path,
128+
SchemaInfo.Endpoint(ep.path, ep.method),
129129
getInlineRequestBodyName (ep.path),
130130
"",
131131
mediaType.getSchema(),
@@ -142,7 +142,7 @@ class ApiConverter(
142142
private fun collectResponses(responses: Map<String, Response>, ep: Endpoint, dataTypes: DataTypes, resolver: RefResolver) {
143143
responses.forEach { httpStatus, httpResponse ->
144144
val results = createResponses(
145-
ep.path,
145+
ep,
146146
httpStatus,
147147
httpResponse,
148148
dataTypes,
@@ -152,9 +152,9 @@ class ApiConverter(
152152
}
153153
}
154154

155-
private fun createParameter(path: String, parameter: Parameter, dataTypes: DataTypes, resolver: RefResolver): ModelParameter {
155+
private fun createParameter(ep: Endpoint, parameter: Parameter, dataTypes: DataTypes, resolver: RefResolver): ModelParameter {
156156
val info = SchemaInfo (
157-
path,
157+
SchemaInfo.Endpoint(ep.path, ep.method),
158158
parameter.getName(),
159159
"",
160160
parameter.getSchema(),
@@ -279,9 +279,11 @@ class ApiConverter(
279279
}
280280
}
281281

282-
private fun createResponses(path: String, httpStatus: String, response: Response, dataTypes: DataTypes, resolver: RefResolver): List<ModelResponse> {
282+
private fun createResponses(ep: Endpoint, httpStatus: String, response: Response, dataTypes: DataTypes, resolver: RefResolver): List<ModelResponse> {
283283
if (response.getContent().isEmpty()) {
284-
val info = SchemaInfo (path, "", "", null, resolver)
284+
val info = SchemaInfo (
285+
SchemaInfo.Endpoint(ep.path, ep.method),
286+
"", "", null, resolver)
285287

286288
val dataType = NoneDataType()
287289
val singleDataType = singleDataTypeWrapper.wrap (dataType, info)
@@ -295,8 +297,8 @@ class ApiConverter(
295297
val schema = mediaType.getSchema()
296298

297299
val info = SchemaInfo (
298-
path,
299-
getInlineResponseName (path, httpStatus),
300+
SchemaInfo.Endpoint(ep.path, ep.method),
301+
getInlineResponseName (ep.path, httpStatus),
300302
contentType,
301303
schema,
302304
resolver)

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.openapiprocessor.core.converter
77

88
import io.openapiprocessor.core.converter.mapping.MappingSchema
9+
import io.openapiprocessor.core.model.HttpMethod
910
import io.openapiprocessor.core.parser.RefResolver as ParserRefResolver
1011
import io.openapiprocessor.core.parser.Schema
1112

@@ -17,7 +18,7 @@ class SchemaInfo(
1718
/**
1819
* Endpoint path.
1920
*/
20-
private val path: String,
21+
private val endpoint: Endpoint,
2122

2223
/**
2324
* name of the type/schema or parameter name.
@@ -41,8 +42,10 @@ class SchemaInfo(
4142

4243
): MappingSchema {
4344

45+
class Endpoint(val path: String, val method: HttpMethod)
46+
4447
override fun getPath(): String {
45-
return path
48+
return endpoint.path
4649
}
4750

4851
override fun getName(): String {
@@ -203,7 +206,7 @@ class SchemaInfo(
203206
fun eachItemOf(action: (info: SchemaInfo) -> Unit) {
204207
schema?.getItems()?.forEachIndexed { index, schema ->
205208
action(SchemaInfo(
206-
path = path,
209+
endpoint = endpoint,
207210
name = "${name}_${itemOf()!!.capitalize()}_${index}",
208211
schema = schema,
209212
resolver = resolver
@@ -225,7 +228,7 @@ class SchemaInfo(
225228
*/
226229
fun buildForRef(): SchemaInfo {
227230
return SchemaInfo(
228-
path = path,
231+
endpoint = endpoint,
229232
name = getRefName(schema!!),
230233
schema = resolver.resolve(schema),
231234
resolver = resolver)
@@ -241,7 +244,7 @@ class SchemaInfo(
241244
*/
242245
private fun buildForNestedType(nestedName: String, nestedSchema: Schema): SchemaInfo {
243246
return SchemaInfo(
244-
path = path,
247+
endpoint = endpoint,
245248
name = getNestedTypeName(nestedName),
246249
schema = nestedSchema,
247250
resolver = resolver)
@@ -260,7 +263,7 @@ class SchemaInfo(
260263
}
261264

262265
return SchemaInfo(
263-
path = path,
266+
endpoint = endpoint,
264267
name = name!!,
265268
schema = schema?.getItem(),
266269
resolver = resolver

src/test/groovy/com/github/hauner/openapi/core/converter/DataTypeConverterDeprecatedSpec.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import io.openapiprocessor.core.framework.Framework
2727
import io.openapiprocessor.core.framework.FrameworkBase
2828
import io.openapiprocessor.core.model.DataTypes
2929
import com.github.hauner.openapi.core.test.TestSchema
30+
import io.openapiprocessor.core.model.HttpMethod
3031
import io.openapiprocessor.core.parser.RefResolver
3132
import spock.lang.Specification
3233
import spock.lang.Unroll
@@ -43,7 +44,9 @@ class DataTypeConverterDeprecatedSpec extends Specification {
4344
4445
when:
4546
def datatype = converter.convert (
46-
new SchemaInfo ("", "", "", schema, Stub(RefResolver)),
47+
new SchemaInfo (
48+
new SchemaInfo.Endpoint ("", HttpMethod.GET),
49+
"", "", schema, Stub(RefResolver)),
4750
new DataTypes())
4851
4952
then:

src/test/groovy/com/github/hauner/openapi/core/converter/DataTypeConverterSpec.groovy

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import io.openapiprocessor.core.framework.Framework
2525
import io.openapiprocessor.core.model.Api
2626
import io.openapiprocessor.core.model.DataTypes
2727
import io.openapiprocessor.core.converter.ApiOptions
28+
import io.openapiprocessor.core.model.HttpMethod
2829
import io.openapiprocessor.core.model.datatypes.ObjectDataType
2930
import com.github.hauner.openapi.core.test.TestSchema
3031
import io.openapiprocessor.core.converter.mapping.UnknownDataTypeException
@@ -45,7 +46,9 @@ class DataTypeConverterSpec extends Specification {
4546
4647
when:
4748
def datatype = converter.convert (
48-
new SchemaInfo ("", javaType, "", schema, Stub(RefResolver)),
49+
new SchemaInfo (
50+
new SchemaInfo.Endpoint("", HttpMethod.GET),
51+
javaType, "", schema, Stub(RefResolver)),
4952
new DataTypes())
5053
5154
then:
@@ -71,7 +74,9 @@ class DataTypeConverterSpec extends Specification {
7174
7275
when:
7376
def datatype = converter.convert (
74-
new SchemaInfo ("", javaType, "", schema, Stub(RefResolver)),
77+
new SchemaInfo (
78+
new SchemaInfo.Endpoint("", HttpMethod.GET),
79+
javaType, "", schema, Stub(RefResolver)),
7580
new DataTypes())
7681
7782
then:
@@ -94,7 +99,9 @@ class DataTypeConverterSpec extends Specification {
9499
def schema = new TestSchema (type: type, format: format)
95100
96101
when:
97-
converter.convert (new SchemaInfo ("", "", "", schema, Stub (RefResolver)),
102+
converter.convert (new SchemaInfo (
103+
new SchemaInfo.Endpoint("", HttpMethod.GET),
104+
"", "", schema, Stub (RefResolver)),
98105
new DataTypes())
99106
100107
then:
@@ -127,10 +134,12 @@ class DataTypeConverterSpec extends Specification {
127134
128135
when:
129136
converter.convert (
130-
new SchemaInfo ("", 'Bar', "", barSchema, Stub(RefResolver)),
137+
new SchemaInfo (new SchemaInfo.Endpoint ("", HttpMethod.GET),
138+
'Bar', "", barSchema, Stub(RefResolver)),
131139
dt)
132140
converter.convert (
133-
new SchemaInfo ("", 'Foo', "", fooSchema, resolver),
141+
new SchemaInfo (new SchemaInfo.Endpoint ("", HttpMethod.GET),
142+
'Foo', "", fooSchema, resolver),
134143
dt)
135144
136145
then:

src/test/kotlin/io/openapiprocessor/core/converter/DataTypeConverterPrimitiveSpec.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import io.mockk.every
1414
import io.mockk.mockk
1515
import io.openapiprocessor.core.converter.mapping.MappingFinder
1616
import io.openapiprocessor.core.model.DataTypes
17+
import io.openapiprocessor.core.model.HttpMethod
1718
import io.openapiprocessor.core.parser.RefResolver
1819
import io.openapiprocessor.core.parser.Schema
1920

2021
class DataTypeConverterPrimitiveSpec: StringSpec({
2122
isolationMode = IsolationMode.InstancePerTest
2223

24+
val any = SchemaInfo.Endpoint("/any", HttpMethod.GET)
2325
val converter = DataTypeConverter(ApiOptions(), MappingFinder())
2426
val resolver = mockk<RefResolver>()
2527

@@ -36,7 +38,7 @@ class DataTypeConverterPrimitiveSpec: StringSpec({
3638
every { schema.getFormat() } returns format
3739

3840
// when:
39-
val info = SchemaInfo("", "foo", schema = schema, resolver = resolver)
41+
val info = SchemaInfo(any, "foo", schema = schema, resolver = resolver)
4042
val datatype = converter.convert(info, DataTypes())
4143

4244
// then:

src/test/kotlin/io/openapiprocessor/core/converter/mapping/MappingFinderSpec.kt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ import io.kotest.matchers.nulls.shouldNotBeNull
1212
import io.kotest.matchers.shouldBe
1313
import io.mockk.mockk
1414
import io.openapiprocessor.core.converter.SchemaInfo
15+
import io.openapiprocessor.core.model.HttpMethod
1516
import io.openapiprocessor.core.parser.RefResolver
1617

1718
class MappingFinderSpec: StringSpec({
1819
val resolver = mockk<RefResolver>()
20+
val any = SchemaInfo.Endpoint("/any", HttpMethod.GET)
21+
val foo = SchemaInfo.Endpoint("/foo", HttpMethod.GET)
1922

2023
"no type mapping in empty mappings" {
2124
val finder = MappingFinder(emptyList())
2225

23-
val info = SchemaInfo("/any", "Any", "", null, resolver)
26+
val info = SchemaInfo(any, "Any", "", null, resolver)
2427
val result = finder.findTypeMapping(info)
2528

2629
result.shouldBeNull()
@@ -35,7 +38,7 @@ class MappingFinderSpec: StringSpec({
3538
)
3639
)
3740

38-
val info = SchemaInfo("/any", "Foo", "", null, resolver)
41+
val info = SchemaInfo(any, "Foo", "", null, resolver)
3942
val result = finder.findTypeMapping(info)
4043

4144
result.shouldNotBeNull()
@@ -51,7 +54,7 @@ class MappingFinderSpec: StringSpec({
5154
)
5255
)
5356

54-
val info = SchemaInfo("/any", "Foo", "", null, resolver)
57+
val info = SchemaInfo(any, "Foo", "", null, resolver)
5558

5659
shouldThrow<AmbiguousTypeMappingException> {
5760
finder.findTypeMapping(info)
@@ -61,11 +64,11 @@ class MappingFinderSpec: StringSpec({
6164
"no io mapping in empty mappings" {
6265
val finder = MappingFinder(emptyList())
6366

64-
val param = SchemaInfo("/any", "parameter", "", null, resolver)
67+
val param = SchemaInfo(any, "parameter", "", null, resolver)
6568
val paramResult = finder.findIoTypeMapping(param)
6669
paramResult.shouldBeNull()
6770

68-
val response = SchemaInfo("/any", "", "application/json", null, resolver)
71+
val response = SchemaInfo(any, "", "application/json", null, resolver)
6972
val responseResult = finder.findIoTypeMapping(response)
7073
responseResult.shouldBeNull()
7174
}
@@ -82,7 +85,7 @@ class MappingFinderSpec: StringSpec({
8285
)
8386
)
8487

85-
val info = SchemaInfo("/any", "far param", "", null, resolver)
88+
val info = SchemaInfo(any, "far param", "", null, resolver)
8689
val result = finder.findIoTypeMapping(info)
8790

8891
result.shouldNotBeNull()
@@ -102,7 +105,7 @@ class MappingFinderSpec: StringSpec({
102105
)
103106
)
104107

105-
val info = SchemaInfo("/any", "", "application/json",null, resolver)
108+
val info = SchemaInfo(any, "", "application/json",null, resolver)
106109
val result = finder.findIoTypeMapping(info)
107110

108111
result.shouldNotBeNull()
@@ -120,7 +123,7 @@ class MappingFinderSpec: StringSpec({
120123
)
121124
)
122125

123-
val info = SchemaInfo("/any", "foo param", "", null, resolver)
126+
val info = SchemaInfo(any, "foo param", "", null, resolver)
124127

125128
shouldThrow<AmbiguousTypeMappingException> {
126129
finder.findIoTypeMapping(info)
@@ -137,7 +140,7 @@ class MappingFinderSpec: StringSpec({
137140
)
138141
)
139142

140-
val info = SchemaInfo("/any", "", "application/json", null, resolver)
143+
val info = SchemaInfo(any, "", "application/json", null, resolver)
141144

142145
shouldThrow<AmbiguousTypeMappingException> {
143146
finder.findIoTypeMapping(info)
@@ -147,7 +150,7 @@ class MappingFinderSpec: StringSpec({
147150
"no endpoint type mapping in empty mappings" {
148151
val finder = MappingFinder(emptyList())
149152

150-
val info = SchemaInfo("/foo", "Foo", "", null, resolver)
153+
val info = SchemaInfo(foo, "Foo", "", null, resolver)
151154
val result = finder.findEndpointTypeMapping(info)
152155

153156
result.shouldBeNull()
@@ -166,7 +169,7 @@ class MappingFinderSpec: StringSpec({
166169
)))
167170
)
168171

169-
val info = SchemaInfo("/foo", "far param", "", null, resolver)
172+
val info = SchemaInfo(foo, "far param", "", null, resolver)
170173
val result = finder.findEndpointTypeMapping(info)
171174

172175
result.shouldNotBeNull()
@@ -187,7 +190,7 @@ class MappingFinderSpec: StringSpec({
187190
)))
188191
)
189192

190-
val info = SchemaInfo("/foo", "", "application/json",null, resolver)
193+
val info = SchemaInfo(foo, "", "application/json",null, resolver)
191194
val result = finder.findEndpointTypeMapping(info)
192195

193196
result.shouldNotBeNull()
@@ -205,7 +208,7 @@ class MappingFinderSpec: StringSpec({
205208
)))
206209
)
207210

208-
val info = SchemaInfo("/foo", "foo param", "", null, resolver)
211+
val info = SchemaInfo(foo, "foo param", "", null, resolver)
209212

210213
shouldThrow<AmbiguousTypeMappingException> {
211214
finder.findEndpointTypeMapping(info)
@@ -223,7 +226,7 @@ class MappingFinderSpec: StringSpec({
223226
)))
224227
)
225228

226-
val info = SchemaInfo("/foo", "", "application/json", null, resolver)
229+
val info = SchemaInfo(foo, "", "application/json", null, resolver)
227230

228231
shouldThrow<AmbiguousTypeMappingException> {
229232
finder.findEndpointTypeMapping(info)
@@ -240,7 +243,7 @@ class MappingFinderSpec: StringSpec({
240243
)))
241244
)
242245

243-
val info = SchemaInfo("/foo", "Foo", "", null, resolver)
246+
val info = SchemaInfo(foo, "Foo", "", null, resolver)
244247
val result = finder.findEndpointTypeMapping(info)
245248

246249
result.shouldNotBeNull()
@@ -251,7 +254,7 @@ class MappingFinderSpec: StringSpec({
251254
"no endpoint null mapping in empty mappings" {
252255
val finder = MappingFinder(emptyList())
253256

254-
val info = SchemaInfo("/foo", "", "", null, resolver)
257+
val info = SchemaInfo(foo, "", "", null, resolver)
255258
val result = finder.findEndpointNullTypeMapping(info)
256259

257260
result.shouldBeNull()
@@ -267,7 +270,7 @@ class MappingFinderSpec: StringSpec({
267270
)))
268271
)
269272

270-
val info = SchemaInfo("/foo", "Foo", "", null, resolver)
273+
val info = SchemaInfo(foo, "Foo", "", null, resolver)
271274
val result = finder.findEndpointNullTypeMapping(info)
272275

273276
result.shouldNotBeNull()

0 commit comments

Comments
 (0)