Skip to content

feat: Get Extension Information Endpoint - BED-6897#2282

Merged
kpowderly merged 8 commits intomainfrom
BED-6897
Jan 29, 2026
Merged

feat: Get Extension Information Endpoint - BED-6897#2282
kpowderly merged 8 commits intomainfrom
BED-6897

Conversation

@kpowderly
Copy link
Contributor

@kpowderly kpowderly commented Jan 22, 2026

Description

Get Extension Info

  • Add GET capability to the extensions endpoint
  • Returns extension id
  • Returns extension display name (for display)
  • Returns extension version
  • Returns default to sort results by extension name in ascending order

Motivation and Context

Resolves BED-6897

Ability to make HTTP call to get extension info

How Has This Been Tested?

Unit tests & http call
curl --request GET \ --url http://bhe.localhost/api/v2/extensions \ --header 'authorization: Bearer {{TOKEN}}

Screenshots (optional):

Screenshot 2026-01-22 at 2 28 32 PM

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

Summary by CodeRabbit

  • New Features

    • New authenticated GET /api/v2/extensions endpoint returning a JSON list of extensions (ID, name, version).
    • PUT /api/v2/extensions now requires authentication.
  • Tests

    • Added tests covering listing and ingest endpoints, including success and error scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

@kpowderly kpowderly self-assigned this Jan 22, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

Walkthrough

Adds authenticated GET /api/v2/extensions to list OpenGraph schema extensions, applies authentication to PUT /api/v2/extensions, implements service and repository hooks, updates structs/mocks, and adds API and service tests.

Changes

Cohort / File(s) Summary
Route Registration
cmd/api/src/api/registration/v2.go
PUT /api/v2/extensions now requires auth; new authenticated GET /api/v2/extensions bound to ListExtensions.
API Layer Types & Handlers
cmd/api/src/api/v2/model.go, cmd/api/src/api/v2/opengraphschema.go
Exported OpenGraphSchemaService field on Resources; added ExtensionsResponse and ExtensionInfo types; added Resources.ListExtensions handler; extended OpenGraphSchemaService interface with ListExtensions.
Service Implementation
cmd/api/src/services/opengraphschema/extension.go
Implemented ListExtensions(ctx) to call repository GetGraphSchemaExtensions, sort by display_name, and map results to v2.ExtensionInfo.
Repository Interface
cmd/api/src/services/opengraphschema/opengraphschema.go
Added GetGraphSchemaExtensions(ctx, extensionFilters, sort, skip, limit) signature to repository interface.
Mocks
cmd/api/src/api/v2/mocks/graphschemaextensions.go, cmd/api/src/services/opengraphschema/mocks/opengraphschema.go
Added mock methods and recorder signatures for ListExtensions (service) and GetGraphSchemaExtensions (repository).
Tests
cmd/api/src/api/v2/opengraphschema_test.go, cmd/api/src/services/opengraphschema/extension_test.go
Added API tests for PUT/GET endpoints (error and success cases) and service tests for ListExtensions (error, single, multi-extension cases).
Module manifest
go.mod
Minor manifest adjustments (lines changed: +3/-1).

Sequence Diagram(s)

sequenceDiagram
  participant Client as Client
  participant API as API (v2)
  participant Service as OpenGraphSchemaService
  participant Repo as OpenGraphSchemaRepository
  participant DB as Database

  Client->>API: GET /api/v2/extensions (Auth)
  API->>API: RequireAuth() middleware (validate token)
  API->>Service: ListExtensions(ctx)
  Service->>Repo: GetGraphSchemaExtensions(ctx, filters, sort, 0, 0)
  Repo->>DB: Query extensions (ORDER BY display_name)
  DB-->>Repo: rows
  Repo-->>Service: model.GraphSchemaExtensions
  Service-->>API: []v2.ExtensionInfo
  API-->>Client: 200 OK { "extensions": [...] }
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

enhancement, api

Suggested reviewers

  • AD7ZJ
  • LawsonWillard
  • wes-mil

Poem

