Skip to content

Conversation

@baptmont
Copy link
Contributor

Refers to #15

@jba
Copy link
Collaborator

jba commented Nov 19, 2025

Refers to #15

Fixes #15


// 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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

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"},
Copy link
Collaborator

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
Copy link
Collaborator

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"},
Copy link
Collaborator

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
Copy link
Collaborator

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()
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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,
Copy link
Collaborator

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"},
Copy link
Collaborator

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.

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.

2 participants