Skip to content

Feature Request: Support for Embedded Structs in Query Parameters #2288

@Lenstack

Description

@Lenstack

Problem

Encore doesn't recognize embedded structs when parsing query parameters or generating API docs, forcing developers to duplicate common fields across every endpoint.

What doesn't work:

// shared/pagination.go
type PageRequest struct {
    Page  int `query:"page"`
    Limit int `query:"limit"`
}

// customer/dto.go
type GetCustomersRequest struct {
    shared.PageRequest  // ❌ NOT recognized - fields ignored
}

Result: page and limit don't appear in docs and aren't parsed.

Current workaround (requires duplication):

type GetCustomersRequest struct {
    Page  int `query:"page"`   // ✅ Must copy-paste in every endpoint
    Limit int `query:"limit"`  // ✅ Must copy-paste in every endpoint
}

Expected Behavior

Encore should process embedded struct fields with query: tags just like Go's standard library does:

type GetCustomersRequest struct {
    shared.PageRequest           // Should work - fields inherited
    Search string `query:"search"`
}

type GetProductsRequest struct {
    shared.PageRequest              // Reuse across all endpoints
    Category string `query:"category"`
}

All fields (including embedded) should:

  • Parse from HTTP requests
  • Appear in generated documentation
  • Work in API explorer

Impact

Without this feature:

  • 20 paginated endpoints = 40 lines of duplicated code
  • Changes to pagination require updating 20+ files
  • Easy to create inconsistencies

With this feature:

  • Define once, reuse everywhere
  • Changes propagate automatically
  • Standard Go composition patterns work as expected

Use Cases

Common reusable patterns that need this:

  • Pagination (PageRequest)
  • Filtering (FilterRequest)
  • Sorting (SortRequest)
  • Multi-tenant parameters
  • Audit metadata

Technical Note

Go's encoding/json and reflection properly handle embedded structs. Encore's compile-time code generation should do the same by recursively traversing embedded fields when analyzing request structs.


This limitation breaks Go's composition idioms and forces non-idiomatic workarounds. Supporting embedded structs would align Encore with Go conventions and significantly reduce boilerplate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions