Skip to content

Reject import-mapping keys that are JSON pointers#2461

Merged
mromaszewicz merged 1 commit into
mainfrom
fix/issue-2459
Jul 13, 2026
Merged

Reject import-mapping keys that are JSON pointers#2461
mromaszewicz merged 1 commit into
mainfrom
fix/issue-2459

Conversation

@mromaszewicz

Copy link
Copy Markdown
Member

Closes: #2459

import-mapping keys are the paths of $ref'd documents — a relative file path or a URL — but users occasionally write a JSON pointer like "#/components/schemas" expecting internal references to be remapped to another Go package (seen in #2078). Such an entry can never match anything, since same-document references always resolve to the package being generated, so the user just sees unresolved types with no hint of the misconfiguration.

Configuration validation now rejects keys starting with "#" with an error explaining what keys must be and pointing at the import-mapping examples. This is an error rather than a warning because warnings are emitted to stderr and easily lost when generation output goes to stdout, and there is no legitimate configuration this rejects.

The README's Import Mapping section gains a note stating the same up front: keys are document paths, internal refs cannot be remapped, and schemas wanted in a separate package should be split into their own spec file.

Closes: #2459

import-mapping keys are the paths of $ref'd documents — a relative file
path or a URL — but users occasionally write a JSON pointer like
"#/components/schemas" expecting internal references to be remapped to
another Go package (seen in #2078). Such an entry can never match
anything, since same-document references always resolve to the package
being generated, so the user just sees unresolved types with no hint of
the misconfiguration.

Configuration validation now rejects keys starting with "#" with an
error explaining what keys must be and pointing at the import-mapping
examples. This is an error rather than a warning because warnings are
emitted to stderr and easily lost when generation output goes to stdout,
and there is no legitimate configuration this rejects.

The README's Import Mapping section gains a note stating the same up
front: keys are document paths, internal refs cannot be remapped, and
schemas wanted in a separate package should be split into their own spec
file.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mromaszewicz
mromaszewicz requested a review from a team as a code owner July 13, 2026 01:20
@greptile-apps

greptile-apps Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a validation guard in Configuration.Validate() that rejects import-mapping keys beginning with "#", which are JSON pointers and can never match an external $ref path. The README's Import Mapping section is updated with a NOTE callout explaining the same constraint up front.

  • pkg/codegen/configuration.go: Loops over ImportMapping keys after the existing sub-validator calls and appends a descriptive error for any key starting with "#", pointing users to the examples directory.
  • pkg/codegen/configuration_test.go: New unit test covering rejection of "#/components/schemas" and acceptance of relative paths, absolute URLs, and the "-" sentinel value.
  • README.md: Adds a NOTE admonition explaining that keys are document paths, not JSON pointers, and describes the workaround of splitting schemas into a separate spec file.

Confidence Score: 5/5

Safe to merge — the change adds a new hard error only for configurations that were previously silently broken anyway, and no struct fields or generated output are touched.

The validation change is surgical: it only affects Validate(), not any struct definitions or code-generation paths. No existing valid configuration is rejected — a key starting with "#" could never have produced a successful mapping before this change, so real users are unaffected. The unit test covers both the failure path and multiple flavors of valid key.

No files require special attention.

Important Files Changed

Filename Overview
pkg/codegen/configuration.go Adds validation in Validate() to reject import-mapping keys that start with "#"; no struct fields were changed, so no JSON schema update is needed
pkg/codegen/configuration_test.go New unit test covering both the rejection of a JSON-pointer key and acceptance of valid file-path/URL keys
README.md Adds a NOTE callout to the Import Mapping section explaining that keys must be document paths, not JSON pointers

Reviews (1): Last reviewed commit: "Reject import-mapping keys that are JSON..." | Re-trigger Greptile

@mromaszewicz
mromaszewicz merged commit 28e0964 into main Jul 13, 2026
31 checks passed
@mromaszewicz
mromaszewicz deleted the fix/issue-2459 branch July 13, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn when import-mapping keys are JSON pointers instead of document paths

1 participant