Skip to content

feat: add configurable type mapping for OpenAPI primitive types#2223

Merged
mromaszewicz merged 4 commits intooapi-codegen:mainfrom
mromaszewicz:feat/primitive-mapping
Feb 16, 2026
Merged

feat: add configurable type mapping for OpenAPI primitive types#2223
mromaszewicz merged 4 commits intooapi-codegen:mainfrom
mromaszewicz:feat/primitive-mapping

Conversation

@mromaszewicz
Copy link
Copy Markdown
Member

Supersedes #428, since the original author's branch is gone and his PR only exists in the ref log.

Added a TypeMapping configuration that lets users override the default OpenAPI type/format to Go type mappings. User-specified mappings are merged on top of built-in defaults, so only overrides need to be specified. For example, mapping string/date-time to a civil.DateTime or changing the default integer type to int64.

Changes:

  • New TypeMapping, FormatMapping, SimpleTypeSpec types with Merge() and Resolve() methods (pkg/codegen/typemapping.go)
  • TypeMapping field added to Configuration struct
  • Merged type mapping stored on globalState, initialized in Generate()
  • Replaced hardcoded switch statements in oapiSchemaToGoType() with map-based lookups via globalState.typeMapping
  • Updated configuration-schema.json with type-mapping property and reusable $defs for format-mapping and simple-type-spec
  • Unit tests for merge, resolve, and default mapping completeness

Copy link
Copy Markdown
Member

@jamietanna jamietanna left a comment

Choose a reason for hiding this comment

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

Can we please add an examples entry for this? To show what it looks like end-to-end? Once done, LGTM

I was wondering if there were any other options this may crossover with, but looks like not

I like that we've started with primitive types, but in the future, we could extend this for other types!

@jamietanna jamietanna added this to the v2.6.0 milestone Feb 15, 2026
mromaszewicz and others added 3 commits February 15, 2026 07:07
Supersedes oapi-codegen#428, since the original author's branch is gone and
his PR only exists in the ref log.

Added a TypeMapping configuration that lets users override the default
OpenAPI type/format to Go type mappings. User-specified mappings are
merged on top of built-in defaults, so only overrides need to be
specified. For example, mapping string/date-time to a civil.DateTime
or changing the default integer type to int64.

Changes:
- New TypeMapping, FormatMapping, SimpleTypeSpec types with Merge()
  and Resolve() methods (pkg/codegen/typemapping.go)
- TypeMapping field added to Configuration struct
- Merged type mapping stored on globalState, initialized in Generate()
- Replaced hardcoded switch statements in oapiSchemaToGoType() with
  map-based lookups via globalState.typeMapping
- Updated configuration-schema.json with type-mapping property and
  reusable $defs for format-mapping and simple-type-spec
- Unit tests for merge, resolve, and default mapping completeness

Co-Authored-By: natsukagami <natsukagami@gmail.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mromaszewicz mromaszewicz force-pushed the feat/primitive-mapping branch from e70edf7 to 8479cdd Compare February 15, 2026 15:24
@mromaszewicz
Copy link
Copy Markdown
Member Author

Simple example added.

Once I'm done with behavioral additions, I intend to make a detailed document about all the options, linking to examples. Our configuration is under-documented.

Move type-mapping examples to output-options
@mromaszewicz mromaszewicz merged commit c6bc7c5 into oapi-codegen:main Feb 16, 2026
26 checks passed
@jamietanna jamietanna added the enhancement New feature or request label Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants