Sub topic 5
Changing paths and scanning with springdoc properties
This chapter assumes you have a Spring Boot 3 project with the springdoc starter on the classpath and a few @RestController classes. You should know how to edit application.yml and read basic URL paths. By default springdoc serves the JSON description at /v3/api-docs and Swagger UI at /swagger-ui.html. It also documents every controller it finds. Properties let you change all three behaviors without writing Java.
Moving the endpoints
The two most common properties set where the documentation lives. Both belong under the springdoc prefix.
springdoc:
api-docs:
path: /v3/api-docs
swagger-ui:
path: /swagger-ui.html
paths-to-match: /api/**springdoc.api-docs.pathis the URL of the OpenAPI JSON document.springdoc.swagger-ui.pathis the URL of the Swagger UI page.springdoc.paths-to-matchis a list of Ant-style patterns. Only endpoints whose paths match are documented.
The values above repeat the defaults for the first two properties, so only paths-to-match changes behavior. To move the documents, change the values. For example, path: /docs/openapi serves the JSON at /docs/openapi. Swagger UI reads the description from that location, so it keeps working after the move.
Limiting what gets scanned
Without a filter, springdoc documents every handler method it finds. That can include actuator-style or internal endpoints you do not want in the public description. paths-to-match is an allow list. With /api/**, a controller mapped to /api/books is documented and one mapped to /internal/cache is not.
Related properties narrow the scan in other ways:
| Property | Effect |
|---|---|
| `springdoc.paths-to-match` | Document only paths matching these patterns |
| `springdoc.paths-to-exclude` | Skip paths matching these patterns |
| `springdoc.packages-to-scan` | Document only controllers in these packages |
| `springdoc.packages-to-exclude` | Skip controllers in these packages |
Use the path-based properties when your URL layout reflects what is public. Use the package-based ones when public and internal controllers live in separate packages.
Checking the result
Start the application and request the JSON.
curl -s http://localhost:8080/v3/api-docsLook at the paths object in the response. Each documented endpoint appears as a key. If an endpoint is missing, compare its mapping against your paths-to-match patterns first. A pattern such as /api/* matches one segment, so /api/books/42 needs /api/**.
flowchart TDHow the filters combine
springdoc starts with every mapped handler. It then keeps those that match the path and package include rules, and removes those matching an exclude rule. The result is what appears in both the JSON and Swagger UI.
Common errors
- A 404 at the new path. The path property must start with
/. Also check that a servlet context path or a security rule is not blocking the new URL. - Swagger UI shows "Failed to load API definition". You changed
api-docs.pathwhile something else, such as a cached browser page, still points at the old location. Hard-reload the page. - Endpoints silently missing. A restrictive
paths-to-matchis the usual cause. The list is an allow list, so anything it does not match is dropped. - Properties ignored. Indentation errors in YAML place keys under the wrong parent. Confirm that
springdocis a top-level key.
Exercise
Your controllers are mapped under /api/books and /internal/cache. You want Swagger UI at /docs and only the /api endpoints documented. Which properties do you set?
Show answer
Set springdoc.swagger-ui.path: /docs and springdoc.paths-to-match: /api/**. Alternatively, keep all paths and set springdoc.paths-to-exclude: /internal/**.