Search in sources :

Example 6 with Message

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;
    }
}
Also used : ApiDeclaration(io.swagger.models.apideclaration.ApiDeclaration) Message(io.swagger.report.Message) Model(io.swagger.models.apideclaration.Model) Api(io.swagger.models.apideclaration.Api) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with Message

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;
}
Also used : Message(io.swagger.report.Message) ArrayList(java.util.ArrayList) AuthorizationScope(io.swagger.models.AuthorizationScope)

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