use of io.swagger.report.Message in project swagger-parser by swagger-api.
the class SwaggerJsonValidator method fillMessages.
private static boolean fillMessages(final ProcessingReport report, final MessageBuilder builder) {
final Severity severity = LEVEL_MAP.get(report.getLogLevel());
final ArrayNode node = JacksonUtils.nodeFactory().arrayNode();
for (final ProcessingMessage processingMessage : report) {
node.add(processingMessage.asJson());
}
final String reportAsString = JacksonUtils.prettyPrint(node);
final Message message = new Message("", reportAsString, severity);
builder.append(message);
return report.isSuccess();
}
use of io.swagger.report.Message in project swagger-parser by swagger-api.
the class ApiDeclarationParser method readParameter.
Parameter readParameter(Map<String, Object> o, MessageBuilder messages) {
Parameter param = new Parameter();
String name = readString(o.get("name"));
if (name != null) {
param.setName(name);
} else {
messages.append(new Message("ApiDeclaration.apis.operations.parameters.name", "missing name", Severity.ERROR));
}
String description = readString(o.get("description"));
param.setDescription(description);
Boolean required = readBoolean(o.get("required"));
param.setRequired(required);
String type = readString(o.get("type"));
param.setType(type);
Boolean allowMultiple = readBoolean(o.get("allowMultiple"));
param.setAllowMultiple(allowMultiple);
return param;
}
use of io.swagger.report.Message in project swagger-parser by swagger-api.
the class SwaggerLegacyParser method read.
public ApiDeclaration read(String url, String resourcePath, Authentication authentication) {
MessageBuilder messageBuilder = new MessageBuilder();
SwaggerReader swaggerReader = new SwaggerReaderFactory(new SwaggerReaderConfiguration()).newReader();
JsonNode jsonNode = null;
try {
String resourceListingURL = getResourceListingURL(url, resourcePath);
jsonNode = swaggerReader.read(resourceListingURL, authentication, messageBuilder);
} catch (URISyntaxException e) {
messageBuilder.append(new Message("", e.getMessage(), Severity.ERROR));
}
validateMessageReport(messageBuilder);
ApiDeclarationMigrator apiDeclarationMigrator = new ApiDeclarationMigrator();
jsonNode = apiDeclarationMigrator.migrate(messageBuilder, jsonNode);
validateMessageReport(messageBuilder);
ApiDeclarationJsonValidator apiDeclarationJsonValidator = new ApiDeclarationJsonValidator();
apiDeclarationJsonValidator.validate(messageBuilder, jsonNode);
validateMessageReport(messageBuilder);
ApiDeclarationDeserializer apiDeclarationDeserializer = new ApiDeclarationDeserializer();
ApiDeclaration apiDeclaration = apiDeclarationDeserializer.deserialize(jsonNode, messageBuilder);
validateMessageReport(messageBuilder);
return apiDeclaration;
}
use of io.swagger.report.Message in project swagger-parser by swagger-api.
the class SimpleSwaggerReader method read.
@Override
public JsonNode read(final String url, final Authentication authentication, MessageBuilder messageBuilder) {
HttpClient httpClient = new io.swagger.io.HttpClient(url);
JsonNode jsonNode = null;
authentication.apply(httpClient);
try {
InputStream swaggerJson = httpClient.execute();
jsonNode = objectMapper.readTree(swaggerJson);
} catch (URISyntaxException | IOException e) {
messageBuilder.append(new Message("", e.getMessage(), Severity.ERROR));
}
httpClient.close();
return jsonNode;
}
use of io.swagger.report.Message in project swagger-parser by swagger-api.
the class ApiDeclarationParser method readApis.
List<Api> readApis(List<Map<String, Object>> om, MessageBuilder messages) {
List<Api> output = new ArrayList<Api>();
for (Map<String, Object> o : om) {
Api op = new Api();
String path = readString(o.get("path"));
if (path != null) {
op.setPath(path);
} else {
messages.append(new Message("ApiDeclaration.apis", "path is missing", Severity.ERROR));
}
Object operations = o.get("operations");
if (operations instanceof List) {
List<Operation> ops = readOperations((List<Map<String, Object>>) operations, messages);
op.setOperations(ops);
}
output.add(op);
}
return output;
}
Aggregations