From a7a3e27875af8c4e2ebdd58735de94490b29b1b2 Mon Sep 17 00:00:00 2001 From: Joel Jonsson Date: Thu, 21 Jun 2018 10:06:19 +0200 Subject: [PATCH] Handle resolving specs without any definitions --- .../swagger/inflector/utils/ResolverUtil.java | 6 ++--- .../swagger/test/utils/ResolverUtilTest.java | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/swagger/inflector/utils/ResolverUtil.java b/src/main/java/io/swagger/inflector/utils/ResolverUtil.java index f72650c2..538055fa 100644 --- a/src/main/java/io/swagger/inflector/utils/ResolverUtil.java +++ b/src/main/java/io/swagger/inflector/utils/ResolverUtil.java @@ -42,9 +42,9 @@ public Map getResolvedModels() { public void resolveFully(Swagger swagger) { if (swagger.getDefinitions() != null) { schemas = swagger.getDefinitions(); - if (schemas == null) { - schemas = new HashMap<>(); - } + } + if (schemas == null) { + schemas = new HashMap<>(); } for (String name : schemas.keySet()) { diff --git a/src/test/java/io/swagger/test/utils/ResolverUtilTest.java b/src/test/java/io/swagger/test/utils/ResolverUtilTest.java index a534d7cb..bd9aaa9b 100644 --- a/src/test/java/io/swagger/test/utils/ResolverUtilTest.java +++ b/src/test/java/io/swagger/test/utils/ResolverUtilTest.java @@ -267,4 +267,26 @@ public void testSelfReferenceResolution() { fail("Recursive loop found"); } } + + + @Test + public void testResolvingWithoutDefinitions() { + String yaml = + "swagger: '2.0'\n" + + "info:\n" + + " version: '1.0'\n" + + " title: No definition example\n" + + "\n" + + "paths:\n" + + " /:\n" + + " get:\n" + + " produces:\n" + + " - application/json\n" + + " responses:\n" + + " 200:\n" + + " description: completed successfully\n"; + + Swagger swagger = new SwaggerParser().parse(yaml); + new ResolverUtil().resolveFully(swagger); + } }