Skip to content

v2: Implement HTTP transport layer — replace swagger-generated code #88

@oss-amikos

Description

@oss-amikos

Context

Currently the client relies on Swagger/OpenAPI codegen for the HTTP layer. We want to own the HTTP transport entirely — fewer dependencies, full control over serialization, better error handling.

Related: #43 (Move away from swagger generated APIs)

Requirements

Internal HttpClient

A package-private HTTP client that the Client and Collection implementations use. NOT part of the public API.

// Package-private
class HttpTransport implements AutoCloseable {
    // Core HTTP methods
    <T> T get(String path, Class<T> responseType);
    <T> T get(String path, TypeToken<T> responseType);  // for generics
    <T> T post(String path, Object body, Class<T> responseType);
    <T> T post(String path, Object body, TypeToken<T> responseType);
    void delete(String path);
    <T> T put(String path, Object body, Class<T> responseType);

    void close();
}

Dependencies

  • OkHttp — HTTP client (keep, it's solid)
  • Gson — JSON serialization (keep, already in use)
  • Remove — swagger-codegen-maven-plugin, swagger annotations, all generated code

Serialization

  • Use Gson TypeToken for generic types (e.g., List<CollectionModel>) — this fixes the generic deserialization bugs in PR [TST] Add v2 API #80
  • Register custom Gson type adapters for:
    • Where → JSON map
    • WhereDocument → JSON map
    • Include enum ↔ string
    • DistanceFunction enum ↔ string
  • All request/response objects use Gson @SerializedName where field names differ from Java convention

Error Handling

URL Building

  • Proper URL construction — no string concatenation for query parameters
  • URL-encode path segments and query values
  • Base path: /api/v2

Acceptance Criteria

  • HttpTransport class with get/post/delete/put methods
  • Generic deserialization via TypeToken
  • Custom Gson type adapters for Where, WhereDocument, Include, DistanceFunction
  • Error response parsing and exception mapping
  • Proper URL building with encoding
  • Configurable timeouts via OkHttp
  • Auth header injection via AuthProvider
  • Default headers support
  • Remove swagger-codegen from pom.xml
  • Remove all generated source code dependencies

Depends On

Supersedes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions