@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; }
@SuppressWarnings("rawtypes") protected void generateSpec() throws Exception { Set<Class<?>> classes = this.registeredControllers; OpenAPIExtensions.setExtensions(Collections.singletonList(new ServerParameterExtension())); OpenAPI openApi = new OpenAPI(); Info info = mapper.convertValue(openAPIConfig.getValue("info").unwrapped(), Info.class); openApi.setInfo(info); Map<String, SecurityScheme> securitySchemes = mapper.convertValue( openAPIConfig.getValue("securitySchemes").unwrapped(),new TypeReference<Map<String, SecurityScheme>>(){}); if (openApi.getComponents() == null) { openApi.setComponents(new Components()); } openApi.getComponents().setSecuritySchemes(securitySchemes); List<Server> servers = mapper.convertValue(openAPIConfig.getValue("servers").unwrapped(), new TypeReference<List<Server>>(){}); openApi.setServers(servers); SwaggerConfiguration config = new SwaggerConfiguration().resourceClasses(classes.stream().map(Class::getName).collect(Collectors.toSet())).openAPI(openApi); config.setModelConverterClassess(Collections.singleton(ServerModelResolver.class.getName())); OpenApiContext ctx = new GenericOpenApiContext().openApiConfiguration(config) .openApiReader(new Reader(config)) .openApiScanner(new JaxrsApplicationAndAnnotationScanner().openApiConfiguration(config)) .init(); openApi = ctx.read(); this.openApi = openApi; this.spec = writer.writeValueAsString(openApi); }
@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; }