Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2297,40 +2297,41 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){

//sets default value according to the schema type
if(node.get("default")!= null) {
if(schema.getType().equals("array")) {
ArrayNode array = getArray("default", node, false, location, result);
if (array != null) {
schema.setDefault(array);
}
}else if(schema.getType().equals("string")) {
value = getString("default", node, false, location, result);
if (value != null) {
try {
schema.setDefault( getDecodedObject( schema, value));
if(!StringUtils.isBlank(schema.getType())) {
if (schema.getType().equals("array")) {
ArrayNode array = getArray("default", node, false, location, result);
if (array != null) {
schema.setDefault(array);
}
catch( ParseException e) {
result.invalidType( location, String.format( "default=`%s`", e.getMessage()), schema.getFormat(), node);
} else if (schema.getType().equals("string")) {
value = getString("default", node, false, location, result);
if (value != null) {
try {
schema.setDefault(getDecodedObject(schema, value));
} catch (ParseException e) {
result.invalidType(location, String.format("default=`%s`", e.getMessage()), schema.getFormat(), node);
}
}
} else if (schema.getType().equals("boolean")) {
bool = getBoolean("default", node, false, location, result);
if (bool != null) {
schema.setDefault(bool);
}
} else if (schema.getType().equals("object")) {
Object object = getObject("default", node, false, location, result);
if (object != null) {
schema.setDefault(object);
}
} else if (schema.getType().equals("integer")) {
Integer number = getInteger("default", node, false, location, result);
if (number != null) {
schema.setDefault(number);
}
} else if (schema.getType().equals("number")) {
BigDecimal number = getBigDecimal("default", node, false, location, result);
if (number != null) {
schema.setDefault(number);
}
}
}else if(schema.getType().equals("boolean")) {
bool = getBoolean("default", node, false, location, result);
if (bool != null) {
schema.setDefault(bool);
}
}else if(schema.getType().equals("object")) {
Object object = getObject("default", node, false, location, result);
if (object != null) {
schema.setDefault(object);
}
} else if(schema.getType().equals("integer")) {
Integer number = getInteger("default", node, false, location, result);
if (number != null) {
schema.setDefault(number);
}
} else if(schema.getType().equals("number")) {
BigDecimal number = getBigDecimal("default", node, false, location, result);
if (number != null) {
schema.setDefault(number);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.core.util.Yaml;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
Expand Down Expand Up @@ -64,6 +65,59 @@

public class OpenAPIDeserializerTest {

@Test
public void testIssue1072() throws Exception {
String yaml = "openapi: 3.0.0\n" +
"info:\n" +
" title: Test\n" +
" version: 1.0.0\n" +
"\n" +
"paths:\n" +
" /value:\n" +
" get:\n" +
" operationId: getValues\n" +
" responses:\n" +
" 200:\n" +
" description: Successful response\n" +
" content:\n" +
" application/json:\n" +
" schema:\n" +
" $ref: '#/components/schemas/ComponentA'\n" +
"components:\n" +
" schemas:\n" +
" ComponentA:\n" +
" description: Component A\n" +
" type: object\n" +
" allOf:\n" +
" - type: object\n" +
" properties:\n" +
" attributeWithoutType:\n" +
" allOf:\n" +
" - $ref: '#/components/schemas/ComponentB'\n" +
" default: \"coucou\"\n" +
" attributeWithWrongType:\n" +
" type: object\n" +
" allOf:\n" +
" - $ref: '#/components/schemas/ComponentB'\n" +
" default: \"coucou\"\n" +
" correctAttribute:\n" +
" type: string\n" +
" allOf:\n" +
" - $ref: '#/components/schemas/ComponentB'\n" +
" default: \"coucou\"\n" +
" ComponentB:\n" +
" description: Component B\n" +
" type: string";

OpenAPIV3Parser parser = new OpenAPIV3Parser();

SwaggerParseResult result = parser.readContents(yaml,null,null);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);

}


@Test
public void testEmptyDefinitions() throws Exception {
String yaml = "openapi: 3.0.0\n" +
Expand Down Expand Up @@ -100,8 +154,6 @@ public void testEmptyDefinitions() throws Exception {

assertNotNull(openAPI.getComponents().getSchemas().get("mydefinition"));



}


Expand Down