Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update and configure SpringDoc Open API and Swagger #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

timler
Copy link
Collaborator

@timler timler commented Nov 18, 2024

Set up SpringDoc to enable Swagger UI for local API exploration and testing.

About the changes:

This allows:

  • Interactive API testing via Swagger UI at /swagger-ui.html
  • OpenAPI spec download in JSON (/api-docs) or YAML (/api-docs.yaml) format which will be used to generate API documentation.

Added OpenAPI annotations to JwtAuthenticationRestController to support authentication through the Swagger UI, which is needed to use the other endpoints.

Added documentation to the endpoints to specify

  • Name tags for each controller
  • Descriptions for all the endpoints
  • Definitions for all the parameters, the request body, and the return status codes and response body

Both the API docs and Swagger UI can be disabled via application properties:

springdoc.api-docs.enabled=false
springdoc.swagger-ui.enabled=false

Usage

Access the Swagger UI at:

Access the OpenAPI spec at:

Authenticate

To use the API, you need to authenticate. To do so, follow these steps:

To get an access token:

  1. Scroll to jwt-authentication-rest-controller
  2. Open the Post /authenticate endpoint
  3. Click "Try it out"
  4. Enter your login details
  5. Click "Execute"

To use the token to authenticate your requests:

  1. Scroll to the top, click "Authorize" button
  2. Enter token
  3. Click "Authorise"

Now you can use the Swagger API endpoints

Set up SpringDoc to enable Swagger UI for local API exploration
and testing.

This allows:
- Interactive API testing via Swagger UI at /swagger-ui.html
- OpenAPI spec download in JSON (/api-docs) or YAML
  (/api-docs.yaml) format which will be used to generate API
   documentation.

Added OpenAPI annotations to JwtAuthenticationRestController to
support authentication through the Swagger UI, which is needed
to use the other endpoints.

Both the API docs and Swagger UI can be disabled via application
properties:
springdoc.api-docs.enabled=false
springdoc.swagger-ui.enabled=false
Added more files that shouldn't be committed to the repository to
avoid any accidental commits
Added API documentation to the REST endpoints to enable us to use
Swagger effectively.
Edited the annotations for the Swagger documentation to add documentation
for new methods and to make endpoint summaries more succinct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant