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

[BUG] Nullable but required field in Go #2184

Open
2 tasks done
condorcet opened this issue Feb 16, 2025 · 0 comments
Open
2 tasks done

[BUG] Nullable but required field in Go #2184

condorcet opened this issue Feb 16, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@condorcet
Copy link

Describe the bug.

Previously nullable types were supported in scope of this issue #1418

But for now if field is required but nullable, it will not use the reference as expected.

For example if we have such schema

    schemaWithNullable:
      type: object
      required:
        - nullable_number
      properties:
        nullable_number:
          type:
            - number
            - "null"

The result will be this

type EventWithNullable struct {
  NullableNumber float64 `json:"nullable_number"` // should be *float64
}

Looks like in this condition must be used OR instead of AND (as the Java generator does)

  if (constrainedModel.options.isNullable || !required) {
    return typeWhenNullableOrOptional;
  }

Expected behavior

For nullable but required field in schema, the result should be generated with reference type, instead of value.

Screenshots

How to Reproduce

  1. Grab schema with nullable and required type above.
  2. Generate Go code.
  3. Check appropriate field in generated Go code.

🥦 Browser

None

👀 Have you checked for similar open issues?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

None

@condorcet condorcet added the bug Something isn't working label Feb 16, 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

1 participant