ModelUtils: isMap only if additionalProperties is a Schema (#410)

Fix for issue #409
This commit is contained in:
Jérémie Bresson 2018-07-01 07:31:36 +02:00 committed by GitHub
parent 8e648e4d95
commit a02b313b89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 1 deletions

View File

@ -304,7 +304,7 @@ public class ModelUtils {
if (schema instanceof MapSchema) {
return true;
}
if (schema.getAdditionalProperties() != null) {
if (schema.getAdditionalProperties() instanceof Schema) {
return true;
}
return false;

View File

@ -0,0 +1,46 @@
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
* Copyright 2018 SmartBear Software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openapitools.codegen.html;
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 org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.languages.StaticHtmlGenerator;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.Collections;
public class StaticHtmlGeneratorTest {
@Test
public void testAdditionalPropertiesFalse() {
final StaticHtmlGenerator codegen = new StaticHtmlGenerator();
Schema schema = new ObjectSchema()
.additionalProperties(false)
.addProperties("id", new IntegerSchema())
.addProperties("name", new StringSchema());
CodegenModel cm = codegen.fromModel("test", schema, Collections.emptyMap());
Assert.assertNotNull(cm);
}
}