use of io.swagger.v3.parser.core.models.ParseOptions in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method loadSwagger.
private OpenAPI loadSwagger(String filename) throws IOException {
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveCombinators(false);
options.setResolveFully(true);
return new OpenAPIV3Parser().readContents(String.join("\n", Files.readAllLines(Paths.get(filename), StandardCharsets.UTF_8)), null, options).getOpenAPI();
}
use of io.swagger.v3.parser.core.models.ParseOptions in project vertx-web by vert-x3.
the class OpenApi3Utils method getParseOptions.
public static ParseOptions getParseOptions() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveCombinators(false);
options.setResolveFully(true);
return options;
}
use of io.swagger.v3.parser.core.models.ParseOptions in project hippo by NHS-digital-website.
the class SwaggerCodeGenOpenApiSpecificationJsonToHtmlConverter method openApiModelFrom.
private OpenAPI openApiModelFrom(final String openApiSpecificationJson) {
final ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true);
final SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readContents(openApiSpecificationJson, null, parseOptions);
Optional.ofNullable(swaggerParseResult.getMessages()).orElse(Collections.emptyList()).forEach(log::warn);
return swaggerParseResult.getOpenAPI();
}
use of io.swagger.v3.parser.core.models.ParseOptions in project carbon-apimgt by wso2.
the class SchemaValidator method getOpenAPIValidator.
/**
* Method to generate OpenApiInteractionValidator when the swagger is provided.
*
* @param swagger Swagger definition.
* @return OpenApiInteractionValidator object for the provided swagger.
*/
private static OpenApiInteractionValidator getOpenAPIValidator(String swagger) {
OpenAPIParser openAPIParser = new OpenAPIParser();
ParseOptions options = new ParseOptions();
options.setResolveFully(true);
SwaggerParseResult swaggerParseResult = openAPIParser.readContents(swagger, new ArrayList<>(), options);
OpenAPI openAPI = swaggerParseResult.getOpenAPI();
return OpenApiInteractionValidator.createFor(openAPI).withLevelResolver(LevelResolver.create().withLevel("validation.schema.required", ValidationReport.Level.INFO).withLevel("validation.response.body.missing", ValidationReport.Level.INFO).build()).build();
}
use of io.swagger.v3.parser.core.models.ParseOptions in project carbon-apimgt by wso2.
the class OAS3Parser method validateAPIDefinition.
/**
* This method validates the given OpenAPI definition by content
*
* @param apiDefinition OpenAPI Definition content
* @param host OpenAPI Definition url
* @param returnJsonContent whether to return the converted json form of the OpenAPI definition
* @return APIDefinitionValidationResponse object with validation information
*/
@Override
public APIDefinitionValidationResponse validateAPIDefinition(String apiDefinition, String host, boolean returnJsonContent) throws APIManagementException {
APIDefinitionValidationResponse validationResponse = new APIDefinitionValidationResponse();
OpenAPIV3Parser openAPIV3Parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult parseAttemptForV3 = openAPIV3Parser.readContents(apiDefinition, null, options);
if (CollectionUtils.isNotEmpty(parseAttemptForV3.getMessages())) {
validationResponse.setValid(false);
for (String message : parseAttemptForV3.getMessages()) {
OASParserUtil.addErrorToValidationResponse(validationResponse, message);
if (message.contains(APIConstants.OPENAPI_IS_MISSING_MSG)) {
ErrorItem errorItem = new ErrorItem();
errorItem.setErrorCode(ExceptionCodes.INVALID_OAS3_FOUND.getErrorCode());
errorItem.setMessage(ExceptionCodes.INVALID_OAS3_FOUND.getErrorMessage());
errorItem.setDescription(ExceptionCodes.INVALID_OAS3_FOUND.getErrorMessage());
validationResponse.getErrorItems().add(errorItem);
}
}
} else {
OpenAPI openAPI = parseAttemptForV3.getOpenAPI();
io.swagger.v3.oas.models.info.Info info = openAPI.getInfo();
List<String> endpoints;
String endpointWithHost = "";
if (openAPI.getServers() == null || openAPI.getServers().isEmpty()) {
endpoints = null;
} else {
endpoints = openAPI.getServers().stream().map(url -> url.getUrl()).collect(Collectors.toList());
for (String endpoint : endpoints) {
if (endpoint.startsWith("/")) {
if (StringUtils.isEmpty(host)) {
endpointWithHost = "http://api.yourdomain.com" + endpoint;
} else {
endpointWithHost = host + endpoint;
}
endpoints.set(endpoints.indexOf(endpoint), endpointWithHost);
}
}
}
String title = null;
String context = null;
if (!StringUtils.isBlank(info.getTitle())) {
title = info.getTitle();
context = info.getTitle().replaceAll("\\s", "").toLowerCase();
}
OASParserUtil.updateValidationResponseAsSuccess(validationResponse, apiDefinition, openAPI.getOpenapi(), title, info.getVersion(), context, info.getDescription(), endpoints);
validationResponse.setParser(this);
if (returnJsonContent) {
if (!apiDefinition.trim().startsWith("{")) {
// not a json (it is yaml)
JsonNode jsonNode = DeserializationUtils.readYamlTree(apiDefinition);
validationResponse.setJsonContent(jsonNode.toString());
} else {
validationResponse.setJsonContent(apiDefinition);
}
}
}
return validationResponse;
}
Aggregations