[html] Use ModelUtils to avoid NullPointerException (#1948)

This commit is contained in:
Jérémie Bresson 2019-01-20 17:51:18 +01:00 committed by William Cheng
parent c16354218a
commit 06824622bf
2 changed files with 14 additions and 1 deletions

View File

@ -194,7 +194,7 @@ public class StaticHtmlGenerator extends DefaultCodegen implements CodegenConfig
Info info = openAPI.getInfo();
info.setDescription(toHtml(info.getDescription()));
info.setTitle(toHtml(info.getTitle()));
Map<String, Schema> models = openAPI.getComponents().getSchemas();
Map<String, Schema> models = ModelUtils.getSchemas(openAPI);
for (Schema model : models.values()) {
model.setDescription(toHtml(model.getDescription()));
model.setTitle(toHtml(model.getTitle()));

View File

@ -17,10 +17,13 @@
package org.openapitools.codegen.html;
import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.IntegerSchema;
import io.swagger.v3.oas.models.media.ObjectSchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.parser.core.models.ParseOptions;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.languages.StaticHtmlGenerator;
@ -43,4 +46,14 @@ public class StaticHtmlGeneratorTest {
Assert.assertNotNull(cm);
}
@Test
public void testSpecWithoutSchema() throws Exception {
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/ping.yaml", null, new ParseOptions()).getOpenAPI();
final StaticHtmlGenerator codegen = new StaticHtmlGenerator();
codegen.preprocessOpenAPI(openAPI);
Assert.assertEquals(openAPI.getInfo().getTitle(), "ping test");
}
}