Skip to content
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

Incorrect generation of free-form objects #1221

Closed
mxk opened this issue Apr 11, 2024 · 3 comments · Fixed by #1246
Closed

Incorrect generation of free-form objects #1221

mxk opened this issue Apr 11, 2024 · 3 comments · Fixed by #1246
Labels
bug Something isn't working

Comments

@mxk
Copy link

mxk commented Apr 11, 2024

OpenAPI Guide states that additionalProperties: true is the default when a schema consists of just type: object, but the generated code ends up with a struct{} type unless additionalProperties: true is specified.

What version of ogen are you using?

v1.0.1-0.20240411144324-e1628ac9f35f

Can this issue be reproduced with the latest version?

Yes

What did you do?

Changed schema from:

"schema": {
  "type": "object"
}

to:

"schema": {
  "type": "object"
  "additionalProperties": true
}

What did you expect to see?

Generated code should be the same.

What did you see instead?

Without additionalProperties:

type MyApiReq struct{}

With additionalProperties:

type MyApiReq map[string]jx.Raw
@mxk mxk added the bug Something isn't working label Apr 11, 2024
@dstubbersfield
Copy link

Bump. I got stung by this one too using latest OGEN, would be great to see a fix.

@tdakkota
Copy link
Member

Current validator/decoder behavior matches expected by JSON Schema.

ogen generates AdditionalProps only if additionalProperties is defined explicitly.
Majority of schemas does not define additionalProperties and probably majority of users do not need them, so current behavior seems more reasonable for me.

#1246 fixes this issue in slighty different way: AdditionalProps would be added implicitly only if properties and patternProperties are not defined, but I still not convinced that any change is required.

@ernado Thoughts?

@ernado
Copy link
Member

ernado commented May 22, 2024

@tdakkota

Let's generate AdditionalProps for type: object schema, the struct{} is pretty useless.
If #1246 achieves this, it is LGTM.

Also let's keep our default unchanged (do not generate AdditionalProps by default in other cases). If this will be a problem for someone, we can introduce a configuration option.

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
4 participants