Skip to content

gen: Unspecified type with 'format' leads to invalid Go code #1471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
utherbit opened this issue Jun 3, 2025 · 2 comments
Open

gen: Unspecified type with 'format' leads to invalid Go code #1471

utherbit opened this issue Jun 3, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@utherbit
Copy link
Contributor

utherbit commented Jun 3, 2025

What version of ogen are you using?

$ go list -m github.com/ogen-go/ogen

github.com/ogen-go/ogen v1.14.0

Can this issue be reproduced with the latest version?

Yes

What did you do?

openapi: 3.0.3
info:
  title: API
  version: 0.1.0
paths:
  /timestamp:
    get:
      operationId: timestamp
      responses:
        '200':
          description: Test
          content:
            application/json:
              schema:
                type: object
                required:
                  - date
                  - time
                  - dateTime
                properties:
                  date:
                    format: date
                    x-ogen-time-format: 02/01/2006
                  time:
                    format: time
                    x-ogen-time-format: 3:04PM
                  dateTime:
                    format: date
                    x-ogen-time-format: 2006-01-02T15:04:05.999999999Z07:00

What did you expect to see?

Either inferred types based on format, use of jx.Raw without format assumptions, a generation warning, or a schema validation error.

What did you see instead?

Generated code is not compilable due to type mismatches caused by missing type with defined format.

@utherbit utherbit added the bug Something isn't working label Jun 3, 2025
@utherbit
Copy link
Contributor Author

utherbit commented Jun 3, 2025

PS: I don’t see this as a critical issue, since it’s easy to work around by explicitly adding the missing type. Still, I’m a big fan of ogen — it's by far the most elegant and thoughtful code generator I’ve used. That’s exactly why I care: a tool this good deserves to never produce non-compilable code, even in edge cases like this.

@abemedia
Copy link
Contributor

abemedia commented Jun 9, 2025

I think a good solution would be to ignore formats that aren't on a specified type, rather than implying the type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants