use of io.gravitee.rest.api.service.exceptions.SwaggerDescriptorException in project gravitee-management-rest-api by gravitee-io.
the class SwaggerServiceImpl method createAPI.
@Override
public SwaggerApiEntity createAPI(ImportSwaggerDescriptorEntity swaggerDescriptor, DefinitionVersion definitionVersion) {
ParseOptions options = new ParseOptions();
// In the context of an import, we need to fully resolve $ref which are required for OAIDescriptorVisitors (ie. policies).
options.setResolveFully(true);
boolean wsdlImport = Format.WSDL.equals(swaggerDescriptor.getFormat());
SwaggerDescriptor descriptor = parse(swaggerDescriptor.getPayload(), wsdlImport, options);
if (wsdlImport) {
overridePayload(swaggerDescriptor, descriptor);
populateXmlToJsonPolicy(swaggerDescriptor);
}
if (descriptor != null) {
if (definitionVersion.equals(DefinitionVersion.V2)) {
return new OAIToAPIV2Converter(swaggerDescriptor, policyOperationVisitorManager, groupService, tagService).convert((OAIDescriptor) descriptor);
} else {
return new OAIToAPIConverter(swaggerDescriptor, policyOperationVisitorManager, groupService, tagService).convert((OAIDescriptor) descriptor);
}
}
throw new SwaggerDescriptorException();
}
use of io.gravitee.rest.api.service.exceptions.SwaggerDescriptorException in project gravitee-management-rest-api by gravitee-io.
the class OAIParser method parse.
public OAIDescriptor parse(String content, ParseOptions options) {
OpenAPIParser parser = new OpenAPIParser();
SwaggerParseResult parseResult;
String path = content;
File temp = null;
if (!isLocationUrl(content)) {
// Swagger v1 supports only a URL to read swagger: create temporary file for Swagger parser
temp = createTempFile(content);
path = temp.getAbsolutePath();
}
parseResult = parser.readLocation(path, null, options);
if (temp != null) {
temp.delete();
}
/* Hack due to swagger v1 converting issue
* See https://github.com/swagger-api/swagger-parser/issues/1451
*/
if (parseResult.getMessages() != null) {
final List<String> filteredMessages = parseResult.getMessages().stream().filter(message -> message != null && !message.matches("^attribute info.contact.*")).collect(Collectors.toList());
parseResult.setMessages(filteredMessages);
}
if (parseResult.getOpenAPI() == null) {
throw new SwaggerDescriptorException("Malformed descriptor");
}
OAIDescriptor descriptor = new OAIDescriptor(parseResult.getOpenAPI());
descriptor.setMessages(parseResult.getMessages());
return descriptor;
}
use of io.gravitee.rest.api.service.exceptions.SwaggerDescriptorException in project gravitee-management-rest-api by gravitee-io.
the class SwaggerServiceImpl method parse.
public SwaggerDescriptor parse(String content, boolean wsdl, ParseOptions options) {
OpenAPI descriptor;
if (isUrl(content)) {
UrlSanitizerUtils.checkAllowed(content, importConfiguration.getImportWhitelist(), importConfiguration.isAllowImportFromPrivate());
}
if (wsdl) {
// try to read wsdl
logger.debug("Trying to load a Wsdl descriptor");
descriptor = new WsdlParser().parse(content);
if (descriptor != null) {
return new OAIDescriptor(descriptor);
}
} else {
OAIDescriptor oaiDescriptor = new OAIParser().parse(content, options);
if (oaiDescriptor == null || oaiDescriptor.getSpecification() == null) {
throw new SwaggerDescriptorException();
}
return oaiDescriptor;
}
throw new SwaggerDescriptorException();
}
Aggregations