sortfmt

package
v1.25.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package sortfmt provides deterministic JSON formatting for OpenAPI documents.

The formatter orders mapping keys using a fixed priority list, alphabetizes maps under paths, properties, and schemas, and sorts selected arrays by a stable display key. It intentionally changes the order of parameters and composition arrays, so callers should opt in only when sorted output is more important than preserving authored array order. Selected arrays whose sort keys have different JSON types return an error, matching Python's ordering behavior. Format also rejects lone UTF-16 surrogate escapes rather than silently replacing them with a different character.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(r io.Reader, w io.Writer) error

Format reads a JSON document, applies the sorted formatting style, and writes two-space-indented JSON with a trailing newline.

func Sort

func Sort(node *yaml.Node) error

Sort applies the sorted formatting order to a YAML node in place. The node must represent data parsed from JSON. Duplicate object keys retain their last value, matching encoding/json and Python's json module.

func Write

func Write(node *yaml.Node, w io.Writer) error

Write serializes a sorted YAML node using the JSON representation produced by Python's json.dump with indent=2, followed by one trailing newline.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL