Skip to content

Add Security Schema by AutoConfigure #2780

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
yuseok-kim-edushare opened this issue Nov 14, 2024 · 2 comments
Closed

Add Security Schema by AutoConfigure #2780

yuseok-kim-edushare opened this issue Nov 14, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@yuseok-kim-edushare
Copy link

yuseok-kim-edushare commented Nov 14, 2024

Is your feature request related to a problem? Please describe.

  • When I'm Developing Spring Cloud based Microservices
  • then I meet Springdoc-Openapi-starter couldn't make OpenAPI with global security schemes in AutoConfiguration of Spring Boot's

Describe the solution you'd like

  • If We pre-defined global security scheme, in yaml or properties could be managed by Spring Cloud Config Server
springdoc:
  api-docs:
    path: /v3/api-docs
  swagger-ui:
    path: /swagger-ui.html
  security-schemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

like we already defined on config class and RESTcontroller

@Configuration
public class SwaggerConfig {

	@Bean
	public OpenAPI customOpenAPI() {
		return new OpenAPI().components(new Components()
			.addSecuritySchemes("basicScheme", new SecurityScheme()
				.type(SecurityScheme.Type.HTTP).bearerFormat("JWT").scheme("bearer")));
	}
}
---
@OpenAPIDefinition(security = @SecurityRequirement(name = "bearerScheme"))
@Slf4j
@RestController
@RequestMapping("/v1")
@RequiredArgsConstructor
public class ProfileRestController {
  • What is the expected result using OpenAPI Description (yml or json)?
    • like following json, springdoc-openapi automatic created api-doc will like following
{
    "openapi": "3.0.1",
    "servers": [
        {
            "url": "http://localhost:53646",
            "description": "Generated server url"
        }
    ],
    "security": [
        {
            "bearerScheme": []
        }
    ],
@bnasslahsen bnasslahsen added the enhancement New feature or request label Dec 8, 2024
@bnasslahsen
Copy link
Collaborator

@yuseok-kim-edushare,

This how you will be able to add it:
You can test it with the latest SNAPSHOT.

springdoc:
  open-api:
    info:
      title: Api info title
      description: Api info description
      version: Api info version
    security:
      - basicScheme: [ ]
    components:
      securitySchemes:
        basicScheme:
          type: http
          scheme: bearer
          bearerFormat: JWT

@yuseok-kim-edushare
Copy link
Author

awesome! thanks!!

ndwlocatieservices added a commit to ndwnu/nls-accessibility-map that referenced this issue Jan 14, 2025
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [nu.ndw.nls.locationdataissuesapi:client-feign](https://dev.azure.com/ndwnu/NLS/_git/nls-location-data-issues) ([source](https://dev.azure.com/ndwnu/NLS/_git/nls-location-data-issues)) | compile | patch | `1.0.17` -> `1.0.18` |
| [org.springdoc:springdoc-openapi-starter-webmvc-ui](https://springdoc.org/) ([source](https://github.com/springdoc/springdoc-openapi)) | compile | minor | `2.7.0` -> `2.8.0` |

---

### Release Notes

<details>
<summary>springdoc/springdoc-openapi (org.springdoc:springdoc-openapi-starter-webmvc-ui)</summary>

### [`v2.8.0`](https://github.com/springdoc/springdoc-openapi/blob/HEAD/CHANGELOG.md#280---2025-01-03)

[Compare Source](springdoc/springdoc-openapi@v2.7.0...v2.8.0)

##### Added

-   [#&#8203;2790](springdoc/springdoc-openapi#2790) - Moving to OpenAPI 3.1 as the default implementation for springdoc-openapi
-   [#&#8203;2817](springdoc/springdoc-openapi#2817) - Obey annotations when flattening ParameterObject fields
-   [#&#8203;2826](springdoc/springdoc-openapi#2826) - Make it possible to mark parameters with [@&#8203;RequestParam](https://github.com/RequestParam) annotation to be sent in form instead of query.
-   [#&#8203;2822](springdoc/springdoc-openapi#2822) - Support returning null in ParameterCustomizer
-   [#&#8203;2830](springdoc/springdoc-openapi#2830) - Add support for deprecated fields.
-   [#&#8203;2780](springdoc/springdoc-openapi#2780) - Add Security Schema by AutoConfigure

##### Changed

-   Upgrade spring-boot to 3.4.1
-   Upgrade spring-cloud-function to 4.2.0
-   Upgrade swagger-core to 2.2.27

##### Fixed

-   [#&#8203;2804](springdoc/springdoc-openapi#2804) - Stable release 2.7.0 depends on Spring Cloud Milestone 4.2.0-M1
-   [#&#8203;2828](springdoc/springdoc-openapi#2828) - Required a bean of type 'org.springframework.data.rest.webmvc.mapping.Associations' that could not be found.
-   [#&#8203;2823](springdoc/springdoc-openapi#2823) - Capturing pattern in identical paths only renders the path element of one method
-   [#&#8203;2817](springdoc/springdoc-openapi#2817) - Automatically add required if a field is [@&#8203;notNull](https://github.com/notNull) or [@&#8203;NotBlank](https://github.com/NotBlank).
-   [#&#8203;2814](springdoc/springdoc-openapi#2814) - An unresolvable circular reference with management.endpoint.gateway.enabled=true.
-   [#&#8203;2798](springdoc/springdoc-openapi#2798) - Object schema generated for Unit Kotlin type.
-   [#&#8203;2797](springdoc/springdoc-openapi#2797) - Removing operationId via customizer does not w...
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants