OpenAPI Documentation¶
Interactive API documentation using OpenAPI 3.0 and Swagger UI.
Accessing OpenAPI Documentation¶
Once the server is running, access the interactive documentation:
Swagger UI¶
Interactive API explorer with try-it-out functionality:
OpenAPI Specification¶
Raw OpenAPI 3.0 specification in JSON format:
Exporting the OpenAPI Specification¶
To add this API to Orchestrate or other tools, you need to export the OpenAPI specification file.
Download the spec using curl (recommended):
This creates an openapi.json file in your current directory.
Download via web browser:
- Start the server:
mvn liberty:dev - Open your browser to:
http://localhost:9080/openapi - Right-click and select "Save Page As..."
- Save as
openapi.json
Export from Swagger UI:
- Navigate to
http://localhost:9080/openapi/ui - Look for the OpenAPI spec link at the top of the page
- Right-click and "Save Link As..."
- Save as
openapi.json
Create a script to export automatically:
#!/bin/bash
# export-openapi.sh
# Wait for server to be ready
echo "Waiting for server to start..."
until curl -s http://localhost:9080/openapi > /dev/null; do
sleep 2
done
# Export the spec
echo "Exporting OpenAPI specification..."
curl http://localhost:9080/openapi -o openapi.json
echo "OpenAPI spec exported to openapi.json"
Make it executable and run:
Verify the Export¶
Check that the file contains valid JSON:
Or view the OpenAPI version:
Expected output: "3.0.3" or similar.
Using the Spec with Orchestrate¶
Once exported, you can:
- Import to Orchestrate - Use the
openapi.jsonfile to register your API - Version Control - Commit the spec to your repository for tracking changes
- API Documentation - Share with team members or external consumers
- Code Generation - Use tools like OpenAPI Generator to create client SDKs
Using Swagger UI¶
- Open Swagger UI at
http://localhost:9080/openapi/ui - Explore Endpoints - Click on any endpoint to see details
- Try It Out - Click "Try it out" button
- Authenticate - Click "Authorize" and enter your JWT token
- Execute - Fill in parameters and click "Execute"
Authentication in Swagger UI¶
- Click the "Authorize" button (lock icon)
- Enter your JWT token in the format:
Bearer YOUR_TOKEN - Click "Authorize"
- Click "Close"
Now you can test protected endpoints.
Getting a Token for Testing¶
curl -X POST http://localhost:8080/realms/secure-test/protocol/openid-connect/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=authentication-test-api" \
-d "client_secret=YOUR_SECRET" \
-d "grant_type=password" \
-d "username=testuser1" \
-d "password=password123" \
| jq -r '.access_token'
Copy the token and use it in Swagger UI.
OpenAPI Annotations¶
The API uses MicroProfile OpenAPI annotations for documentation:
@Operation(
summary = "Get user schedule",
description = "Retrieve the authenticated user's schedule"
)
@APIResponses({
@APIResponse(
responseCode = "200",
description = "Schedule retrieved successfully"
)
})