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

Commit 1009957

Browse files
committed
#55, use http method to find mapping
1 parent f46d8b7 commit 1009957

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ApiConverter(
7373
}
7474

7575
private fun createInterface(path: String, operation: Operation, interfaces: MutableMap<String, Interface>): Interface {
76-
val targetInterfaceName = getInterfaceName(operation, isExcluded(path))
76+
val targetInterfaceName = getInterfaceName(operation, isExcluded(path, operation.getMethod()))
7777

7878
var itf = interfaces[targetInterfaceName]
7979
if (itf != null) {
@@ -112,7 +112,7 @@ class ApiConverter(
112112
ep.parameters.add (createParameter (ep, parameter, dataTypes, resolver))
113113
}
114114

115-
val addMappings = mappingFinder.findEndpointAddParameterTypeMappings (ep.path)
115+
val addMappings = mappingFinder.findEndpointAddParameterTypeMappings (ep.path, ep.method)
116116
addMappings.forEach {
117117
ep.parameters.add (createAdditionalParameter (it, dataTypes, resolver))
118118
}
@@ -329,8 +329,8 @@ class ApiConverter(
329329
return toClass(path) + "Response" + httpStatus
330330
}
331331

332-
private fun isExcluded(path: String): Boolean {
333-
return mappingFinder.isExcludedEndpoint(path)
332+
private fun isExcluded(path: String, method: HttpMethod): Boolean {
333+
return mappingFinder.isExcludedEndpoint(path, method)
334334
}
335335

336336
private fun getInterfaceName(op: Operation, excluded: Boolean): String {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ class SchemaInfo(
4848
return endpoint.path
4949
}
5050

51+
override fun getMethod(): HttpMethod {
52+
return endpoint.method
53+
}
54+
5155
override fun getName(): String {
5256
return name
5357
}

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

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

88
import io.openapiprocessor.core.converter.SchemaInfo
99
import io.openapiprocessor.core.converter.mapping.matcher.*
10+
import io.openapiprocessor.core.model.HttpMethod
1011

1112
/**
1213
* find mappings of a given schema info in the type mapping list.
@@ -21,7 +22,7 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
2122
* @throws AmbiguousTypeMappingException if there is more than one match.
2223
*/
2324
fun findEndpointTypeMapping(info: SchemaInfo): TypeMapping? {
24-
val ep = filterMappings(EndpointTypeMatcher(info.getPath()), typeMappings)
25+
val ep = filterMappings(EndpointTypeMatcher(info.getPath(), info.getMethod()), typeMappings)
2526

2627
val parameter = getTypeMapping(filterMappings(ParameterTypeMatcher(info), ep))
2728
if (parameter != null)
@@ -71,8 +72,8 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
7172
* @return the matching mapping or null if there is no match.
7273
* @throws AmbiguousTypeMappingException if there is more than one match.
7374
*/
74-
fun findEndpointAddParameterTypeMappings(path: String): List<AddParameterTypeMapping> {
75-
return filterMappings(EndpointTypeMatcher(path), typeMappings)
75+
fun findEndpointAddParameterTypeMappings(path: String, method: HttpMethod): List<AddParameterTypeMapping> {
76+
return filterMappings(EndpointTypeMatcher(path, method), typeMappings)
7677
.filterIsInstance<AddParameterTypeMapping>()
7778
}
7879

@@ -83,7 +84,7 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
8384
* @return the "result" type mappings or null if there is no match.
8485
*/
8586
fun findEndpointResultTypeMapping(info: SchemaInfo): ResultTypeMapping? {
86-
val ep = filterMappings(EndpointTypeMatcher(info.getPath()), typeMappings)
87+
val ep = filterMappings(EndpointTypeMatcher(info.getPath(), info.getMethod()), typeMappings)
8788

8889
val matches = filterMappings({ _: ResultTypeMapping -> true }, ep)
8990
if (matches.isEmpty())
@@ -112,7 +113,7 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
112113
* @return the "single" type mappings or null if there is no match.
113114
*/
114115
fun findEndpointSingleTypeMapping(info: SchemaInfo): TypeMapping? {
115-
val ep = filterMappings(EndpointTypeMatcher(info.getPath()), typeMappings)
116+
val ep = filterMappings(EndpointTypeMatcher(info.getPath(), info.getMethod()), typeMappings)
116117

117118
val matches = filterMappings(SingleTypeMatcher(), ep)
118119
if (matches.isEmpty())
@@ -141,7 +142,7 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
141142
* @return the "multi" type mappings or null if there is no match.
142143
*/
143144
fun findEndpointMultiTypeMapping(info: SchemaInfo): TypeMapping? {
144-
val ep = filterMappings(EndpointTypeMatcher(info.getPath()), typeMappings)
145+
val ep = filterMappings(EndpointTypeMatcher(info.getPath(), info.getMethod()), typeMappings)
145146

146147
val matches = filterMappings(MultiTypeMatcher(), ep)
147148
if (matches.isEmpty())
@@ -169,10 +170,10 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
169170
* @param path the endpoint path
170171
* @return true/false
171172
*/
172-
fun isExcludedEndpoint(path: String): Boolean {
173+
fun isExcludedEndpoint(path: String, method: HttpMethod): Boolean {
173174
val ep = typeMappings
174175
.filterIsInstance<EndpointTypeMapping>()
175-
.filter(EndpointTypeMatcher(path))
176+
.filter(EndpointTypeMatcher(path, method))
176177

177178
if (ep.isEmpty())
178179
return false
@@ -189,7 +190,7 @@ class MappingFinder(private val typeMappings: List<Mapping> = emptyList()) {
189190
* @return the "null" type mappings or null if there is no match.
190191
*/
191192
fun findEndpointNullTypeMapping(info: SchemaInfo): NullTypeMapping? {
192-
val ep = filterMappings(EndpointTypeMatcher(info.getPath()), typeMappings)
193+
val ep = filterMappings(EndpointTypeMatcher(info.getPath(), info.getMethod()), typeMappings)
193194

194195
val matches = filterMappings(NullTypeMatcher(), ep)
195196
if (matches.isEmpty())

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55

66
package io.openapiprocessor.core.converter.mapping
77

8+
import io.openapiprocessor.core.model.HttpMethod
9+
810
/**
911
* Provides the properties required to check if a [Mapping] applies to a
1012
* [io.openapiprocessor.core.converter.SchemaInfo].
1113
*/
1214
interface MappingSchema {
1315

1416
fun getPath(): String
17+
fun getMethod(): HttpMethod
1518
fun getName(): String
1619
fun getContentType(): String
1720

src/main/kotlin/io/openapiprocessor/core/converter/mapping/matcher/EndpointTypeMatcher.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
package io.openapiprocessor.core.converter.mapping.matcher
77

88
import io.openapiprocessor.core.converter.mapping.EndpointTypeMapping
9+
import io.openapiprocessor.core.model.HttpMethod
910

1011
/**
1112
* [io.openapiprocessor.core.converter.mapping.MappingFinder] matcher for endpoint type mappings.
1213
*/
13-
class EndpointTypeMatcher(private val path: String): (EndpointTypeMapping) -> Boolean {
14+
class EndpointTypeMatcher(private val path: String, private val method: HttpMethod)
15+
: (EndpointTypeMapping) -> Boolean {
1416

1517
override fun invoke(m: EndpointTypeMapping): Boolean {
16-
return m.path == path
18+
return m.path == path && (m.method == null || m.method == method)
1719
}
1820

1921
}

0 commit comments

Comments
 (0)