Skip to content

Commit

Permalink
[html] Use ModelUtils to avoid NullPointerException (#1948)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmini authored and wing328 committed Jan 20, 2019
1 parent c163542 commit 0682462
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,4 +46,14 @@ public void testAdditionalPropertiesFalse() {
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");
}

}

0 comments on commit 0682462

Please sign in to comment.