Skip to content

Commit e76d981

Browse files
author
bnasslahsen
committed
Merge branch 'kgeis-master'
2 parents 1d3c96b + 54491de commit e76d981

File tree

4 files changed

+132
-61
lines changed

4 files changed

+132
-61
lines changed

faq.md

Lines changed: 101 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The OpenAPI description of this group, will be available by default on:
1414

1515
To enable the support of multiple OpenAPI definitions, a bean of type `GroupedOpenApi` needs to be defined.
1616

17-
For the following Group definition(based on package path), the OpenAPI description url will be : /v3/api-docs/**stores**
17+
For the following Group definition(based on package path), the OpenAPI description URL will be : /v3/api-docs/**stores**
1818
```java
1919
@Bean
2020
public GroupedOpenApi storeOpenApi() {
@@ -24,7 +24,7 @@ public GroupedOpenApi storeOpenApi() {
2424
}
2525
```
2626

27-
For the following Group definition (based on package name), the OpenAPI description url will be: /v3/api-docs/**users**
27+
For the following Group definition (based on package name), the OpenAPI description URL will be: /v3/api-docs/**users**
2828
```java
2929
@Bean
3030
public GroupedOpenApi userOpenApi() {
@@ -34,7 +34,7 @@ public GroupedOpenApi userOpenApi() {
3434
}
3535
```
3636

37-
For the following Group definition(based on path), the OpenAPI description url will be: /v3/api-docs/**pets**
37+
For the following Group definition(based on path), the OpenAPI description URL will be: /v3/api-docs/**pets**
3838
```java
3939
@Bean
4040
public GroupedOpenApi petOpenApi() {
@@ -44,7 +44,7 @@ public GroupedOpenApi petOpenApi() {
4444
}
4545
```
4646

47-
For the following Group definition (based on package name and path), the OpenAPI description url will be: /v3/api-docs/**groups**
47+
For the following Group definition (based on package name and path), the OpenAPI description URL will be: /v3/api-docs/**groups**
4848
```java
4949
@Bean
5050
public GroupedOpenApi groupOpenApi() {
@@ -71,11 +71,11 @@ springdoc.swagger-ui.filter=group-a
7171
```
7272

7373
### How can I disable/enable Swagger UI generation based on env variable?
74-
- This property helps you disable only the ui.
74+
- This property helps you disable only the UI.
7575
```properties
7676
springdoc.swagger-ui.enabled=false
7777
```
78-
### How can I control the default expansion setting for the operations and tags, in the Swagger Ui ,
78+
### How can I control the default expansion setting for the operations and tags, in the Swagger UI ,
7979
- You can set this property in your application.yml like so for example:
8080
```properties
8181
springdoc.swagger-ui.doc-expansion= none
@@ -135,7 +135,7 @@ springdoc.packagesToScan=package1, package2
135135
</dependency>
136136
```
137137

138-
### Is there a gradle plugin available?
138+
### Is there a Gradle plugin available?
139139
- There is no `springdoc-gradle-plugin` planned for short term.
140140

141141
### How can I hide a parameter from the documentation ?
@@ -171,7 +171,7 @@ The projects that uses `spring-data` should add this dependency together with th
171171
```
172172

173173
- If you use Pageable in a GET HTTP method, you will have to declare the explicit mapping of Pageable fields as Query Params and add the @Parameter(hidden = true) Pageable pageable on your pageable parameter.
174-
- You should also, declare the annotation `@PageableAsQueryParam` provided by springdoc on the method level, or declare your own if need to define your custom description, defaultvalue, ...
174+
- You should also, declare the annotation `@PageableAsQueryParam` provided by springdoc on the method level, or declare your own if need to define your custom description, defaultValue, ...
175175
- Since, v1.3.1 you can use as well `@ParameterObject` instead of `@PageableAsQueryParam` for HTTP `GET` methods.
176176

177177

@@ -196,10 +196,10 @@ public String toString() {
196196
}
197197
```
198198

199-
### Does it really support Spring Boot 2.2.x.RELEASE & Hateoas 1.0?
199+
### Does it really support Spring Boot 2.2.x.RELEASE & HATEOAS 1.0?
200200
- Yes
201201

202-
### How can I deploy the Doploy `springdoc-openapi-ui`, behind a reverse proxy?
202+
### How can I deploy `springdoc-openapi-ui` behind a reverse proxy?
203203
- If your application is running behind a proxy, a load-balancer or in the cloud, the request information (like the host, port, scheme…​) might change along the way. Your application may be running on `10.10.10.10:8080`, but HTTP clients should only see `example.org`.
204204

205205
- [RFC7239 "Forwarded Headers"](https://tools.ietf.org/html/rfc7239) defines the Forwarded HTTP header; proxies can use this header to provide information about the original request. You can configure your application to read those headers and automatically use that information when creating links and sending them to clients in HTTP 302 responses, JSON documents or HTML pages. There are also non-standard headers, like `X-Forwarded-Host`, `X-Forwarded-Port`, `X-Forwarded-Proto`, `X-Forwarded-Ssl`, and `X-Forwarded-Prefix`.
@@ -239,7 +239,7 @@ springdoc.swagger-ui.path= /swagger-ui/api-docs.html
239239
```
240240

241241
### How can I test the Swagger UI?
242-
- You can have a look on this sample test of the ui:
242+
- You can have a look on this sample test of the UI:
243243
- [https://github.com/springdoc/springdoc-openapi/blob/master/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1Test.java](https://github.com/springdoc/springdoc-openapi/blob/master/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1Test.java).
244244

245245
### How can I customise the OpenAPI object ?
@@ -255,7 +255,7 @@ return openApi -> openApi.getPaths().values().stream().flatMap(pathItem -> pathI
255255
}
256256
```
257257

258-
### How to include` spring-boot-actuator` endpoints to Swagger Ui?
258+
### How to include` spring-boot-actuator` endpoints to Swagger UI?
259259
- In order to display `spring-boot-actuator` endpoints, you will need to add the following property:
260260
```properties
261261
springdoc.show-actuator=true
@@ -265,7 +265,7 @@ springdoc.show-actuator=true
265265
- It is be possible to handle as return an empty content as response using, one of the following syntaxes:
266266
- `content = @Content`
267267
- `content = @Content(schema = @Schema(hidden = true))`
268-
- For exmaple:
268+
- For example:
269269
```java
270270
@Operation(summary = "Get thing", responses = {
271271
@ApiResponse(description = "Successful Operation", responseCode = "200", content = @Content(mediaType = "application/json", schema = @Schema(implementation = String.class))),
@@ -312,7 +312,7 @@ ResponseEntity<String> testme() {
312312
### Differentiation to Springfox project
313313

314314
- OAS 3 was released in July 2017, and there was no release of `springfox` to support OAS 3.
315-
`springfox` covers for the moment only swagger 2 integration with Spring Boot. The lastest release date is june 2018. So, in terms of maintenance there is a big lack of support lately.
315+
`springfox` covers for the moment only swagger 2 integration with Spring Boot. The latest release date is June 2018. So, in terms of maintenance there is a big lack of support lately.
316316

317317
- We decided to move forward and share the library that we already used on our internal projects, with the community.
318318
- The biggest difference with `springfox`, is that we integrate new features not covered by `springfox`:
@@ -326,14 +326,14 @@ ResponseEntity<String> testme() {
326326
- There is no relation between `springdoc-openapi` and `springfox`.If you want to migrate to OpenAPI 3:
327327
- Remove all the dependencies and the related code to springfox
328328
- Add `springdoc-openapi-ui` dependency
329-
- If you don't want to serve the ui from your root path or there is a conflict with an existing configuration, you can just change the following property:
329+
- If you don't want to serve the UI from your root path or there is a conflict with an existing configuration, you can just change the following property:
330330
```properties
331331
springdoc.swagger-ui.path=/you-path/swagger-ui.html
332332
```
333333

334334
### How can I set a global header?
335335
- You may have global parameters with Standard OpenAPI description.
336-
- If you need the defintions to appear globally (withing every group), no matter if the group fulfills the conditions specified on the GroupedOpenApi , you can use OpenAPI Bean.
336+
- If you need the definitions to appear globally (within every group), no matter if the group fulfills the conditions specified on the GroupedOpenApi , you can use OpenAPI Bean.
337337
- You can define common parameters under parameters in the global components section and reference them elsewhere via `$ref`. You can also define global header parameters.
338338
- For this, you can override to OpenAPI Bean, and set the global headers or parameters definition on the components level.
339339
```java
@@ -386,26 +386,26 @@ public OpenAPI customOpenAPI() {
386386
.version("100")).addTagsItem(new Tag().name("mytag"));
387387
}
388388
```
389-
### Can i use spring property with swagger annotations?
389+
### Can I use spring property with swagger annotations?
390390
- The support of spring property resolver for `@Info`: `title` - `description` - `version` - `termsOfService`
391391
- The support of spring property resolver for `@Info.license`: `name` - `url`
392392
- The support of spring property resolver for `@Info.contact`: `name` - `email` - `url`
393393
- The support of spring property resolver for `@Operation`: `description` - `summary`
394394
- The support of spring property resolver for `@Parameter`: `description` - `name`
395395
- The support of spring property resolver for `@ApiResponse`: `description`
396-
- Its also possible to declare security urls for `@OAuthFlow`: `openIdConnectUrl` - `authorizationUrl` - `refreshUrl` - `tokenUrl`
396+
- Its also possible to declare security URLs for `@OAuthFlow`: `openIdConnectUrl` - `authorizationUrl` - `refreshUrl` - `tokenUrl`
397397
- The support of spring property resolver for `@Schema`: `name` - `title` - `description` , by setting `springdoc.api-docs.resolve-schema-properties` to `true`
398-
### How can i disable springdoc-openapi cache?
398+
### How can I disable springdoc-openapi cache?
399399
- By default, the OpenAPI description is calculated once, and then cached.
400-
- Sometimes the same swagger-ui is served behind internal and external proxies. some users want the server url, to be computed on each http request.
400+
- Sometimes the same swagger-ui is served behind internal and external proxies. some users want the server URL, to be computed on each http request.
401401
- In order to disable springdoc cache, you will have to set the following property:
402402
```properties
403403
springdoc.cache.disabled= true
404404
```
405405

406406

407-
### How is server url generated ?
408-
- Generating automatically server url may be useful, if the documentation is not present.
407+
### How is server URL generated ?
408+
- Generating automatically server URL may be useful, if the documentation is not present.
409409
- If the server annotations are present, they will be used instead.
410410

411411
### How can I expose the api-docs endpoints without using the `swagger-ui`?
@@ -437,18 +437,18 @@ OR
437437
@ApiResponse(responseCode = "404", description = "Not found", content = @Content)
438438
```
439439

440-
### What is the url of the `swagger-ui`, when I set a different context-path?
440+
### What is the URL of the `swagger-ui`, when I set a different context-path?
441441

442442
- If you use different context-path:
443443
```properties
444444
server.servlet.context-path= /foo
445445
```
446-
- The `swagger-ui` will be available on the following url:
446+
- The `swagger-ui` will be available on the following URL:
447447
- http://server:port/foo/swagger-ui.html
448448

449449
### Can I customize OpenAPI object programmatically?
450450

451-
- You can Define your own OpenAPI Bean: If you need the defintions to appear globally (withing every group), no matter if the group fulfills the conditions specified on the GroupedOpenApi , you can use OpenAPI Bean.
451+
- You can Define your own OpenAPI Bean: If you need the definitions to appear globally (within every group), no matter if the group fulfills the conditions specified on the GroupedOpenApi , you can use OpenAPI Bean.
452452

453453
```java
454454
@Bean
@@ -460,7 +460,7 @@ public OpenAPI customOpenAPI(@Value("${springdoc.version}") String appVersion) {
460460
.license(new License().name("Apache 2.0").url("http://springdoc.org")));
461461
}
462462
```
463-
- If you need the defintions to appear withing a specific group, and respect the conditions specified on the GroupedOpenApi, you can add OpenApiCustomiser to your GroupedOpenApi definition.
463+
- If you need the definitions to appear within a specific group, and respect the conditions specified on the GroupedOpenApi, you can add OpenApiCustomiser to your GroupedOpenApi definition.
464464

465465
```java
466466
GroupedOpenApi.builder().setGroup("users").pathsToMatch(paths).packagesToScan(packagedToMatch).addOpenApiCustomiser(customerGlobalHeaderOpenApiCustomiser())
@@ -477,7 +477,7 @@ public OpenApiCustomiser customerGlobalHeaderOpenApiCustomiser() {
477477

478478

479479
### Where can I find the source code of the demo applications?
480-
- The source code of the application is available at the following github repository:
480+
- The source code of the application is available at the following GitHub repository:
481481
- [https://github.com/springdoc/springdoc-openapi-demos.git](https://github.com/springdoc/springdoc-openapi-demos.git).
482482

483483
### Does this library supports annotations from interfaces?
@@ -530,15 +530,15 @@ springdoc.swagger-ui.url=/api-docs.yaml
530530
### My Rest Controller using @Controller annotation is ignored?
531531
- This is the default behaviour if your `@Controller` doesn't have annotation `@ResponseBody`
532532
- You can change your controllers to `@RestControllers`. Or add `@ResponseBody` + `@Controller`.
533-
- If its not possible, you can configure sprindoc to scan you additionnal controller using SpringDocUtils. For example:
533+
- If its not possible, you can configure springdoc to scan you additional controller using SpringDocUtils. For example:
534534

535535
```java
536536
static {
537537
SpringDocUtils.getConfig().addRestControllers(HelloController.class);
538538
}
539539
```
540540

541-
### How can i define groups using application.yml?
541+
### How can I define groups using application.yml?
542542
- You can load groups dynamically using spring-boot configuration files.
543543
- Note that, for this usage, you don't have to declare the **GroupedOpenApi** Bean.
544544
- You need to declare the following properties, under the prefix **springdoc.group-configs**.
@@ -551,10 +551,81 @@ springdoc.group-configs[0].packages-to-scan=test.org.springdoc.api
551551
- The list of properties under this prefix, are available here:
552552
- https://springdoc.org/springdoc-properties.html#springdoc-openapi-core-properties
553553

554-
### How can i extract fields from parameter object ?
554+
### How can I extract fields from parameter object ?
555555
- You can use springdoc annotation @ParameterObject.
556556
- Request parameter annotated with @ParameterObject will help adding each field of the parameter as a separate request parameter.
557557
- This is compatible with Spring MVC request parameters mapping to POJO object.
558558
- This annotation does not support nested parameter objects.
559559

560+
### Where can I find a tutorial of using springdoc-openapi ?
561+
- [Baeldung](https://www.baeldung.com/spring-rest-openapi-documentation)
562+
- [DZone](https://dzone.com/articles/openapi-3-documentation-with-spring-boot)
563+
- [Piotrminkowski Blog](https://piotrminkowski.com/2020/02/20/microservices-api-documentation-with-springdoc-openapi/)
564+
565+
### How to Integrate Open API 3 with Spring project (not Spring Boot)?
566+
When your application is using spring without (spring-boot), you need to add beans and auto-configuration that are natively provided in spring-boot.
567+
568+
For example, lets assume you want load the swagger-ui in spring-mvc application:
569+
570+
- You mainly, need to add the springdoc-openapi module
571+
572+
```xml
573+
<dependency>
574+
<groupId>org.springdoc</groupId>
575+
<artifactId>springdoc-openapi-ui</artifactId>
576+
<version>last.version</version>
577+
</dependency>
578+
```
579+
580+
- If you don't have the spring-boot and spring-boot-autoconfigure dependencies, you need to add them. And pay attention to the compatibility matrix, between you spring.version and spring-boot.version. For example, in this case (spring.version=5.1.12.RELEASE):
581+
582+
```xml
583+
<dependency>
584+
<groupId>org.springframework.boot</groupId>
585+
<artifactId>spring-boot</artifactId>
586+
<version>2.1.11.RELEASE</version>
587+
</dependency>
588+
<dependency>
589+
<groupId>org.springframework.boot</groupId>
590+
<artifactId>spring-boot-autoconfigure</artifactId>
591+
<version>2.1.11.RELEASE</version>
592+
</dependency>
593+
```
594+
595+
- Scan for the springdoc auto-configuration classes that spring-boot automatically loads for you.
596+
- Depending on your module, you can find them on the file: spring.factories of each springdoc-openapi module.
597+
598+
```java
599+
@EnableWebMvc
600+
public class AppInitializer implements WebApplicationInitializer {
601+
602+
@Override
603+
public void onStartup(ServletContext servletContext) throws ServletException {
604+
WebApplicationContext context = getContext();
605+
servletContext.addListener(new ContextLoaderListener(context));
606+
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("RestServlet",
607+
new DispatcherServlet(context));
608+
dispatcher.setLoadOnStartup(1);
609+
dispatcher.addMapping("/*");
610+
}
611+
612+
private AnnotationConfigWebApplicationContext getContext() {
613+
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
614+
context.scan("rest");
615+
context.register(this.getClass(), org.springdoc.ui.SwaggerConfig.class,
616+
org.springdoc.core.SwaggerUiConfigProperties.class, org.springdoc.core.SwaggerUiOAuthProperties.class,
617+
org.springdoc.core.SpringDocWebMvcConfiguration.class,
618+
org.springdoc.core.MultipleOpenApiSupportConfiguration.class,
619+
org.springdoc.core.SpringDocConfiguration.class, org.springdoc.core.SpringDocConfigProperties.class,
620+
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration.class);
621+
622+
return context;
623+
}
624+
}
625+
```
626+
627+
628+
629+
630+
560631
[back](./)

0 commit comments

Comments
 (0)