@Override public OpenAPI read(Set<Class<?>> classes, Map<String, Object> resources) { OpenAPI openApi = openApiConfiguration.getOpenAPI(); return openApi; } };
public static boolean isIgnored(String path, OpenAPIConfiguration config) { if (config.getIgnoredRoutes() == null) { return false; } for (String item : config.getIgnoredRoutes()) { final int length = item.length(); if (path.startsWith(item) && (path.length() == length || path.startsWith(PATH_DELIMITER, length))) { return true; } } return false; }
protected OpenApiScanner buildScanner(final OpenAPIConfiguration openApiConfiguration) throws Exception { OpenApiScanner scanner; if (StringUtils.isNotBlank(openApiConfiguration.getScannerClass())) { Class cls = getClass().getClassLoader().loadClass(openApiConfiguration.getScannerClass()); scanner = (OpenApiScanner) cls.newInstance(); } else { scanner = new GenericOpenApiScanner(); } scanner.setConfiguration(openApiConfiguration); return scanner; }
private OpenAPIConfiguration mergeParentConfiguration(OpenAPIConfiguration config, OpenApiContext parent) { if (parent == null || parent.getOpenApiConfiguration() == null) { return config; OpenAPIConfiguration parentConfig = parent.getOpenApiConfiguration(); merged.setResourceClasses(parentConfig.getResourceClasses()); merged.setFilterClass(parentConfig.getFilterClass()); merged.setIgnoredRoutes(parentConfig.getIgnoredRoutes()); merged.setOpenAPI(parentConfig.getOpenAPI()); merged.setReaderClass(parentConfig.getReaderClass()); merged.setResourcePackages(parentConfig.getResourcePackages()); merged.setScannerClass(parentConfig.getScannerClass()); merged.setCacheTTL(parentConfig.getCacheTTL()); merged.setUserDefinedOptions(parentConfig.getUserDefinedOptions()); merged.setPrettyPrint(parentConfig.isPrettyPrint()); merged.setReadAllResources(parentConfig.isReadAllResources()); merged.setObjectMapperProcessorClass(parentConfig.getObjectMapperProcessorClass());
.ctxId(ctxId) .buildContext(true); OpenAPI oas = ctx.read(); boolean pretty = false; if (ctx.getOpenApiConfiguration() != null && Boolean.TRUE.equals(ctx.getOpenApiConfiguration().isPrettyPrint())) { pretty = true; if (ctx.getOpenApiConfiguration() != null && ctx.getOpenApiConfiguration().getFilterClass() != null) { try { OpenAPISpecFilter filterImpl = (OpenAPISpecFilter) Class.forName(ctx.getOpenApiConfiguration().getFilterClass()).newInstance(); SpecFilter f = new SpecFilter(); oas = f.filter(oas, filterImpl, getQueryParams(uriInfo.getQueryParameters()), getCookies(headers),
OpenAPI oas = ctx.read(); if (ctx.getOpenApiConfiguration() != null && Boolean.TRUE.equals(ctx.getOpenApiConfiguration().isPrettyPrint())) { pretty = true;
protected OpenApiReader buildReader(final OpenAPIConfiguration openApiConfiguration) throws Exception { OpenApiReader reader; if (StringUtils.isNotBlank(openApiConfiguration.getReaderClass())) { Class cls = getClass().getClassLoader().loadClass(openApiConfiguration.getReaderClass()); reader = (OpenApiReader) cls.newInstance(); } else { reader = new OpenApiReader() { OpenAPIConfiguration openApiConfiguration; @Override public void setConfiguration(OpenAPIConfiguration openApiConfiguration) { this.openApiConfiguration = openApiConfiguration; } @Override public OpenAPI read(Set<Class<?>> classes, Map<String, Object> resources) { OpenAPI openApi = openApiConfiguration.getOpenAPI(); return openApi; } }; } reader.setConfiguration(openApiConfiguration); return reader; }
@Override public OpenApiContext buildContext(boolean init) throws OpenApiConfigurationException { if (StringUtils.isBlank(ctxId)) { ctxId = OpenApiContext.OPENAPI_CONTEXT_ID_DEFAULT; } OpenApiContext ctx = OpenApiContextLocator.getInstance().getOpenApiContext(ctxId); if (ctx == null) { OpenApiContext rootCtx = OpenApiContextLocator.getInstance().getOpenApiContext(OpenApiContext.OPENAPI_CONTEXT_ID_DEFAULT); ctx = new GenericOpenApiContext() .openApiConfiguration(openApiConfiguration) .id(ctxId) .parent(rootCtx); if (ctx.getConfigLocation() == null && configLocation != null) { ((GenericOpenApiContext) ctx).configLocation(configLocation); } if (((GenericOpenApiContext) ctx).getResourcePackages() == null && resourcePackages != null) { ((GenericOpenApiContext) ctx).resourcePackages(resourcePackages); } if (((GenericOpenApiContext) ctx).getResourceClasses() == null && resourceClasses != null) { ((GenericOpenApiContext) ctx).resourceClasses(resourceClasses); } if (init) { ctx.init(); // includes registering itself with OpenApiContextLocator } } return ctx; }
@Override public OpenAPI read() { if (cacheTTL == 0) { resetReader(); return getOpenApiReader().read(getOpenApiScanner().classes(), getOpenApiScanner().resources()); } Cache cached = cache.get("openapi"); if (cached == null || cached.isStale(cacheTTL)) { cached = new Cache(); cached.createdAt = System.currentTimeMillis(); resetReader(); cached.openApi = getOpenApiReader().read(getOpenApiScanner().classes(), getOpenApiScanner().resources()); cache.put("openapi", cached); } return cached.openApi; }
protected OpenAPIConfiguration loadConfiguration() throws OpenApiConfigurationException { Map<String, OpenApiConfigurationLoader> loaders = getLocationLoaders(); try { if (StringUtils.isNotEmpty(configLocation)) { if (loaders.get("classpath").exists(configLocation)) { return loaders.get("classpath").load(configLocation); } if (loaders.get("file").exists(configLocation)) { return loaders.get("file").load(configLocation); } } // check known locations List<ImmutablePair<String, String>> knownLocations = getKnownLocations(); for (ImmutablePair<String, String> location : knownLocations) { if (loaders.get(location.left).exists(location.right)) { try { return loaders.get(location.left).load(location.right); } catch (IOException ioe) { // try next one } } } return null; } catch (Exception e) { throw new OpenApiConfigurationException(e.getMessage(), e); } }
protected boolean isOperationHidden(Method method) { io.swagger.v3.oas.annotations.Operation apiOperation = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.Operation.class); if (apiOperation != null && apiOperation.hidden()) { return true; } Hidden hidden = method.getAnnotation(Hidden.class); if (hidden != null) { return true; } if (config != null && !Boolean.TRUE.equals(config.isReadAllResources()) && apiOperation == null) { return true; } return false; }
@Override public OpenAPIConfiguration load(String path) throws IOException { ServiceLoader<OpenAPIConfigBuilder> loader = ServiceLoader.load(OpenAPIConfigBuilder.class); if (loader.iterator().hasNext()) { return loader.iterator().next().build(); } throw new IOException("Error loading OpenAPIConfigBuilder service implementation."); }
if (objectMapperProcessor != null) { ObjectMapper mapper = IntegrationObjectMapperFactory.createJson(); objectMapperProcessor.processJsonObjectMapper(mapper); ModelConverters.getInstance().addConverter(new ModelResolver(mapper)); if (openApiConfiguration.getCacheTTL() != null) { this.cacheTTL = openApiConfiguration.getCacheTTL();
protected ObjectMapperProcessor buildObjectMapperProcessor(final OpenAPIConfiguration openApiConfiguration) throws Exception { ObjectMapperProcessor objectMapperProcessor = null; if (StringUtils.isNotBlank(openApiConfiguration.getObjectMapperProcessorClass())) { Class cls = getClass().getClassLoader().loadClass(openApiConfiguration.getObjectMapperProcessorClass()); objectMapperProcessor = (ObjectMapperProcessor) cls.newInstance(); } return objectMapperProcessor; }
protected Set<ModelConverter> buildModelConverters(final OpenAPIConfiguration openApiConfiguration) throws Exception { if (openApiConfiguration.getModelConverterClasses() != null && !openApiConfiguration.getModelConverterClasses().isEmpty()) { LinkedHashSet<ModelConverter> modelConverters = new LinkedHashSet<>(); for (String converterClass: openApiConfiguration.getModelConverterClasses()) { Class cls = getClass().getClassLoader().loadClass(converterClass); ModelConverter converter = (ModelConverter) cls.newInstance(); modelConverters.add(converter); } return modelConverters; } return null; }
@Override public void setConfiguration(OpenAPIConfiguration openApiConfiguration) { if (openApiConfiguration != null) { this.config = ContextUtils.deepCopy(openApiConfiguration); if (openApiConfiguration.getOpenAPI() != null) { this.openAPI = this.config.getOpenAPI(); if (this.openAPI.getComponents() != null) { this.components = this.openAPI.getComponents(); } } } }
@Override protected OpenApiReader buildReader(OpenAPIConfiguration openApiConfiguration) throws Exception { OpenApiReader reader; if (StringUtils.isNotBlank(openApiConfiguration.getReaderClass())) { Class cls = getClass().getClassLoader().loadClass(openApiConfiguration.getReaderClass()); reader = (OpenApiReader) cls.newInstance(); } else { reader = new Reader(); } if (reader instanceof Reader) { ((Reader) reader).setApplication(app); } reader.setConfiguration(openApiConfiguration); return reader; }
@Override public OpenApiContext buildContext(boolean init) throws OpenApiConfigurationException { if (StringUtils.isBlank(ctxId)) { ctxId = OpenApiContext.OPENAPI_CONTEXT_ID_DEFAULT; } OpenApiContext ctx = OpenApiContextLocator.getInstance().getOpenApiContext(ctxId); if (ctx == null) { OpenApiContext rootCtx = OpenApiContextLocator.getInstance().getOpenApiContext(OpenApiContext.OPENAPI_CONTEXT_ID_DEFAULT); ctx = new XmlWebOpenApiContext() .servletConfig(servletConfig) .openApiConfiguration(openApiConfiguration) .id(ctxId) .parent(rootCtx); if (ctx.getConfigLocation() == null && configLocation != null) { ((XmlWebOpenApiContext) ctx).configLocation(configLocation); } if (((XmlWebOpenApiContext) ctx).getResourcePackages() == null && resourcePackages != null) { ((XmlWebOpenApiContext) ctx).resourcePackages(resourcePackages); } if (((XmlWebOpenApiContext) ctx).getResourceClasses() == null && resourceClasses != null) { ((XmlWebOpenApiContext) ctx).resourceClasses(resourceClasses); } if (init) { ctx.init(); // includes registering itself with OpenApiContextLocator } } return ctx; }
@Override protected OpenApiScanner buildScanner(OpenAPIConfiguration openApiConfiguration) throws Exception { OpenApiScanner scanner; if (StringUtils.isNotBlank(openApiConfiguration.getScannerClass())) { Class cls = getClass().getClassLoader().loadClass(openApiConfiguration.getScannerClass()); scanner = (OpenApiScanner) cls.newInstance(); } else { scanner = new JaxrsApplicationAndAnnotationScanner(); } scanner.setConfiguration(openApiConfiguration); if (scanner instanceof JaxrsOpenApiScanner) { ((JaxrsOpenApiScanner) scanner).setApplication(app); } return scanner; } }
@Override public OpenApiContext buildContext(boolean init) throws OpenApiConfigurationException { if (StringUtils.isBlank(ctxId)) { ctxId = OpenApiContext.OPENAPI_CONTEXT_ID_DEFAULT; } OpenApiContext ctx = OpenApiContextLocator.getInstance().getOpenApiContext(ctxId); if (ctx == null) { OpenApiContext rootCtx = OpenApiContextLocator.getInstance().getOpenApiContext(OpenApiContext.OPENAPI_CONTEXT_ID_DEFAULT); ctx = new XmlWebOpenApiContext() .servletConfig(servletConfig) .app(application) .openApiConfiguration(openApiConfiguration) .id(ctxId) .parent(rootCtx); if (ctx.getConfigLocation() == null && configLocation != null) { ((XmlWebOpenApiContext) ctx).configLocation(configLocation); } if (((XmlWebOpenApiContext) ctx).getResourcePackages() == null && resourcePackages != null) { ((XmlWebOpenApiContext) ctx).resourcePackages(resourcePackages); } if (((XmlWebOpenApiContext) ctx).getResourceClasses() == null && resourceClasses != null) { ((XmlWebOpenApiContext) ctx).resourceClasses(resourceClasses); } if (init) { ctx.init(); // includes registering itself with OpenApiContextLocator } } return ctx; }