Skip to content

Generate deterministic, indented OpenAPI JSON - #1699

Closed
Wassim Chegham (manekinekko) wants to merge 1 commit into
mainfrom
manekinekko-deterministic-openapi-json
Closed

Wassim Chegham (manekinekko) wants to merge 1 commit into
mainfrom
manekinekko-deterministic-openapi-json

Conversation

@manekinekko

Copy link
Copy Markdown
Member

Summary

The committed website OpenAPI specification was a single minified line, so even small API changes replaced the entire document in diffs.

Use a shared serializer for generation and website-file snapshot enforcement: deterministic recursive object-key ordering, two-space indentation, LF line endings, and exactly one trailing newline. Arrays retain their original order. Focused regressions cover insertion-order independence, unchanged inputs/content, and a one-line schema-description diff.

The regenerated artifact is a one-time formatting migration. Its parsed OpenAPI content is unchanged, and runtime API behavior is unaffected.

Fixes: #1685

Demos

N/A - generated-artifact formatting, no Portal/CLI interaction changes.

Before

N/A - the generated specification was one minified line.

After

N/A - the specification is indented with stable keys; small schema changes produce localized line diffs.

Testing

Validation used the available supported Node runtimes after restoring locked dependencies; the default Node 20.18.0 could not start the installed Vitest.

  • pnpm exec vitest run apps/api/src/openapi/serialize.test.ts apps/api/src/openapi-snapshot.test.ts apps/api/src/openapi/openapi.test.ts - passed, 40 tests across 3 files using Node 22.21.1.
  • pnpm --filter api exec tsc --noEmit - passed.
  • pnpm --filter api generate:openapi - passed after building the telemetry prerequisite with pnpm --filter telemetry build; repeated generation produced byte-identical bytes.
  • Node assert.deepStrictEqual comparison of parsed regenerated JSON against git show HEAD:website/src/openapi/scope-openapi.json before committing - passed, no schema-content changes.
  • npx --yes pnpm@10.29.1 test from website/ - passed, 22 tests.
  • npx --yes pnpm@10.29.1 build from website/ - blocked by an existing tooling path-encoding issue: the schema resolver converts this worktree's ~~ into %7E%7E and cannot open the file. The same command passed against an identical temporary copy of the website sources in a path without those characters, building 227 pages. Temporary copy removed afterward.
  • git diff --check - passed.

Documentation and compatibility

Updated the generated-artifact contract in docs/architecture/app-design.md and the refresh instructions in website/README.md.

Breaking changes: None. No API/CLI, dependency, database, or runtime serialization changes. No upgrade steps; the initial generated-file formatting diff is expected.

Checklist

  • If Portal features changed, keep CLI capabilities in sync. N/A - no Portal features changed.
  • If Portal components changed, update their Storybook stories. N/A - no Portal components changed.
  • If database changes require a migration, include up() / down() and keep it CosmosDB-compatible. N/A - no database changes.
  • If dependencies changed, update the lockfile and regenerate NOTICE / NOTICE-REVIEW.txt with pnpm notice as needed. N/A - dependencies and lockfiles unchanged.
  • Video showing the behavior before the suggested change. N/A - artifact-only formatting change.
  • Video showing the behavior after the suggested change. N/A - artifact-only formatting change.

Share canonical serialization between website generation and snapshot enforcement, preserve array order, and cover stable output and localized diffs. Regenerate the website artifact without changing its parsed content.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added type: documentation Documentation additions, corrections, and improvements. language: javascript Work involving JavaScript code, tooling, or dependencies. topic: testing Test coverage, test infrastructure, and validation quality. topic: ui Portal, visual presentation, layout, and interface components. labels Nov 23, 2026
@github-actions

Copy link
Copy Markdown

Test Results (Node.js 22)

test: Run #619

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
3351 3343 0 8 0 0 0 1m29s

🎉 All tests passed!

Github Test Reporter

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the deterministic OpenAPI artifact serialization change.

No open issues 🎉

What changed in this PR

Addresses #1685 by making Scope’s generated website OpenAPI JSON readable and deterministic, reducing diff churn from small schema changes without changing runtime API serialization.

Changes:

  • Adds a shared serializer with stable recursive object-key ordering, two-space indentation, LF line endings, and one trailing newline while preserving array order.
  • Uses the serializer for generation and snapshot enforcement, with regression tests for determinism, input preservation, and localized diffs.
  • Documents the generated-artifact format and refresh contract.
File Description
website/​README.md Documents deterministic output in refresh instructions.
docs/​architecture/​app-design.md Defines the shared artifact serialization contract.
apps/​api/​src/​openapi/​serialize.ts Implements stable, indented OpenAPI serialization.
apps/​api/​src/​openapi/​serialize.test.ts Tests formatting, determinism, preservation, and localized diffs.
apps/​api/​src/​openapi/​generate.ts Writes the website specification using the shared serializer.
apps/​api/​src/​openapi-snapshot.test.ts Enforces artifact formatting and repeatable generation.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

language: javascript Work involving JavaScript code, tooling, or dependencies. topic: testing Test coverage, test infrastructure, and validation quality. topic: ui Portal, visual presentation, layout, and interface components. type: documentation Documentation additions, corrections, and improvements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generate deterministically indented OpenAPI JSON to minimize diff churn

2 participants