🐰 I hopped through code with nimble paws,
New endpoints stitched without a pause,
Auth guards the path, extensions parade,
Services fetch what models made,
Tests clap softly—hooray for laws! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically identifies the main change: adding a GET Extension Information endpoint with the associated Jira ticket reference.
Description check ✅ Passed The description is mostly complete with detailed explanation of changes, motivation, testing approach, and properly completed checklist items for a new feature.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kpowderly kpowderly marked this pull request as ready for review January 22, 2026 21:25
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@cmd/api/src/api/v2/opengraphschema.go`:
- Around line 95-97: The error string passed to api.WriteErrorResponse in the
block handling s.OpenGraphSchemaService.ListExtensions uses "error listing graph
schema extensions" which mismatches the test expectation; update the error
message passed (the fmt.Sprintf call) to "error getting graph schema extensions"
so the handler (in the code path calling s.OpenGraphSchemaService.ListExtensions
and api.WriteErrorResponse) matches opengraphschema_test.go.

In `@cmd/api/src/services/opengraphschema/extension.go`:
- Around line 74-82: The slice apiExtensions is allocated using count which may
differ from the actual length of extensions and can cause zero-values or panics;
change the allocation to use len(extensions) instead of count so apiExtensions
:= make([]v2.ExtensionInfo, len(extensions)) and keep the existing loop that
assigns into apiExtensions by index (refer to apiExtensions, extensions, count,
and v2.ExtensionInfo in extension.go).
🧹 Nitpick comments (5)
cmd/api/src/services/opengraphschema/extension_test.go (1)

410-416: Swap assert.Equal argument order for clarity.

The assert.Equal function in testify expects (t, expected, actual) but the calls here have (t, actual, expected). While testify's comparison still works correctly, the failure messages will show swapped values which can be confusing during debugging.

♻️ Suggested fix
 		if tt.expected.err != nil {
 			assert.EqualError(t, err, tt.expected.err.Error())
-			assert.Equal(t, res, tt.expected.extensions)
+			assert.Equal(t, tt.expected.extensions, res)
 		} else {
 			assert.NoError(t, err)
-			assert.Equal(t, res, tt.expected.extensions)
+			assert.Equal(t, tt.expected.extensions, res)
 		}
cmd/api/src/api/v2/opengraphschema_test.go (2)

279-279: Minor: Use http.MethodGet constant for consistency.

Line 168 uses http.MethodPut, but this line uses the string literal "GET". Consider using http.MethodGet for consistency.

Suggested fix
-			router.HandleFunc("/api/v2/extensions", resources.ListExtensions).Methods("GET")
+			router.HandleFunc("/api/v2/extensions", resources.ListExtensions).Methods(http.MethodGet)

202-259: Consider adding a test case for empty extensions list.

The tests cover error and success (with data) paths, but an edge case for successfully returning an empty list would increase coverage and verify the response is {"extensions":[]} rather than {"extensions":null}.

cmd/api/src/api/v2/opengraphschema.go (2)

84-88: Consider using ID instead of Id per Go naming conventions.

Go convention recommends keeping acronyms in all caps for exported identifiers (e.g., ID, URL, HTTP). The JSON tag ensures the output remains "id".

Suggested fix
 type ExtensionInfo struct {
-	Id      string `json:"id"`
+	ID      string `json:"id"`
 	Name    string `json:"name"`
 	Version string `json:"version"`
 }

Note: This change would require updates to the test file and any code that references ExtensionInfo.Id.


90-101: Handler implementation is functional, consider early-return pattern for consistency.

The if-else where the success path is in else could use an early return pattern for better readability, though this is a minor stylistic preference.

Alternative with early return pattern
 func (s Resources) ListExtensions(response http.ResponseWriter, request *http.Request) {
-	var (
-		ctx = request.Context()
-	)
+	ctx := request.Context()
 
-	if extensions, err := s.OpenGraphSchemaService.ListExtensions(ctx); err != nil {
+	extensions, err := s.OpenGraphSchemaService.ListExtensions(ctx)
+	if err != nil {
 		api.WriteErrorResponse(ctx, api.BuildErrorResponse(http.StatusInternalServerError, fmt.Sprintf("error getting graph schema extensions: %v", err), request), response)
 		return
-	} else {
-		api.WriteJSONResponse(ctx, ExtensionsResponse{Extensions: extensions}, http.StatusOK, response)
 	}
+	api.WriteJSONResponse(ctx, ExtensionsResponse{Extensions: extensions}, http.StatusOK, response)
 }

@kpowderly kpowderly merged commit 54a73c9 into main Jan 29, 2026
13 checks passed
@kpowderly kpowderly deleted the BED-6897 branch January 29, 2026 19:06
@github-actions github-actions bot locked and limited conversation to collaborators Jan 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants