use of io.swagger.v3.oas.models.OpenAPI 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.oas.models.OpenAPI in project cxf by apache.
the class OpenApiCustomizer method customize.
public void customize(final OpenAPI oas) {
if (replaceTags || javadocProvider != null) {
Map<String, ClassResourceInfo> operations = new HashMap<>();
Map<Pair<String, String>, OperationResourceInfo> methods = new HashMap<>();
cris.forEach(cri -> {
cri.getMethodDispatcher().getOperationResourceInfos().forEach(ori -> {
String normalizedPath = getNormalizedPath(cri.getURITemplate().getValue(), ori.getURITemplate().getValue());
operations.put(normalizedPath, cri);
methods.put(Pair.of(ori.getHttpMethod(), normalizedPath), ori);
});
});
List<Tag> tags = new ArrayList<>();
oas.getPaths().forEach((pathKey, pathItem) -> {
Tag tag = null;
if (replaceTags && operations.containsKey(pathKey)) {
ClassResourceInfo cri = operations.get(pathKey);
tag = new Tag();
tag.setName(cri.getURITemplate().getValue().replaceAll("/", "_"));
if (javadocProvider != null) {
tag.setDescription(javadocProvider.getClassDoc(cri));
}
if (!tags.contains(tag)) {
tags.add(tag);
}
}
for (Map.Entry<HttpMethod, Operation> subentry : pathItem.readOperationsMap().entrySet()) {
if (replaceTags && tag != null) {
subentry.getValue().setTags(Collections.singletonList(tag.getName()));
}
Pair<String, String> key = Pair.of(subentry.getKey().name(), pathKey);
if (methods.containsKey(key) && javadocProvider != null) {
OperationResourceInfo ori = methods.get(key);
if (StringUtils.isBlank(subentry.getValue().getSummary())) {
subentry.getValue().setSummary(javadocProvider.getMethodDoc(ori));
}
if (subentry.getValue().getParameters() == null) {
List<Parameter> parameters = new ArrayList<>();
addParameters(parameters);
subentry.getValue().setParameters(parameters);
} else {
for (int i = 0; i < subentry.getValue().getParameters().size(); i++) {
if (StringUtils.isBlank(subentry.getValue().getParameters().get(i).getDescription())) {
subentry.getValue().getParameters().get(i).setDescription(javadocProvider.getMethodParameterDoc(ori, i));
}
}
addParameters(subentry.getValue().getParameters());
}
if (subentry.getValue().getResponses() != null && !subentry.getValue().getResponses().isEmpty()) {
ApiResponse response = subentry.getValue().getResponses().entrySet().iterator().next().getValue();
if (StringUtils.isBlank(response.getDescription())) {
response.setDescription(javadocProvider.getMethodResponseDoc(ori));
}
}
}
}
});
if (replaceTags && oas.getTags() != null) {
oas.setTags(tags);
}
}
}
use of io.swagger.v3.oas.models.OpenAPI in project cxf by apache.
the class OpenApiFeature method initialize.
@Override
public void initialize(Server server, Bus bus) {
final JAXRSServiceFactoryBean sfb = (JAXRSServiceFactoryBean) server.getEndpoint().get(JAXRSServiceFactoryBean.class.getName());
final ServerProviderFactory factory = (ServerProviderFactory) server.getEndpoint().get(ServerProviderFactory.class.getName());
final Set<String> packages = new HashSet<>();
if (resourcePackages != null) {
packages.addAll(resourcePackages);
}
Properties swaggerProps = null;
GenericOpenApiContextBuilder<?> openApiConfiguration;
final Application application = getApplicationOrDefault(server, factory, sfb, bus);
if (StringUtils.isEmpty(getConfigLocation())) {
swaggerProps = getSwaggerProperties(propertiesLocation, bus);
if (isScan()) {
packages.addAll(scanResourcePackages(sfb));
}
final OpenAPI oas = new OpenAPI().info(getInfo(swaggerProps));
registerComponents(securityDefinitions).ifPresent(oas::setComponents);
final SwaggerConfiguration config = new SwaggerConfiguration().openAPI(oas).prettyPrint(getOrFallback(isPrettyPrint(), swaggerProps, PRETTY_PRINT_PROPERTY)).readAllResources(isReadAllResources()).ignoredRoutes(getIgnoredRoutes()).filterClass(getOrFallback(getFilterClass(), swaggerProps, FILTER_CLASS_PROPERTY)).resourceClasses(getResourceClasses()).resourcePackages(getOrFallback(packages, swaggerProps, RESOURCE_PACKAGE_PROPERTY));
openApiConfiguration = new JaxrsOpenApiContextBuilder<>().application(application).openApiConfiguration(config);
} else {
openApiConfiguration = new JaxrsOpenApiContextBuilder<>().application(application).configLocation(getConfigLocation());
}
try {
final OpenApiContext context = openApiConfiguration.buildContext(true);
final Properties userProperties = getUserProperties(context.getOpenApiConfiguration().getUserDefinedOptions());
registerOpenApiResources(sfb, packages, context.getOpenApiConfiguration());
registerSwaggerUiResources(sfb, combine(swaggerProps, userProperties), factory, bus);
if (customizer != null) {
customizer.setApplicationInfo(factory.getApplicationProvider());
}
} catch (OpenApiConfigurationException ex) {
throw new RuntimeException("Unable to initialize OpenAPI context", ex);
}
}
use of io.swagger.v3.oas.models.OpenAPI in project gravitee-management-rest-api by gravitee-io.
the class SwaggerServiceImpl method transformV3.
private OpenAPI transformV3(String content, PageConfigurationEntity config) {
SwaggerParseResult result = new OpenAPIV3Parser().readContents(content, null, null);
if (result != null && config != null && config.getTryItURL() != null) {
URI newURI = URI.create(config.getTryItURL());
result.getOpenAPI().getServers().forEach(server -> {
try {
server.setUrl(new URI(newURI.getScheme(), newURI.getUserInfo(), newURI.getHost(), newURI.getPort(), newURI.getPath(), newURI.getQuery(), newURI.getFragment()).toString());
} catch (URISyntaxException e) {
logger.error(e.getMessage(), e);
}
});
}
if (result != null) {
return result.getOpenAPI();
} else {
return null;
}
}
use of io.swagger.v3.oas.models.OpenAPI in project vertx-web by vert-x3.
the class OpenAPI3RouterFactoryImpl method resolveOperationId.
private String resolveOperationId(HttpMethod method, String path) {
// I assume the user give path in openapi style
PathItem pathObject = this.spec.getPaths().get(path);
if (pathObject == null) {
throw RouterFactoryException.createPathNotFoundException(path);
}
Operation operation;
switch(method) {
case GET:
operation = pathObject.getGet();
break;
case PUT:
operation = pathObject.getPut();
break;
case HEAD:
operation = pathObject.getHead();
break;
case DELETE:
operation = pathObject.getDelete();
break;
case PATCH:
operation = pathObject.getPatch();
break;
case POST:
operation = pathObject.getPost();
break;
case OPTIONS:
operation = pathObject.getOptions();
break;
case TRACE:
operation = pathObject.getTrace();
break;
case OTHER:
case CONNECT:
default:
throw RouterFactoryException.createPathNotFoundException(path);
}
return operation.getOperationId();
}
Aggregations