Skip to content

Add Swagger/OpenAPI 3.0 docs and interactive Swagger UI for Thomas REST API#1055

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/add-swagger-openapi-docs
Draft

Add Swagger/OpenAPI 3.0 docs and interactive Swagger UI for Thomas REST API#1055
Copilot wants to merge 2 commits into
masterfrom
copilot/add-swagger-openapi-docs

Conversation

Copilot AI commented May 1, 2026

Copy link
Copy Markdown

Thomas has no machine-readable API contract or interactive docs for its HTTP layer. This adds a static OpenAPI 3.0 spec and a CDN-backed Swagger UI served directly from the existing http4s server—no tapir or rho required.

Changes

  • http4s/src/main/resources/swagger/openapi.yaml — Full OpenAPI 3.0 spec covering all public endpoints (/users/groups/query, /health, /tests/*, /features/*) and internal management endpoints (/internal/tests CRUD), with complete schema definitions for UserGroupQuery, AbtestSpec, UserGroupQueryResult, EntityAbtest, Group, etc.

  • http4s/src/main/scala/com/iheart/thomas/http4s/SwaggerUIRoutes.scala — New HttpRoutes serving two endpoints:

    • GET /swagger/openapi.yaml — spec loaded from classpath, served as text/yaml
    • GET /swagger-ui — Swagger UI HTML loading assets from unpkg CDN, pinned to v5.17.14 with SRI integrity hashes on both <link> and <script> tags; includes a null-guard on the classpath resource load
  • http4s/src/main/scala/com/iheart/thomas/http4s/AdminUI.scala — Prepends SwaggerUIRoutes to the top-level route composition; requires only the existing MonadThrow[F] bound already on AdminUI.

  • README.md — Documents access URLs (/swagger-ui, /swagger/openapi.yaml).

Route wiring

// AdminUI.scala
private val swaggerRoutes = new SwaggerUIRoutes[F].routes

def routes(builder: WebSocketBuilder2[F]) =
  swaggerRoutes <+> authUI.publicEndpoints <+> liftService(...)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • repo.scala-sbt.org
    • Triggering command: /usr/bin/java java -Dfile.encoding=UTF8 -Xms1G -Xmx6G -XX:MaxMetaspaceSize=2G -XX:ReservedCodeCacheSize=250M -XX:&#43;TieredCompilation -XX:-UseGCOverheadLimit -Dsbt.script=/tmp/sbt/bin/sbt -Dscala.ext.dirs=/home/REDACTED/.sbt/1.0/java9-rt-ext-eclipse_adoptium_17_0_18 -jar /tmp/sbt/bin/sbt-launch.jar http4s/compile (dns block)
  • repo.typesafe.com
    • Triggering command: /usr/bin/java java -Dfile.encoding=UTF8 -Xms1G -Xmx6G -XX:MaxMetaspaceSize=2G -XX:ReservedCodeCacheSize=250M -XX:&#43;TieredCompilation -XX:-UseGCOverheadLimit -Dsbt.script=/tmp/sbt/bin/sbt -Dscala.ext.dirs=/home/REDACTED/.sbt/1.0/java9-rt-ext-eclipse_adoptium_17_0_18 -jar /tmp/sbt/bin/sbt-launch.jar http4s/compile (dns block)
  • unpkg.com
    • Triggering command: /usr/bin/curl curl -sI REDACTED (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Overview

Add Swagger/OpenAPI 3.0 documentation for the Thomas A/B testing REST API. The project uses http4s for its HTTP layer (see http4s/ module). The goal is to produce interactive Swagger UI docs and a machine-readable openapi.yaml / openapi.json spec that describes all public and internal HTTP endpoints.


Approach

Use tapir with the http4s integration (tapir-http4s-server) and the OpenAPI docs integration (tapir-openapi-docs, tapir-swagger-ui-bundle) to describe existing endpoints and serve Swagger UI.

Alternatively, if tapir is too invasive, use rho or simply write a static openapi.yaml file and serve it alongside the Swagger UI static assets. A static OpenAPI YAML approach is the least-invasive option.


Endpoints to Document

The following REST endpoints are defined in the codebase:

Public Endpoints (AbtestService)

Method Path Description
POST /users/groups/query Get group assignments for a user given a UserGroupQuery
GET /health Health check, returns {"status":"healthy","version":"..."}
GET /tests/history/{at} Get all tests as of epoch seconds at
GET /tests/{endAfter} Get all tests ending after epoch endAfter
GET /tests Get all tests, optional at (epoch ms) and endAfter query params
GET /testsWithFeatures Get cached tests with features, optional at query param
GET /testsData Get tests data for a time window (atEpochMilli, durationMillisecond)
GET /tests/{testId} Get a single test by ID
GET /tests/cache Get cached tests, optional at query param
GET /features Get all feature names
GET /features/{feature}/tests Get tests for a feature
GET /features/{feature}/overrides Get overrides for a feature

Internal / Management Endpoints (AbtestManagementService, auth-protected)

Method Path Description
POST /internal/tests Create a new A/B test (AbtestSpec), optional ?auto=true
POST /internal/tests/auto Create a new A/B test with auto=true
PUT /internal/tests Continue/update an existing A/B test (AbtestSpec)
DELETE /internal/tests/{testId} Terminate a test by ID

Key Data Models

All models live in core/src/main/scala/com/iheart/thomas/abtest/model/package.scala.

UserGroupQuery (POST body for /users/groups/query)

{
  "userId": "string | null",
  "at": "ISO-8601 datetime | null",
  "tags": ["string"],
  "meta": { "key": "value" },
  "features": ["featureName"],
  "eligibilityControlFilter": "All | On | Off"
}

AbtestSpec (POST/PUT body for test creation)

{
  "name": "string",
  "feature": "string",
  "author": "string",
  "start": "ISO-8601 datetime",
  "end": "ISO-8601 datetime | null",
  "groups": [
    { "name": "string", "size": 0.5, "meta": {}, "description": "string | null" }
  ],
  "requiredTags": ["string"],
  "alternativeIdName": "string | null",
  "userMetaCriteria": "object | null",
  "reshuffle": false,
  "segmentRanges": [{ "start": 0.0, "end": 1.0 }],
  "specialization": "MultiArmBandit | null",
  "note": "string | null"
}

UserGroupQueryResult (response)

{
  "at": "epoch millis",
  "groups": { "featureName": "groupName" },
  "meta": {}
}

Entity[Abtest] (response)

{
  "_id": "string",
  "data": { /* Abtest fields same as AbtestSpec but with ranges and salt */ }
}

