use of io.swagger.report.Message 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;
}
}
use of io.swagger.report.Message in project swagger-parser by swagger-api.
the class SwaggerParser method readAuthorizationScopes.
protected List<AuthorizationScope> readAuthorizationScopes(List<Map<String, Object>> map, MessageBuilder messages) {
List<AuthorizationScope> authorizationScopes = new ArrayList<>();
for (Map<String, Object> object : map) {
AuthorizationScope authorizationScope = new AuthorizationScope();
Object scope = object.get("scope");
if (scope != null) {
authorizationScope.setScope(scope.toString());
} else {
messages.append(new Message("AuthorizationScopes.scopes.scope", "missing required scope", Severity.ERROR));
}
Object description = object.get("description");
if (description != null) {
authorizationScope.setDescription(description.toString());
} else {
messages.append(new Message("AuthorizationScopes.scopes.description", "missing description", Severity.RECOMMENDED));
}
authorizationScopes.add(authorizationScope);
}
return authorizationScopes;
}
Aggregations