io.swagger.v3.oas.models.security.SecurityScheme Java Examples
The following examples show how to use
io.swagger.v3.oas.models.security.SecurityScheme.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenApiCustomizerSubclassTest.java From cxf with Apache License 2.0 | 7 votes |
@Override protected OpenApiFeature createOpenApiFeature() { final OpenApiCustomizer customizer = new OpenApiCustomizer() { public void customize(io.swagger.v3.oas.models.OpenAPI oas) { super.customize(oas); oas.getInfo().setDescription("Custom Description"); oas.getInfo().getLicense().setName("Custom License"); oas.getComponents().getSecuritySchemes().put("openid", new SecurityScheme()); } }; customizer.setJavadocProvider(new JavaDocProvider()); customizer.setDynamicBasePath(true); customizer.setReplaceTags(true); final OpenApiFeature feature = super.createOpenApiFeature(); feature.setCustomizer(customizer); feature.setScan(false); feature.setResourcePackages(Collections.singleton(getClass().getPackage().getName())); return feature; }
Example #2
Source File: OAS3Parser.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * This method returns the boolean value which checks whether the swagger is included default security scheme or not * * @param swaggerContent resource json * @return boolean * @throws APIManagementException */ private boolean isDefaultGiven(String swaggerContent) throws APIManagementException { OpenAPI openAPI = getOpenAPI(swaggerContent); Components components = openAPI.getComponents(); if (components == null) { return false; } Map<String, SecurityScheme> securitySchemes = components.getSecuritySchemes(); if (securitySchemes == null) { return false; } SecurityScheme checkDefault = openAPI.getComponents().getSecuritySchemes().get(OPENAPI_SECURITY_SCHEMA_KEY); if (checkDefault == null) { return false; } return true; }
Example #3
Source File: OpenAPIBuilder.java From springdoc-openapi with Apache License 2.0 | 6 votes |
/** * Gets security schemes classes. * * @param scanner the scanner * @param packagesToScan the packages to scan * @return the security schemes classes */ private Set<io.swagger.v3.oas.annotations.security.SecurityScheme> getSecuritySchemesClasses( ClassPathScanningCandidateComponentProvider scanner, List<String> packagesToScan) { Set<io.swagger.v3.oas.annotations.security.SecurityScheme> apiSecurityScheme = new HashSet<>(); for (String pack : packagesToScan) { for (BeanDefinition bd : scanner.findCandidateComponents(pack)) { try { apiSecurityScheme.add(AnnotationUtils.findAnnotation(Class.forName(bd.getBeanClassName()), io.swagger.v3.oas.annotations.security.SecurityScheme.class)); } catch (ClassNotFoundException e) { LOGGER.error("Class Not Found in classpath : {}", e.getMessage()); } } } return apiSecurityScheme; }
Example #4
Source File: OpenAPIBuilder.java From springdoc-openapi with Apache License 2.0 | 6 votes |
/** * Add security scheme. * * @param apiSecurityScheme the api security scheme * @param components the components */ private void addSecurityScheme(Set<io.swagger.v3.oas.annotations.security.SecurityScheme> apiSecurityScheme, Components components) { for (io.swagger.v3.oas.annotations.security.SecurityScheme securitySchemeAnnotation : apiSecurityScheme) { Optional<SecuritySchemePair> securityScheme = securityParser.getSecurityScheme(securitySchemeAnnotation); if (securityScheme.isPresent()) { Map<String, SecurityScheme> securitySchemeMap = new HashMap<>(); if (StringUtils.isNotBlank(securityScheme.get().getKey())) { securitySchemeMap.put(securityScheme.get().getKey(), securityScheme.get().getSecurityScheme()); if (!CollectionUtils.isEmpty(components.getSecuritySchemes())) { components.getSecuritySchemes().putAll(securitySchemeMap); } else { components.setSecuritySchemes(securitySchemeMap); } } } } }
Example #5
Source File: BearerOpenAPIFilter.java From RestDoc with Apache License 2.0 | 6 votes |
@Override public OpenAPI handle(OpenAPI openApi) { var components = openApi.getComponents(); // security 添加 token var scheme = new SecurityScheme(); scheme.setType(SecurityScheme.Type.HTTP); scheme.setScheme("bearer"); scheme.setBearerFormat("JWT"); components.addSecuritySchemes("bearerAuth", scheme); // path 添加 token var paths = openApi.getPaths(); var securityRequirement = new SecurityRequirement().addList("bearerAuth"); paths.forEach((s, pathItem) -> { handelPathItem(pathItem.getGet(), securityRequirement); handelPathItem(pathItem.getPost(), securityRequirement); handelPathItem(pathItem.getPut(), securityRequirement); handelPathItem(pathItem.getDelete(), securityRequirement); handelPathItem(pathItem.getPatch(), securityRequirement); handelPathItem(pathItem.getHead(), securityRequirement); handelPathItem(pathItem.getOptions(), securityRequirement); handelPathItem(pathItem.getTrace(), securityRequirement); }); return openApi; }
Example #6
Source File: OpenApiSecuritySchemeValidationsTest.java From openapi-generator with Apache License 2.0 | 6 votes |
@Test(dataProvider = "apacheNginxRecommendationExpectations", description = "disable apache nginx via turning off rule") public void testApacheNginxWithDisabledRule(SecurityScheme.In in, String key, boolean matches) { RuleConfiguration config = new RuleConfiguration(); config.setEnableApacheNginxUnderscoreRecommendation(false); OpenApiSecuritySchemeValidations validator = new OpenApiSecuritySchemeValidations(config); SecurityScheme securityScheme = new SecurityScheme().in(in).name(key); ValidationResult result = validator.validate(new SecuritySchemeWrapper(null, securityScheme)); Assert.assertNotNull(result.getWarnings()); List<Invalid> warnings = result.getWarnings().stream() .filter(invalid -> ValidationConstants.ApacheNginxUnderscoreFailureMessage.equals(invalid.getMessage())) .collect(Collectors.toList()); Assert.assertNotNull(warnings); Assert.assertEquals(warnings.size(), 0, "Expected rule to be disabled."); }
Example #7
Source File: OpenApiSecuritySchemeValidationsTest.java From openapi-generator with Apache License 2.0 | 6 votes |
@Test(dataProvider = "apacheNginxRecommendationExpectations", description = "default apache nginx recommendation") public void testDefaultRecommendationApacheNginx(SecurityScheme.In in, String key, boolean matches) { RuleConfiguration config = new RuleConfiguration(); config.setEnableRecommendations(true); OpenApiSecuritySchemeValidations validator = new OpenApiSecuritySchemeValidations(config); SecurityScheme securityScheme = new SecurityScheme().in(in).name(key); ValidationResult result = validator.validate(new SecuritySchemeWrapper(null, securityScheme)); Assert.assertNotNull(result.getWarnings()); List<Invalid> warnings = result.getWarnings().stream() .filter(invalid -> ValidationConstants.ApacheNginxUnderscoreFailureMessage.equals(invalid.getMessage())) .collect(Collectors.toList()); Assert.assertNotNull(warnings); if (matches) { Assert.assertEquals(warnings.size(), 1, "Expected " + key + " to match recommendation."); } else { Assert.assertEquals(warnings.size(), 0, "Expected " + key + " not to match recommendation."); } }
Example #8
Source File: SecuritySchemeSerializer.java From api-layer with Eclipse Public License 2.0 | 6 votes |
@Override public void serialize(SecurityScheme value, JsonGenerator jGen, SerializerProvider serializers) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); String securitySchemeContent = objectMapper.writeValueAsString(value); ObjectNode jsonNode = objectMapper.readValue(securitySchemeContent, ObjectNode.class); SecurityScheme.Type securitySchemeType = value.getType(); if (securitySchemeType != null) { jsonNode.put("type", securitySchemeType.toString()); } SecurityScheme.In securitySchemeIn = value.getIn(); if (securitySchemeIn != null) { jsonNode.put("in", securitySchemeIn.toString()); } jGen.writeObject(jsonNode); }
Example #9
Source File: OpenAPICodegenUtils.java From product-microgateway with Apache License 2.0 | 6 votes |
/** * Provide api keys for a given security requirement list. * * @param securityRequirementList {@link List<SecurityRequirement>} object * @return list of API Keys */ public static List<APIKey> generateAPIKeysFromSecurity(List<SecurityRequirement> securityRequirementList, boolean isAPIKeyEnabled) { List<APIKey> apiKeys = new ArrayList<>(); if (securityRequirementList != null) { securityRequirementList.forEach(value -> value.forEach((k, v) -> { //check if the key is in apikey list if (apiKeySecuritySchemaMap.containsKey(k)) { apiKeys.add((APIKey) apiKeySecuritySchemaMap.get(k)); } })); } if (isAPIKeyEnabled && apiKeys.isEmpty()) { apiKeys.add(new APIKey(SecurityScheme.In.HEADER, OpenAPIConstants.DEFAULT_API_KEY_HEADER_QUERY)); apiKeys.add(new APIKey(SecurityScheme.In.QUERY, OpenAPIConstants.DEFAULT_API_KEY_HEADER_QUERY)); } return apiKeys; }
Example #10
Source File: OpenAPICodegenUtils.java From product-microgateway with Apache License 2.0 | 6 votes |
/** * store the security schemas of type "basic" and "apikey". * * @param openAPI {@link OpenAPI} object */ public static void setSecuritySchemaList(OpenAPI openAPI) { //Since the security schema list needs to instantiated per each API basicSecuritySchemaList = new ArrayList<>(); apiKeySecuritySchemaMap = new HashMap(); if (openAPI.getComponents() == null || openAPI.getComponents().getSecuritySchemes() == null) { return; } openAPI.getComponents().getSecuritySchemes().forEach((key, val) -> { if (val.getType() == SecurityScheme.Type.HTTP && val.getScheme().toLowerCase(Locale.getDefault()).equals("basic")) { basicSecuritySchemaList.add(key); } else if (val.getType() == SecurityScheme.Type.APIKEY) { APIKey apiKey = new APIKey(val.getIn(), val.getName()); apiKeySecuritySchemaMap.put(key, apiKey); } }); }
Example #11
Source File: SecurityRequirementsDiff.java From openapi-diff with Apache License 2.0 | 6 votes |
private List<Pair<SecurityScheme.Type, SecurityScheme.In>> getListOfSecuritySchemes( Components components, SecurityRequirement securityRequirement) { return securityRequirement .keySet() .stream() .map( x -> { SecurityScheme result = components.getSecuritySchemes().get(x); if (result == null) { throw new IllegalArgumentException("Impossible to find security scheme: " + x); } return result; }) .map(this::getPair) .distinct() .collect(Collectors.toList()); }
Example #12
Source File: OpenApiObjectGenerator.java From flow with Apache License 2.0 | 6 votes |
private OpenAPI createBasicModel() { OpenAPI openAPI = new OpenAPI(); Info info = new Info(); info.setTitle(configuration.getApplicationTitle()); info.setVersion(configuration.getApplicationApiVersion()); openAPI.setInfo(info); Paths paths = new Paths(); openAPI.setPaths(paths); Server server = new Server(); server.setUrl(configuration.getServerUrl()); server.setDescription(configuration.getServerDescription()); openAPI.setServers(Collections.singletonList(server)); Components components = new Components(); SecurityScheme vaadinConnectOAuth2Scheme = new SecurityScheme() .type(SecurityScheme.Type.OAUTH2) .flows(new OAuthFlows().password(new OAuthFlow() .tokenUrl(VAADIN_CONNECT_OAUTH2_TOKEN_URL) .scopes(new Scopes()))); components.addSecuritySchemes(VAADIN_CONNECT_OAUTH2_SECURITY_SCHEME, vaadinConnectOAuth2Scheme); openAPI.components(components); return openAPI; }
Example #13
Source File: OpenAPIV3ParserTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testIssue480() { final OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/issue-480.yaml"); for (String key : openAPI.getComponents().getSecuritySchemes().keySet()) { SecurityScheme definition = openAPI.getComponents().getSecuritySchemes().get(key); if ("petstore_auth".equals(key)) { assertTrue(definition.getType().equals(SecurityScheme.Type.OAUTH2) ); //OAuth2 oauth = (OAuth2Definition) definition; assertEquals("This is a description", definition.getDescription()); } if ("api_key".equals(key)) { assertTrue(definition.getType().equals(SecurityScheme.Type.APIKEY) ); assertEquals("This is another description", definition.getDescription()); } } }
Example #14
Source File: JaxRsActivatorNew.java From pnc with Apache License 2.0 | 6 votes |
private SecurityScheme getAuthScheme() { try { final KeycloakClientConfig keycloakConfig = systemConfig.getKeycloakServiceAccountConfig(); if (keycloakConfig == null || StringUtils.isEmpty(keycloakConfig.getAuthServerUrl())) { return null; } URI keycloakURL = new URI(keycloakConfig.getAuthServerUrl() + "/") .resolve("realms/" + keycloakConfig.getRealm() + "/protocol/openid-connect/auth"); final OAuthFlow implicitFlow = new OAuthFlow().authorizationUrl(keycloakURL.toString()); SecurityScheme scheme = new SecurityScheme(); scheme.type(SecurityScheme.Type.OAUTH2) .description("This application uses Keycloak oauth authentication") .flows(new OAuthFlows().implicit(implicitFlow)); return scheme; } catch (URISyntaxException ex) { logger.warn("Failed to parse Keycloak setting", ex); return null; } }
Example #15
Source File: OASParserUtil.java From carbon-apimgt with Apache License 2.0 | 6 votes |
private static void setScopes(final OpenAPI destOpenAPI, final Set<Scope> aggregatedScopes) { Map<String, SecurityScheme> securitySchemes; SecurityScheme securityScheme; OAuthFlow oAuthFlow; Scopes scopes = new Scopes(); if (destOpenAPI.getComponents() != null && (securitySchemes = destOpenAPI.getComponents().getSecuritySchemes()) != null && (securityScheme = securitySchemes.get(OAS3Parser.OPENAPI_SECURITY_SCHEMA_KEY)) != null && (oAuthFlow = securityScheme.getFlows().getImplicit()) != null) { Map<String, String> scopeBindings = new HashMap<>(); for (Scope scope : aggregatedScopes) { scopes.addString(scope.getKey(), scope.getDescription()); scopeBindings.put(scope.getKey(), scope.getRoles()); } oAuthFlow.setScopes(scopes); Map<String, Object> extensions = new HashMap<>(); extensions.put(APIConstants.SWAGGER_X_SCOPES_BINDINGS, scopeBindings); oAuthFlow.setExtensions(extensions); } }
Example #16
Source File: OAS3Parser.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * This method returns the oauth scopes according to the given swagger * * @param resourceConfigsJSON resource json * @return scope set * @throws APIManagementException */ @Override public Set<Scope> getScopes(String resourceConfigsJSON) throws APIManagementException { OpenAPI openAPI = getOpenAPI(resourceConfigsJSON); Map<String, SecurityScheme> securitySchemes; SecurityScheme securityScheme; OAuthFlow oAuthFlow; Scopes scopes; if (openAPI.getComponents() != null && (securitySchemes = openAPI.getComponents().getSecuritySchemes()) != null && (securityScheme = securitySchemes.get(OPENAPI_SECURITY_SCHEMA_KEY)) != null && (oAuthFlow = securityScheme.getFlows().getImplicit()) != null && (scopes = oAuthFlow.getScopes()) != null) { Set<Scope> scopeSet = new HashSet<>(); for (Map.Entry<String, String> entry : scopes.entrySet()) { Scope scope = new Scope(); scope.setKey(entry.getKey()); scope.setName(entry.getKey()); scope.setDescription(entry.getValue()); Map<String, String> scopeBindings; if (oAuthFlow.getExtensions() != null && (scopeBindings = (Map<String, String>) oAuthFlow.getExtensions().get(APIConstants.SWAGGER_X_SCOPES_BINDINGS)) != null) { if (scopeBindings.get(scope.getKey()) != null) { scope.setRoles(scopeBindings.get(scope.getKey())); } } scopeSet.add(scope); } return OASParserUtil.sortScopes(scopeSet); } else { return OASParserUtil.sortScopes(getScopesFromExtensions(openAPI)); } }
Example #17
Source File: SpringDocTestApp.java From springdoc-openapi with Apache License 2.0 | 5 votes |
@Bean public OpenAPI customOpenAPI() { return new OpenAPI() .components(new Components().addSecuritySchemes("basicScheme", new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic"))) .info(new Info().title("Petstore API").version("v0").description( "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.") .termsOfService("http://swagger.io/terms/") .license(new License().name("Apache 2.0").url("http://springdoc.org"))); }
Example #18
Source File: SpringDocApp2Test.java From springdoc-openapi with Apache License 2.0 | 5 votes |
@Bean public OpenAPI customOpenAPI() { return new OpenAPI() .components(new Components().addSecuritySchemes("basicScheme", new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic"))) .info(new Info().title("Petstore API").version("v0").description( "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.") .termsOfService("http://swagger.io/terms/") .license(new License().name("Apache 2.0").url("http://springdoc.org"))); }
Example #19
Source File: SecurityRequirementsDiff.java From openapi-diff with Apache License 2.0 | 5 votes |
public boolean same(SecurityRequirement left, SecurityRequirement right) { // List<SecurityScheme.Type> leftTypes = left.keySet().stream() // .map(x -> leftComponents.getSecuritySchemes().get(x).getType()) // .collect(Collectors.toList()); // List<SecurityScheme.Type> rightTypes = right.keySet().stream() // .map(x -> rightComponents.getSecuritySchemes().get(x).getType()) // .collect(Collectors.toList()); // List<Pair<SecurityScheme.Type, SecurityScheme.In>> leftTypes = getListOfSecuritySchemes(leftComponents, left); List<Pair<SecurityScheme.Type, SecurityScheme.In>> rightTypes = getListOfSecuritySchemes(rightComponents, right); return CollectionUtils.isEqualCollection(leftTypes, rightTypes); }
Example #20
Source File: SecurityRequirementDiff.java From openapi-diff with Apache License 2.0 | 5 votes |
private LinkedHashMap<String, List<String>> contains( SecurityRequirement right, String schemeRef) { SecurityScheme leftSecurityScheme = leftComponents.getSecuritySchemes().get(schemeRef); LinkedHashMap<String, List<String>> found = new LinkedHashMap<>(); for (Map.Entry<String, List<String>> entry : right.entrySet()) { SecurityScheme rightSecurityScheme = rightComponents.getSecuritySchemes().get(entry.getKey()); if (leftSecurityScheme.getType() == rightSecurityScheme.getType()) { switch (leftSecurityScheme.getType()) { case APIKEY: if (leftSecurityScheme.getName().equals(rightSecurityScheme.getName())) { found.put(entry.getKey(), entry.getValue()); return found; } break; case OAUTH2: case HTTP: case OPENIDCONNECT: found.put(entry.getKey(), entry.getValue()); return found; } } } return found; }
Example #21
Source File: JaxRsActivatorNew.java From pnc with Apache License 2.0 | 5 votes |
private void configureSwagger() { OpenAPI oas = new OpenAPI(); Info info = new Info().title("PNC") .description("PNC build system") .termsOfService("http://swagger.io/terms/") .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html")); oas.info(info); oas.addServersItem(new Server().url("/pnc-rest-new")); final SecurityScheme authScheme = getAuthScheme(); if (authScheme == null) { logger.warn("Not adding auth scheme to openapi definition as auth scheme could not been generated."); } else { oas.schemaRequirement(KEYCLOAK_AUTH, authScheme); oas.addSecurityItem(new SecurityRequirement().addList(KEYCLOAK_AUTH)); } SwaggerConfiguration oasConfig = new SwaggerConfiguration().openAPI(oas); try { new JaxrsOpenApiContextBuilder().servletConfig(servletConfig) .application(this) .openApiConfiguration(oasConfig) .buildContext(true); } catch (OpenApiConfigurationException ex) { throw new IllegalArgumentException("Failed to setup OpenAPI configuration", ex); } }
Example #22
Source File: SpringDocApp1Test.java From springdoc-openapi with Apache License 2.0 | 5 votes |
@Bean public OpenAPI customOpenAPI() { return new OpenAPI() .components(new Components().addSecuritySchemes("basicScheme", new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic"))) .info(new Info().title("SpringShop API").version("v0") .license(new License().name("Apache 2.0").url("http://springdoc.org"))); }
Example #23
Source File: OpenAPICodegenUtils.java From product-microgateway with Apache License 2.0 | 5 votes |
/** * store the security schemas of type "oauth2". * * @param openAPI {@link OpenAPI} object */ public static void setOauthSecuritySchemaList(OpenAPI openAPI) { //Since the security schema list needs to instantiated per each API oauthSecuritySchemaList = new ArrayList<>(); if (openAPI.getComponents() == null || openAPI.getComponents().getSecuritySchemes() == null) { return; } openAPI.getComponents().getSecuritySchemes().forEach((key, val) -> { if (val.getType() == SecurityScheme.Type.OAUTH2 || (val.getType() == SecurityScheme.Type.HTTP && val.getScheme().toLowerCase(Locale.getDefault()).equals("jwt"))) { oauthSecuritySchemaList.add(key); } }); }
Example #24
Source File: SpringDocApp105Test.java From springdoc-openapi with Apache License 2.0 | 5 votes |
@Bean public OpenAPI customOpenAPI() { return new OpenAPI() .components(new Components().addSecuritySchemes("basicScheme", new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic"))) .info(new Info().title("Petstore API").version("v0").description( "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.") .termsOfService("http://swagger.io/terms/") .license(new License().name("Apache 2.0").url("http://springdoc.org"))); }
Example #25
Source File: ProtoOpenAPI.java From product-microgateway with Apache License 2.0 | 5 votes |
/** * Add scopes to the security schema. * * @param scope scope */ private void addScopeToSchema(String scope) { if (StringUtils.isEmpty(scope)) { return; } SecurityScheme scheme = openAPI.getComponents().getSecuritySchemes().get(OAUTH2_SCHEME); if (!scheme.getFlows().getImplicit().getScopes().containsKey(scope)) { //scopes description is set as a null string scheme.getFlows().getImplicit().setScopes(new Scopes().addString(scope, "")); } }
Example #26
Source File: ProtoOpenAPI.java From product-microgateway with Apache License 2.0 | 5 votes |
private void addAPIKeySecurityScheme() { SecurityScheme scheme = new SecurityScheme(); scheme.setType(SecurityScheme.Type.APIKEY); scheme.setName("api_key"); scheme.setIn(SecurityScheme.In.HEADER); openAPI.getComponents().addSecuritySchemes(APIKEY_SCHEME, scheme); isAPIKeyEnabled = true; }
Example #27
Source File: SecuritySchemeSerializerTest.java From api-layer with Eclipse Public License 2.0 | 5 votes |
private SecurityScheme getDummyScheme() { SecurityScheme scheme = new SecurityScheme(); scheme.type(SecurityScheme.Type.HTTP); scheme.description("desc"); scheme.name("name"); scheme.$ref("ref"); scheme.in(SecurityScheme.In.COOKIE); scheme.scheme("scheme"); scheme.bearerFormat("format"); scheme.flows(new OAuthFlows()); scheme.openIdConnectUrl("url"); scheme.extensions(Collections.emptyMap()); return scheme; }
Example #28
Source File: ApiDocV3Service.java From api-layer with Eclipse Public License 2.0 | 5 votes |
private ObjectMapper initializeObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(SecurityScheme.class, new SecuritySchemeSerializer()); objectMapper.registerModule(simpleModule); return objectMapper; }
Example #29
Source File: SwaggerConfig.java From platform with Apache License 2.0 | 5 votes |
@Bean public OpenAPI openAPI() { return new OpenAPI().components( new Components().addSecuritySchemes("basicScheme", new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")) ).info(new Info() .title("Platform API") .version("1.0.0") .description("Platform API")); }
Example #30
Source File: SpringDocTestApp.java From springdoc-openapi with Apache License 2.0 | 5 votes |
@Bean public OpenAPI customOpenAPI() { return new OpenAPI() .components(new Components() .addSecuritySchemes("basicScheme", new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")) .addParameters("myHeader1", new Parameter().in("header").schema(new StringSchema()).name("myHeader1")) .addHeaders("myHeader2", new Header().description("myHeader2 header").schema(new StringSchema()))) .info(new Info().title("Petstore API").version("v0").description( "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.") .termsOfService("http://swagger.io/terms/") .license(new License().name("Apache 2.0").url("http://springdoc.org"))); }