ahoque.org

Personal Blog

Follow me on GitHub

Swagger UI and Request Validator

30 Mar 2022

Swagger UI Demo

  1. Git clone project git clone https://github.com/ahoqueali/ahoqueali.github.io
  2. Cd into swagger-demo
  3. Start demo app ./gradlew bootRun
  4. Go to Swagger UI http://localhost:8080/swagger-ui.html and clink on the Try it out button
  5. Type a name that has more than 5 characters and click on the execute button

The URLs below allow access to the Swagger Specs

  1. JSON Swagger Spec http://localhost:8080/v3/api-docs/
  2. YAML Swagger Spec http://localhost:8080/v3/api-docs.yaml

alt text

Swagger Request Validator Demo

  1. Whilst the demo app is running, open a terminal and execute the following command curl http://localhost:8080/hello?name=Ross
  2. The message below will be shown.. The error is produced by the Swagger Request Validator after intercepting the request as the name cannot be less than 5 chars

alt text

See source for implementation details.

Reference

  1. Documenting a Spring REST API Using OpenAPI 3.0
  2. Swagger Request Validator