Skip to content

Commit 024878f

Browse files
committed
fixed handling of empty mapping
1 parent cf46771 commit 024878f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/main/groovy/com/github/hauner/openapi/spring/generatr/MappingConverter.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ class MappingConverter {
4545
List<Mapping> convert (YamlMapping source) {
4646
def result = new ArrayList<Mapping>()
4747

48-
source.map.types.each {
48+
source?.map?.types?.each {
4949
result.add (convertType (it))
5050
}
5151

52-
source.map.parameters.each {
52+
source?.map?.parameters?.each {
5353
result.add (convertParameter (it))
5454
}
5555

56-
source.map.responses.each {
56+
source?.map?.responses?.each {
5757
result.add (convertResponse (it))
5858
}
5959

60-
source.map.paths.each {
60+
source?.map?.paths?.each {
6161
result.add(convertPath (it.key, it.value))
6262
}
6363

src/test/groovy/com/github/hauner/openapi/spring/generatr/MappingConverterSpec.groovy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,15 @@ map:
316316
exclude << [true, false]
317317
}
318318

319+
void "handles empty mapping" () {
320+
String yaml = ""
321+
322+
when:
323+
def mapping = reader.read (yaml)
324+
def mappings = converter.convert (mapping)
325+
326+
then:
327+
mappings.size() == 0
328+
}
329+
319330
}

0 commit comments

Comments
 (0)