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

Setting default to all schemas when it's only set in one #1392

Closed
sixstone-qq opened this issue Feb 5, 2025 · 1 comment
Closed

Setting default to all schemas when it's only set in one #1392

sixstone-qq opened this issue Feb 5, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@sixstone-qq
Copy link

What version of ogen are you using?

v1.9.0

Can this issue be reproduced with the latest version?

Yes

What did you do?

We have an OpenAPI 3.1.0 schema shared that includes a regular expression to validate the input:

components:
  schemas:
...
    Target:
      type: string
      pattern: ^[a-z0-9][-_a-z0-9]*[a-z0-9]$

We use it in different schemas such as:

components:
  schemas:
...
    RequestA:
      type: object
      properties:
        target:
          $ref: '#/components/schemas/Target'

When we add a new schema where we want it to have a default value such as:

components:
  schemas:
...
    RequestWithDefault:
      type: object
      properties:
        target:
          $ref: '#/components/schemas/Target'
          default: "default"

What did you expect to see?

Generate defaults for RequestWithDefault target property.

What did you see instead?

Generate defaults for all schemas that uses Target instead.

I tried by setting with allOf but complains with Complex defaults error.

--- a/oas_defaults_gen.go
+++ b/oas_defaults_gen.go
@@ -4,24 +4,60 @@ package api

 // setDefaults set default value of fields.
 func (s *RequestA) setDefaults() {
+       {
+               val := Target("default")
+               s.Target.SetTo(val)
+       }
@sixstone-qq sixstone-qq added the bug Something isn't working label Feb 5, 2025
@tdakkota
Copy link
Member

tdakkota commented Feb 6, 2025

Closing as duplicate of #1321.

@tdakkota tdakkota closed this as completed Feb 6, 2025
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