Search in sources :

Example 1 with Message

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();
}
Also used : ProcessingMessage(com.github.fge.jsonschema.core.report.ProcessingMessage) Message(io.swagger.report.Message) ProcessingMessage(com.github.fge.jsonschema.core.report.ProcessingMessage) Severity(io.swagger.report.Severity) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with Message

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;
}
Also used : Message(io.swagger.report.Message) Parameter(io.swagger.models.apideclaration.Parameter)

Example 3 with Message

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;
}
Also used : ApiDeclaration(io.swagger.models.apideclaration.ApiDeclaration) SwaggerReaderFactory(io.swagger.reader.SwaggerReaderFactory) ApiDeclarationJsonValidator(io.swagger.validate.ApiDeclarationJsonValidator) MessageBuilder(io.swagger.report.MessageBuilder) Message(io.swagger.report.Message) ApiDeclarationDeserializer(io.swagger.deserializer.ApiDeclarationDeserializer) SwaggerReaderConfiguration(io.swagger.reader.SwaggerReaderConfiguration) ApiDeclarationMigrator(io.swagger.transform.migrate.ApiDeclarationMigrator) JsonNode(com.fasterxml.jackson.databind.JsonNode) URISyntaxException(java.net.URISyntaxException) SwaggerReader(io.swagger.reader.SwaggerReader)

Example 4 with Message

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;
}
Also used : Message(io.swagger.report.Message) InputStream(java.io.InputStream) HttpClient(io.swagger.io.HttpClient) JsonNode(com.fasterxml.jackson.databind.JsonNode) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 5 with Message

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;
}
Also used : Message(io.swagger.report.Message) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Api(io.swagger.models.apideclaration.Api) Operation(io.swagger.models.apideclaration.Operation) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Message (io.swagger.report.Message)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Api (io.swagger.models.apideclaration.Api)2 ApiDeclaration (io.swagger.models.apideclaration.ApiDeclaration)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ProcessingMessage (com.github.fge.jsonschema.core.report.ProcessingMessage)1 ApiDeclarationDeserializer (io.swagger.deserializer.ApiDeclarationDeserializer)1 HttpClient (io.swagger.io.HttpClient)1 AuthorizationScope (io.swagger.models.AuthorizationScope)1 Model (io.swagger.models.apideclaration.Model)1 Operation (io.swagger.models.apideclaration.Operation)1 Parameter (io.swagger.models.apideclaration.Parameter)1 SwaggerReader (io.swagger.reader.SwaggerReader)1 SwaggerReaderConfiguration (io.swagger.reader.SwaggerReaderConfiguration)1 SwaggerReaderFactory (io.swagger.reader.SwaggerReaderFactory)1