Skip to content

Generate schema properties in the original order#1722

Closed
diamondburned wants to merge 1 commit into
oapi-codegen:mainfrom
diamondburned:ordered-schema-properties
Closed

Generate schema properties in the original order#1722
diamondburned wants to merge 1 commit into
oapi-codegen:mainfrom
diamondburned:ordered-schema-properties

Conversation

@diamondburned
Copy link
Copy Markdown

This commit temporarily switches to a fork of kin-openapi that provides
the original ordering of the Properties object. This provides a way for
this tool to generate the properties in the original order as they were
written in the YAML file.

This commit temporarily switches to a fork of kin-openapi that provides
the original ordering of the Properties object. This provides a way for
this tool to generate the properties in the original order as they were
written in the YAML file.
@diamondburned
Copy link
Copy Markdown
Author

#1388 will essentially replace this PR with a few simple tweaks -_-

See pb33f/libopenapi#205

@mromaszewicz
Copy link
Copy Markdown
Member

Property ordering is cosmetic, and it doesn't affect behavior, so it's better to stay on the official release of kin-openapi than to use someone else's fork.

Why is it important to preserve property order in generated code that you won't be editing?

@diamondburned
Copy link
Copy Markdown
Author

Property ordering is cosmetic, and it doesn't affect behavior, so it's better to stay on the official release of kin-openapi than to use someone else's fork.

Right. There's a PR for this to kin-openapi, which is why this PR is a draft. See getkin/kin-openapi#1003.

Why is it important to preserve property order in generated code that you won't be editing?

Because the Go types are used for documentation when writing Go code. It is what you see first when you Go to Definition, not an external OpenAPI documentation.

@mromaszewicz
Copy link
Copy Markdown
Member

Thank you for submitting this PR, @diamondburned — but we need to close it because the approach (depending on a fork of kin-openapi) is something we'd rather not take on, and the underlying use case is now served by the x-order extension that landed in #1190 (Jan 2024). Specs can opt into explicit ordering with x-order annotations on individual properties; without it, fields are sorted alphabetically for determinism. There's an integration test at internal/test/extensions/x-order/spec.yaml showing the pattern.

Appreciate you flagging this and prototyping a path forward — x-order ended up being the shape we went with.

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