Skip to content

Add REST API tools: client library, auth filter, validation, and tests#6

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1782312484-rest-api-tools
Open

Add REST API tools: client library, auth filter, validation, and tests#6
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1782312484-rest-api-tools

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Adds a complete set of reusable REST API tools to the petstore project:

1. REST API Client (io.swagger.petstore.client)

  • PetStoreClient — typed HTTP client wrapping all petstore endpoints (Pet, Store, User CRUD) with built-in API key auth, configurable timeouts, and ApiResponse<T> wrapper for status/body inspection
  • ApiClientConfig — builder-pattern configuration for base URL, API key, timeouts
PetStoreClient client = new PetStoreClient("http://localhost:8080/api/v3", "special-key");
ApiResponse<Pet> resp = client.getPetById(1L, Pet.class);

2. Authentication/Authorization (io.swagger.petstore.security)

  • ApiKeyAuthFilter — servlet filter validating api_key header, Authorization: Bearer, or query param; skips public endpoints (login, logout, openapi spec, OPTIONS)
  • ApiKeyStore — singleton in-memory key registry (production: swap for DB lookup)
  • SecurityContext — models OAuth2 scopes (read:pets, write:pets) for future use

3. Request Validation (io.swagger.petstore.validation)

  • RequestValidator — static validators for Pet (name required, status enum, photoUrls non-empty), Order (petId > 0, quantity > 0, status enum), User (username required, email/phone format)
  • ValidationResult — immutable error list with isValid(), getErrorMessage()

4. Tests — 74 unit tests across controllers, validation, client config, and security (JUnit 4 + Mockito)

5. Documentationdocs/API_TOOLS.md with usage examples, curl commands, and architecture overview

Dependencies added (pom.xml): JUnit 4.13.2 (test), Mockito 4.11.0 (test), javax.servlet-api 3.1.0 (provided)

Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/c056fa75403a48eb86b94db3429c5598

- Add reusable PetStoreClient with typed responses and builder config
- Add ApiKeyAuthFilter for API key and Bearer token authentication
- Add RequestValidator with validation for Pet, Order, User models
- Add comprehensive test suite (74 tests) covering all controllers,
  validation logic, client configuration, and security
- Add API_TOOLS.md documentation with usage examples and curl commands
- Add test dependencies (JUnit 4.13.2, Mockito 4.11.0, Servlet API)
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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.

0 participants