Java Code Examples for io.swagger.v3.parser.core.models.SwaggerParseResult#ofError()

The following examples show how to use io.swagger.v3.parser.core.models.SwaggerParseResult#ofError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenAPIV3Parser.java    From swagger-parser with Apache License 2.0 6 votes vote down vote up
private SwaggerParseResult readContents(String swaggerAsString, List<AuthorizationValue> auth, ParseOptions options,
                                        String location) {
    if (swaggerAsString == null || swaggerAsString.trim().isEmpty()) {
        return SwaggerParseResult.ofError("Null or empty definition");
    }

    try {
        final ObjectMapper mapper = getRightMapper(swaggerAsString);
        final JsonNode rootNode = mapper.readTree(swaggerAsString);
        final SwaggerParseResult result = parseJsonNode(location, rootNode);
        return resolve(result, auth, options, location);
    } catch (JsonProcessingException e) {
        LOGGER.warn("Exception while parsing:", e);
        final String message = getParseErrorMessage(e.getOriginalMessage(), location);
        return SwaggerParseResult.ofError(message);
    }
}
 
Example 2
Source File: OpenAPIV3Parser.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Override
public SwaggerParseResult readLocation(String url, List<AuthorizationValue> auth, ParseOptions options) {
    try {
        final String content = readContentFromLocation(url, emptyListIfNull(auth));
        LOGGER.debug("Loaded raw data: {}", content);
        return readContents(content, auth, options, url);
    } catch (ReadContentException e) {
        LOGGER.warn("Exception while reading:", e);
        return SwaggerParseResult.ofError(e.getMessage());
    }
}