This repository was archived by the owner on Mar 16, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +58
-11
lines changed
groovy/com/github/hauner/openapi/core/processor
kotlin/com/github/hauner/openapi/core/processor/mapping/version
test/groovy/com/github/hauner/openapi/core/processor Expand file tree Collapse file tree 4 files changed +58
-11
lines changed Original file line number Diff line number Diff line change @@ -22,8 +22,6 @@ import com.github.hauner.openapi.core.processor.mapping.Mapping as MappingV1
2222import com.github.hauner.openapi.core.processor.mapping.VersionedMapping
2323import com.github.hauner.openapi.core.processor.mapping.v2.MappingConverter as MappingConverterV2
2424import com.github.hauner.openapi.core.processor.mapping.v2.Mapping as MappingV2
25- import org.slf4j.Logger
26- import org.slf4j.LoggerFactory
2725
2826/**
2927 * Converter for the type mapping from the mapping yaml. It converts the type mapping information
@@ -32,14 +30,12 @@ import org.slf4j.LoggerFactory
3230 * @author Martin Hauner
3331 */
3432class MappingConverter {
35- private static final Logger LOG = LoggerFactory . getLogger (MappingConverter )
3633
3734 List<Mapping > convert (VersionedMapping source ) {
3835 if (source?. isV2()) {
3936 def converter = new MappingConverterV2 ()
4037 converter. convert (source as MappingV2 )
4138 } else {
42- LOG . warn (" current mapping.yaml format is deprecated, upgrade to v2" )
4339 def converter = new MappingConverterV1 ()
4440 converter. convert (source as MappingV1 )
4541 }
Original file line number Diff line number Diff line change @@ -30,12 +30,14 @@ import com.github.hauner.openapi.core.processor.mapping.version.Mapping as Versi
3030import com.github.hauner.openapi.core.processor.mapping.v2.Mapping as MappingV2
3131import com.github.hauner.openapi.core.processor.mapping.v2.Parameter as ParameterV2
3232import com.github.hauner.openapi.core.processor.mapping.v2.ParameterDeserializer as ParameterDeserializerV2
33+ import groovy.util.logging.Slf4j
3334
3435/**
3536 * Reader for mapping yaml.
3637 *
3738 * @author Martin Hauner
3839 */
40+ @Slf4j
3941class MappingReader {
4042
4143 VersionedMapping read (String typeMappings ) {
@@ -54,11 +56,19 @@ class MappingReader {
5456
5557 def versionMapper = createVersionParser ()
5658 VersionMapping version = versionMapper. readValue (mapping, VersionMapping )
59+
60+ if (version. isDeprecatedVersionKey ()) {
61+ log. warn (' the mapping version key "openapi-processor-spring" is deprecated, please use "openapi-processor-mapping"' )
62+ }
63+
5764 if (version. v2) {
5865 def mapper = createV2Parser ()
5966 mapper. readValue (mapping, MappingV2 )
6067 } else {
6168 // assume v1
69+ log. info (' please update the mapping to the latest format' )
70+ log. info (' see https://hauner.github.io/openapi-processor/spring/mapping/structure.html' )
71+
6272 def mapper = createYamlParser ()
6373 mapper. readValue (mapping, Mapping )
6474 }
Original file line number Diff line number Diff line change 1616
1717package com.github.hauner.openapi.core.processor.mapping.version
1818
19- import com.fasterxml.jackson.annotation.JsonAlias
2019import com.fasterxml.jackson.annotation.JsonProperty
2120
2221data class Mapping (
2322 @JsonProperty(" openapi-processor-mapping" )
24- @JsonAlias(" openapi-processor-spring" ) // deprecated
25- val version : String? ) {
23+ val version : String? = null ,
24+
25+ @JsonProperty(" openapi-processor-spring" )
26+ val versionObsolete : String? = null
27+ ) {
2628
2729 fun isV2 (): Boolean {
28- if (version == null ) {
29- return false
30- }
30+ return getSafeVersion().startsWith(" v2" )
31+ }
32+
33+ fun isDeprecatedVersionKey (): Boolean {
34+ return versionObsolete != null
35+ }
36+
37+ private fun getSafeVersion (): String {
38+ if (version != null )
39+ return version
40+
41+ if (versionObsolete != null )
42+ return versionObsolete
3143
32- return version.startsWith( " v2 " )
44+ return " no version"
3345 }
3446
3547}
Original file line number Diff line number Diff line change 1616
1717package com.github.hauner.openapi.core.processor
1818
19+ import com.github.hauner.openapi.core.test.Sl4jMockRule
1920import com.google.common.jimfs.Configuration
2021import com.google.common.jimfs.Jimfs
2122import org.junit.Rule
2223import org.junit.rules.TemporaryFolder
24+ import org.slf4j.Logger
2325import spock.lang.Shared
2426import spock.lang.Specification
2527
@@ -33,6 +35,9 @@ class MappingReaderSpec extends Specification {
3335 @Rule
3436 TemporaryFolder folder
3537
38+ def log = Mock Logger
39+ @Rule Sl4jMockRule rule = new Sl4jMockRule (MappingReader , log)
40+
3641 void " ignores empty type mapping" () {
3742 when :
3843 def reader = new MappingReader ()
@@ -105,4 +110,28 @@ map:
105110 mapping
106111 }
107112
113+ void " warns use of old mapping version key" () {
114+ def yaml = """ \
115+ openapi-processor-spring: v2
116+ """
117+
118+ when :
119+ new MappingReader (). read (yaml)
120+
121+ then :
122+ 1 * log. warn (* _)
123+ }
124+
125+ void " warns use of old mapping format" () {
126+ def yaml = """ \
127+ openapi-processor-mapping: v1
128+ """
129+
130+ when :
131+ new MappingReader (). read (yaml)
132+
133+ then :
134+ 2 * log. info (* _)
135+ }
136+
108137}
You can’t perform that action at this time.
0 commit comments