Skip to content

Preserve descriptor order in JSON Schema and OpenAPI output - #302

Open
moohee-lee wants to merge 1 commit into
ePages-de:masterfrom
moohee-lee:fix/preserve-schema-property-order
Open

moohee-lee wants to merge 1 commit into
ePages-de:masterfrom
moohee-lee:fix/preserve-schema-property-order

Conversation

@moohee-lee

Copy link
Copy Markdown

Problem

Generated request and response schemas can lose fieldWithPath declaration order during Everit serialization. The schema collection changes in #280 do not address this common JSON Schema generation path.

Changes

  • Restore properties and required order from the original field descriptors, including nested objects and root or nested arrays.
  • Precompute ordered child names by full parent path. Escape slashes and tildes to distinguish repeated field names and names containing path separators.
  • Use the first occurrence of each field path for its position while retaining existing descriptor deduplication and type merging behavior.
  • Align required lists with property order in the OpenAPI 2 and 3 writers after Swagger sorts those lists alphabetically. Preserve numeric defaults during serialization.
  • Document the ordering guarantees and verify that Postman example bodies remain unchanged.

Validation

  • ./gradlew build with JDK 17: 189 tests passed, 3 existing tests skipped; Kotlin lint and plugin validation passed.
  • Regression coverage includes JSON, YAML and YML output, extracted component schemas, optional fields absent from examples, array items, repeated field names, and escaped paths.

Fixes #198.

Everit's schema serialization loses field descriptor order, so ordered
schema collection maps alone do not preserve the declared property order.

Build each parent's child order once from the original descriptors and
reuse it for nested objects and array items. Use escaped full parent paths
to distinguish repeated field names and names containing slashes or tildes.
Keep the existing descriptor deduplication and type merging behavior.

Align required names with property order in OpenAPI 2 and 3 output after
Swagger sorts those names alphabetically. Preserve numeric defaults when
converting Swagger models to JSON trees.

Add regression coverage for JSON, YAML and YML output, optional fields
absent from examples, root and nested arrays, duplicate descriptors, and
repeated or escaped field names. Verify Postman example bodies remain
unchanged and document the ordering guarantees.

Validation: ./gradlew build with JDK 17; 189 tests passed, 3 existing skips.
@wodrobina wodrobina self-assigned this Nov 4, 2026
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.

Fields order in OpenAPI Specification

2 participants