Skip to content

Enhancement: Allow overriding generic types via map-types in .kommentaar#106

Merged
marcizhu merged 1 commit intomasterfrom
enhancement/generic-types-map
Apr 21, 2026
Merged

Enhancement: Allow overriding generic types via map-types in .kommentaar#106
marcizhu merged 1 commit intomasterfrom
enhancement/generic-types-map

Conversation

@marcizhu
Copy link
Copy Markdown
Member

Generic types were unconditionally generated as type: object, which is incorrect in Swagger 2.0 when the type is semantically a primitive (e.g. a GroupBy[string] wrapper that should appear as type: string). Regular (non-generic) types already supported this via the map-types config section. This PR closes the gap for generic types.

How it works

The lookup follows a two-level priority:

  1. Full instantiated key: matches a specific parameterisation: pkg.Foo[Bar]
  2. Main type fallback: matches all instantiations of a generic: pkg.Foo

Example config:

map-types
    pkg.Wrapper[string]    string    # only Wrapper[string] → string
    pkg.GroupBy            string    # all GroupBy[*] → string

map-format works the same way, so format overrides (e.g. date-time) are also supported for generic types.

Changes

  • docparse/jsonschema.go: added genericMapTypeLookup (checks both key levels before falling through to struct expansion) and applyMapType (shared helper that eliminates duplicated type-assignment blocks)
  • docparse/docparse.go: MapType now skips the format lookup when no type mapping is found
  • testdata/openapi2/src/generics-map-types/: integration test covering full-key match, main-key fallback, format override, and unmapped (object expansion) cases

@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 24665618788

Coverage decreased (-1.1%) to 51.758%

Details

  • Coverage decreased (-1.1%) from the base build.
  • Patch coverage: 42 uncovered changes across 1 file (3 of 45 lines covered, 6.67%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
docparse/jsonschema.go 42 0 0.0%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
docparse/docparse.go 1 69.16%

Coverage Stats

Coverage Status
Relevant Lines: 2162
Covered Lines: 1119
Line Coverage: 51.76%
Coverage Strength: 43.76 hits per line

💛 - Coveralls

@marcizhu marcizhu merged commit eb685b6 into master Apr 21, 2026
3 checks passed
@marcizhu marcizhu deleted the enhancement/generic-types-map branch April 21, 2026 08:52
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.

3 participants