io.swagger.models.reader.ApiDeclarationParser Maven / Gradle / Ivy
package io.swagger.models.reader;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import io.swagger.models.apideclaration.Api;
import io.swagger.models.apideclaration.ApiDeclaration;
import io.swagger.models.apideclaration.Model;
import io.swagger.models.apideclaration.ModelProperty;
import io.swagger.models.apideclaration.Operation;
import io.swagger.models.apideclaration.Parameter;
import io.swagger.report.Message;
import io.swagger.report.MessageBuilder;
import io.swagger.report.Severity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ApiDeclarationParser extends SwaggerParser {
public ApiDeclaration read(String json, MessageBuilder messages) {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.setSerializationInclusion(Include.NON_NULL);
try {
Map m = mapper.readValue(json, Map.class);
ApiDeclaration api = new ApiDeclaration();
String apiVersion = readString(m.get("apiVersion"));
if (apiVersion != null) {
api.setApiVersion(apiVersion);
} else {
messages.append(new Message("ApiDeclaration.apiVersion", "apiVersion is missing", Severity.RECOMMENDED));
}
String swaggerVersion = readString(m.get("swaggerVersion"));
if (swaggerVersion != null) {
api.setSwaggerVersion(swaggerVersion);
} else {
messages.append(new Message("ApiDeclaration.swaggerVersion", "swaggerVersion is missing", Severity.ERROR));
}
String basePath = readString(m.get("basePath"));
if (basePath != null) {
api.setBasePath(basePath);
} else {
messages.append(new Message("ApiDeclaration.basePath", "basePath is missing", Severity.ERROR));
}
String resourcePath = readString(m.get("resourcePath"));
if (resourcePath != null) {
api.setResourcePath(resourcePath);
} else {
messages.append(new Message("ApiDeclaration.resourcePath", "resourcePath is missing", Severity.ERROR));
}
String produces = readString(m.get("produces"));
Object apis = m.get("apis");
if (apis != null) {
List o = readApis((List