Skip to content

feat(params): support unspecified type parameters#1583

Merged
ernado merged 1 commit intoogen-go:mainfrom
lanej:support-any-type-parameters
Nov 24, 2025
Merged

feat(params): support unspecified type parameters#1583
ernado merged 1 commit intoogen-go:mainfrom
lanej:support-any-type-parameters

Conversation

@lanej
Copy link
Contributor

@lanej lanej commented Nov 24, 2025

Summary

This PR adds support for OpenAPI parameters with no type specified (schema: {}). Previously, these parameters would cause "any type parameter not supported" errors. Now they are represented as Go any type.

Motivation

OpenAPI allows parameters to have schemas with no type field specified, which means the parameter can be of any type. ogen was rejecting these with an error, making it impossible to work with specs that use this pattern (common in legacy APIs or APIs with dynamic parameter types).

Implementation

Core Changes (5 files, 21 lines changed):

  1. gen/_template/uri/decode.tmpl - Added IsAny case to decode URI strings into Go any type
  2. gen/_template/uri/encode.tmpl - Added IsAny case with nil check, uses fmt.Sprint() for encoding
  3. gen/gen_parameters.go - Removed error case that rejected any type parameters
  4. gen/ir/type.go - Added feature check to return "any" for URI contexts vs "jx.Raw" for JSON bodies
  5. README.md - Documented the feature

Design Decisions:

  • Go any type: More semantically accurate than forcing to string - if the schema says "any", the Go type should be any
  • Client encoding: Uses fmt.Sprint() for flexibility (allows passing strings, ints, bools, etc.)
  • Context differentiation: JSON bodies use jx.Raw, URI parameters use any (different serialization contexts)
  • No smart parsing: Keeps implementation simple - server receives string, client can send any value that fmt.Sprint can handle

Test Coverage

  • _testdata/positive/any_parameters.json - Comprehensive OpenAPI test spec
  • internal/integration/any_parameters_test.go - Full integration test covering:
    • Required parameters (path, query, header, cookie)
    • Optional parameters
    • Array parameters
    • Nil handling

Breaking Changes

None - this is purely additive. Existing code continues to work unchanged.

Example Usage

Server side:

func (h *Handler) AnyParams(ctx context.Context, params api.AnyParamsParams) (*api.AnyParamsOK, error) {
    // Type assert the any value
    queryStr := params.Query.(string)
    
    if params.Filter != nil {
        filterStr := params.Filter.(string)
        // Use optional filter...
    }
    
    return &api.AnyParamsOK{Message: "ok"}, nil
}

Client side:

// Can pass different types - all will be encoded via fmt.Sprint()
client.AnyParams(ctx, api.AnyParamsParams{
    Query: "search text",      // string
    ID: 123,                   // int
    Filter: api.OptAny(true),  // bool
})

Add support for OpenAPI parameters with no type specified
(schema: {}) by representing them as Go `any` type.

Parameters are decoded as strings from URIs and encoded using
fmt.Sprint() on client side. Updates IR type system to return
"any" for URI contexts instead of "jx.Raw" for JSON contexts.

Includes integration tests and documentation.
lanej added a commit to lanej/ogen that referenced this pull request Nov 24, 2025
Merged from ogen-go/ogen PR ogen-go#1583 which adds support for OpenAPI
parameters with no type specified (schema: {}). These parameters are
now represented as Go 'any' type instead of causing errors.

Key changes:
- Added IsAny case to URI decode/encode templates
- Updated gen_parameters.go to allow any type parameters
- Added feature check in ir/type.go for URI contexts
- Resolved conflicts with existing IsSum support
- Updated all imports to use github.com/lanej/ogen module path
- Regenerated all code and updated golden files

Co-authored-by: Josh Lane <lanej@gmail.com>
@ernado ernado merged commit 5a625df into ogen-go:main Nov 24, 2025
21 of 22 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.

2 participants