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

change use_struct_references behaviour when it would generate invalid type #343

Closed

Conversation

Fazt01
Copy link
Contributor

@Fazt01 Fazt01 commented Jul 2, 2024

A possible fix for #342. More description and discussion in the issue itself.
I am definitely fine for going another approach (reason for draft) if the breaking change is not appropriate.

This PR fixes the issue by changing what type is generated for non-nullable input field types with no default value: for example the added test currently generates:

type UseStructReferencesInput struct {
	Struct         StructInput  `json:"struct"`
	NullableStruct *StructInput `json:"nullableStruct,omitempty"`
}

Previously, it would generate:

type UseStructReferencesInput struct {
	Struct         *StructInput `json:"struct,omitempty"`
	NullableStruct *StructInput `json:"nullableStruct,omitempty"`
}

and after #338 this would cause an error during generation as the validation is trying to prevent a type that could cause runtime error by omitting a value for a type for which omitting is not possible.

I have:

  • Written a clear PR title and description (above)
  • Signed the Khan Academy CLA
  • Added tests covering my changes, if applicable
  • Included a link to the issue fixed, if applicable
  • Included documentation, for new features
  • Added an entry to the changelog

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.

1 participant