Skip to content

fix(gen): encode const URI/string formats with e.Str - #1752

Merged
ernado merged 1 commit into
ogen-go:mainfrom
BetterAndBetterII:fix/const-uri-uncompilable
Nov 13, 2026
Merged

ernado merged 1 commit into
ogen-go:mainfrom
BetterAndBetterII:fix/const-uri-uncompilable

Conversation

@BetterAndBetterII

Copy link
Copy Markdown
Contributor

Summary

Const object properties with type: string and a typed JSON encoder (format: uri, UUID, date, and similar) were generated as:

json.EncodeURI(e, "https://example.com/context.jsonld")

json.EncodeURI (and the other typed encoders) take url.URL / typed Go values, not a string constant, so the generated package does not compile.

For const JSON strings whose encoder has no jx primitive (Fn empty, Type == "String"), emit e.Str(...) instead. Required and optional const URI fields are both covered.

Test plan

  • go test ./gen/ -run TestGenerateSchemaConstURICompiles -count=1 (RED on main template, GREEN after fix)
  • CI on this PR

Fixes #1751

Const string fields with typed JSON encoders (URI, UUID, date, …)
were emitted as json.EncodeURI(e, "…"), which expects url.URL and
does not compile. Emit e.Str for const JSON strings instead.

Fixes ogen-go#1751
@ernado ernado closed this Nov 13, 2026
@ernado ernado reopened this Nov 13, 2026
@ernado
ernado merged commit a67c428 into ogen-go:main Nov 13, 2026
17 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.

[gen]: const uri field in openapi yaml genеrates uncompilable code.

2 participants