Implementation Tasks

  1. Add a static openapi.yaml file to http4s/src/main/resources/swagger/openapi.yaml (or at the project root as docs/openapi.yaml) documenting all endpoints above with request/response schemas.

  2. Serve Swagger UI — Add a new SwaggerUIRoutes http4s service in http4s/src/main/scala/com/iheart/thomas/http4s/SwaggerUIRoutes.scala that:

    • Serves the openapi.yaml at GET /swagger/openapi.yaml
    • Serves the Swagger UI HTML at GET /swagger-ui using swagger-ui webjars or inline HTML pointing to a CDN.
  3. Wire up the new routes into AdminUI.scala so Swagger UI is accessible when running the server.

  4. Add swagger-ui webjar dependency to build.sbt (or project/Dependencies.scala):

    "org.webjars" % "swagger-ui" % "5.17.14"
    // or use http4s-swagger from tapir if already preferred
  5. Update README.md with a note on how to access the Swagger UI (e.g., http://localhost:8080/swagger-ui).


File locations in the repo

  • HTTP routes: http4s/src/main/scala/com/iheart/thomas/http4s/abtest/AbtestService.scala
  • Management routes: http4s/src/main/scala/com/iheart/thomas/http4s/abtest/AbtestManagementService.scala
  • Server wiring: `http4s/src/main/scala/com/ihear...

This pull request was created from Copilot chat.

@orca-security-us orca-security-us Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

@orca-security-us orca-security-us Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Failed Failed Infrastructure as Code high 1   medium 1   low 35   info 25 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca
🛡️ The following IaC misconfigurations have been detected
NAME FILE
medium Global Server Object Uses HTTP ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response Code Missing (v3) ...swagger/openapi.yaml View in code
low Response on operations that should have a body has undefined schema ...swagger/openapi.yaml View in code
low Response on operations that should have a body has undefined schema ...swagger/openapi.yaml View in code
info Empty Array ...swagger/openapi.yaml View in code
info Empty Array ...swagger/openapi.yaml View in code
info Empty Array ...swagger/openapi.yaml View in code
info Empty Array ...swagger/openapi.yaml View in code
info Path Is Ambiguous ...swagger/openapi.yaml View in code
info Path Is Ambiguous ...swagger/openapi.yaml View in code
... ... ... ...

Copilot AI changed the title [WIP] Add Swagger/OpenAPI 3.0 documentation for Thomas A/B testing API Add Swagger/OpenAPI 3.0 docs and interactive Swagger UI for Thomas REST API May 1, 2026
Copilot finished work on behalf of lofoyet May 1, 2026 23:43
Copilot AI requested a review from lofoyet May 1, 2026 23:43
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.

2 participants