Skip to content

Create static response types#21

Merged
LightJack05 merged 4 commits intomainfrom
static-response-types
Jan 28, 2026
Merged

Create static response types#21
LightJack05 merged 4 commits intomainfrom
static-response-types

Conversation

@LightJack05
Copy link
Member

No description provided.

@LightJack05 LightJack05 self-assigned this Jan 28, 2026
Copilot AI review requested due to automatic review settings January 28, 2026 13:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Introduces typed (static) response payload structs for product endpoints and updates the generated OpenAPI artifacts to use a shared handlers.Error schema for error responses.

Changes:

  • Added dedicated response wrapper structs for product-by-id and product-search handlers, and switched handlers to return these types instead of gin.H.
  • Updated Swagger (yaml/json/docs.go) to define and reference handlers.Error for 4xx/5xx responses on the product endpoints.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/handlers/product/getId.go Adds a typed response wrapper for the 200 payload and uses it in c.JSON.
internal/handlers/product/get.go Adds a typed response wrapper for the 200 payload and uses it in c.JSON.
docs/swagger.yaml Adds handlers.Error definition and refs it for error responses.
docs/swagger.json Adds handlers.Error definition and refs it for error responses.
docs/docs.go Updates generated Swagger template to include handlers.Error definition and refs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +12 to +14
type getProductByIdResponse struct {
Product product.Product `json:"product"`
}
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

getProductByIdResponse uses Id in the type name; in Go initialisms are typically capitalized (e.g., ID). Renaming to getProductByIDResponse would also align with GetProductByID used below.

Copilot uses AI. Check for mistakes.
}

c.JSON(http.StatusOK, gin.H{"product": product})
c.JSON(http.StatusOK, getProductByIdResponse{Product: *product})
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

This copies the entire product.Product struct (*product) into the response. Since product.Product is large, prefer returning a pointer in the response type (e.g., make the field *product.Product and set it to product) to avoid an extra full-struct copy per request.

Copilot uses AI. Check for mistakes.
}

c.JSON(http.StatusOK, gin.H{"product": product})
c.JSON(http.StatusOK, getProductByIdResponse{Product: *product})
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The handler now returns getProductByIdResponse, but the Swagger annotation still documents the 200 response as map[string]product.Product (@Success 200 ...). Update the @Success type to the new response struct so generated OpenAPI matches the actual response body.

Copilot uses AI. Check for mistakes.
}

c.JSON(http.StatusOK, gin.H{"products": products})
c.JSON(http.StatusOK, productGetResponse{Products: *products})
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The handler now returns productGetResponse, but the Swagger annotation still documents the 200 response as map[string][]product.Product (@Success 200 ...). Update the @Success type to the new response struct so generated OpenAPI matches the actual response body.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings January 28, 2026 13:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +12 to +14
type getProductByIdResponse struct {
Product product.Product `json:"product"`
}
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

getProductByIdResponse stores product.Product by value, which forces a full struct copy when building the response (*product). product.Product is very large (see internal/database/product/product.go), so this adds avoidable per-request copying. Prefer making the field a pointer (e.g., *product.Product) and returning the pointer directly to avoid the copy and keep behavior consistent with the previous gin.H{"product": product}.

Copilot uses AI. Check for mistakes.
@LightJack05 LightJack05 merged commit 9c06589 into main Jan 28, 2026
12 checks passed
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.

1 participant