use of org.eclipse.microprofile.openapi.OASModelReader in project wildfly-swarm by wildfly-swarm.
the class OpenApiServletContextListener method modelFromReader.
/**
* Instantiate the configured {@link OASModelReader} and invoke it. If no reader is configured, then return null. If a class is configured but there is an
* error either instantiating or invokig it, a {@link RuntimeException} is thrown.
*/
private OpenAPIImpl modelFromReader() {
String readerClassName = config.getOptionalValue(OASConfig.MODEL_READER, String.class).orElse(null);
if (readerClassName == null) {
return null;
}
try {
ClassLoader cl = getContextClassLoader();
if (cl == null) {
cl = OpenApiServletContextListener.class.getClassLoader();
}
Class<?> c = cl.loadClass(readerClassName);
OASModelReader reader = (OASModelReader) c.newInstance();
return (OpenAPIImpl) reader.buildModel();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
Aggregations