feat: add configurable type mapping for OpenAPI primitive types#2223
Merged
mromaszewicz merged 4 commits intooapi-codegen:mainfrom Feb 16, 2026
Merged
feat: add configurable type mapping for OpenAPI primitive types#2223mromaszewicz merged 4 commits intooapi-codegen:mainfrom
mromaszewicz merged 4 commits intooapi-codegen:mainfrom
Conversation
jamietanna
reviewed
Feb 15, 2026
jamietanna
reviewed
Feb 15, 2026
Member
jamietanna
left a comment
There was a problem hiding this comment.
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!
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>
e70edf7 to
8479cdd
Compare
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
jamietanna
approved these changes
Feb 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: