use of io.swagger.models.apideclaration.Model in project swagger-parser by swagger-api.
the class ApiDeclarationParser method readModels.
Map<String, Model> readModels(Map<String, Object> o, MessageBuilder messages) {
Map<String, Model> output = new HashMap<String, Model>();
for (String modelName : o.keySet()) {
Model model = new Model();
Map<String, Object> value = (Map<String, Object>) o.get(modelName);
String id = readString(value.get("id"));
model.setId(id);
String description = readString(value.get("description"));
model.setDescription(description);
String discriminator = readString(value.get("discriminator"));
model.setDiscriminator(discriminator);
Object properties = value.get("properties");
if (properties != null) {
}
output.put(modelName, model);
}
return output;
}
use of io.swagger.models.apideclaration.Model in project swagger-parser by swagger-api.
the class ApiDeclarationParser method read.
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<String, Object> 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<Api> o = readApis((List<Map<String, Object>>) apis, messages);
if (o.size() > 0) {
api.setApis(o);
}
}
Object models = m.get("models");
if (models != null) {
Map<String, Model> modelMap = readModels((Map<String, Object>) models, messages);
api.setModels(modelMap);
}
return api;
} catch (Exception e) {
messages.append(new Message("ApiDeclaration", "invalid json", Severity.ERROR));
return null;
}
}
Aggregations