-
Notifications
You must be signed in to change notification settings - Fork 18
Add PropertyOrder #51
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
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| // Since we collected them backwards, we need to reverse the result | ||
| // to restore the correct order. | ||
| for i, j := 0, len(cleaned)-1; i < j; i, j = i+1, j-1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(but I don't think you'll need it)
| "I": {Type: "integer"}, | ||
| "C": {Type: "custom"}, | ||
| "G": {Type: "integer"}, | ||
| "B": {Type: "integer"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be bool. The top-level field takes precedence.
| F func() | ||
| C custom | ||
| B bool | ||
| E |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also test with E before B.
| }, | ||
| Required: []string{"I", "C", "B"}, | ||
| AdditionalProperties: falseSchema(), | ||
| PropertyOrder: []string{"I", "C", "G", "B"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be I, C, B, G
| } | ||
| } | ||
| if skip { | ||
| continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should move L268 to here, before the continue.
|
|
||
| skipPath = field.Index | ||
| for name, prop := range override.Properties { | ||
| s.Properties[name] = prop.CloneSchemas() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated bug: if an anonymous field is first, s.Properties will be nil.
| } | ||
| } | ||
|
|
||
| // Remove PropertyOrder duplicates, keeping the last occurrence |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there should be no duplicates after the above change.
| // | ||
| // If PropertyOrder is set, it controls the relative ordering of properties in [Schema.MarshalJSON]. | ||
| // The rendered JSON first lists any properties that appear in the PropertyOrder slice in the order | ||
| // they appear, followed by any properties that do not appear in the PropertyOrder slice in an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"followed by all other properties..."
|
|
||
| // PropertyOrder records the ordering of properties for JSON rendering. | ||
| // | ||
| // During [For], PropertyOrder is set to the field order, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc this in For and ForType.
| s := &Schema{ | ||
| Type: "object", | ||
| Properties: map[string]*Schema{ | ||
| "A": {Type: "integer"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add "E", make sure it's at the end.
Refers to #15