use of io.gravitee.rest.api.service.swagger.OAIDescriptor in project gravitee-management-rest-api by gravitee-io.
the class SwaggerService_ParseTest method shouldThrowInfoNameMissingWhenFailIfErrorsTrue.
@Test
public void shouldThrowInfoNameMissingWhenFailIfErrorsTrue() throws IOException {
PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/swagger-v2-no-info-name.json", MediaType.APPLICATION_JSON);
OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent());
assertNotNull(descriptor.getMessages());
assertEquals("attribute info.title is missing", descriptor.getMessages().get(0));
}
use of io.gravitee.rest.api.service.swagger.OAIDescriptor in project gravitee-management-rest-api by gravitee-io.
the class EntrypointsOAITransformer method transform.
@Override
public void transform(OAIDescriptor descriptor) {
if (asBoolean(SwaggerProperties.ENTRYPOINTS_AS_SERVERS) && entrypoints != null && !entrypoints.isEmpty()) {
List<Server> servers = new ArrayList<>();
// Add server according to entrypoints
entrypoints.forEach(entrypoint -> {
Server server = new Server();
if (asBoolean(SwaggerProperties.ENTRYPOINT_AS_BASEPATH)) {
server.setUrl(entrypoint.getTarget());
} else {
URI target = URI.create(entrypoint.getTarget());
server.setUrl(entrypoint.getTarget().substring(0, entrypoint.getTarget().indexOf(target.getRawPath())));
}
servers.add(server);
});
descriptor.getSpecification().setServers(servers);
} else if (asBoolean(SwaggerProperties.ENTRYPOINT_AS_BASEPATH) && descriptor.getSpecification().getServers() != null) {
// Replace the server path with the api context-path.
descriptor.getSpecification().getServers().forEach(server -> {
final URI newURI = URI.create(server.getUrl());
try {
server.setUrl(new URI(newURI.getScheme(), newURI.getUserInfo(), newURI.getHost(), newURI.getPort(), this.contextPath, newURI.getQuery(), newURI.getFragment()).toString());
} catch (URISyntaxException e) {
logger.error(e.getMessage(), e);
}
});
}
}
use of io.gravitee.rest.api.service.swagger.OAIDescriptor 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