feat(openapi): add sorted format style - #2118
Conversation
There was a problem hiding this comment.
1 issue found across 10 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="cmd/openapi/transform.go">
<violation number="1" location="cmd/openapi/transform.go:190">
P3: The new sorted-style check lowercases the output path (`strings.ToLower(flags.Out)`) and so rejects `out.YML`/`out.YAML` as YAML, but the shared `setupOutput` computes `yamlOut := utils.HasYAMLExt(out)` on the raw path without normalizing case. As a result, the two format styles make opposite decisions for the same uppercase extension: `--style sorted --out out.YML` is rejected, while `--style readable --out out.YML` is treated as JSON and writes JSON into a `.YML` file. Normalize case in `setupOutput` (or a shared helper) so both styles handle uppercase YAML extensions consistently.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
| if style != workflow.FormatStyleReadable && style != workflow.FormatStyleSorted { | ||
| return fmt.Errorf("unsupported format style %q", flags.Style) | ||
| } | ||
| if style == workflow.FormatStyleSorted && utils.HasYAMLExt(strings.ToLower(flags.Out)) { |
There was a problem hiding this comment.
P3: The new sorted-style check lowercases the output path (strings.ToLower(flags.Out)) and so rejects out.YML/out.YAML as YAML, but the shared setupOutput computes yamlOut := utils.HasYAMLExt(out) on the raw path without normalizing case. As a result, the two format styles make opposite decisions for the same uppercase extension: --style sorted --out out.YML is rejected, while --style readable --out out.YML is treated as JSON and writes JSON into a .YML file. Normalize case in setupOutput (or a shared helper) so both styles handle uppercase YAML extensions consistently.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At cmd/openapi/transform.go, line 190:
<comment>The new sorted-style check lowercases the output path (`strings.ToLower(flags.Out)`) and so rejects `out.YML`/`out.YAML` as YAML, but the shared `setupOutput` computes `yamlOut := utils.HasYAMLExt(out)` on the raw path without normalizing case. As a result, the two format styles make opposite decisions for the same uppercase extension: `--style sorted --out out.YML` is rejected, while `--style readable --out out.YML` is treated as JSON and writes JSON into a `.YML` file. Normalize case in `setupOutput` (or a shared helper) so both styles handle uppercase YAML extensions consistently.</comment>
<file context>
@@ -166,14 +182,26 @@ func runCleanup(ctx context.Context, flags basicFlagsI) error {
+ if style != workflow.FormatStyleReadable && style != workflow.FormatStyleSorted {
+ return fmt.Errorf("unsupported format style %q", flags.Style)
+ }
+ if style == workflow.FormatStyleSorted && utils.HasYAMLExt(strings.ToLower(flags.Out)) {
+ return fmt.Errorf("sorted formatting only supports JSON output")
+ }
</file context>
| if style == workflow.FormatStyleSorted && utils.HasYAMLExt(strings.ToLower(flags.Out)) { | |
| func setupOutput(_ context.Context, out string) (*os.File, bool, error) { | |
| yamlOut := utils.HasYAMLExt(strings.ToLower(out)) | |
| if out != "" { | |
| file, err := os.Create(out) | |
| if err != nil { | |
| return nil, yamlOut, err | |
| } | |
| return file, yamlOut, nil | |
| } | |
| return os.Stdout, yamlOut, nil | |
| } |
|
Resolved the review finding by making shared YAML extension detection case-insensitive and adding regression coverage for uppercase |
b1bc99a to
a8758e0
Compare
Summary
format: { style: sorted }in workflows while preserving readable/default behaviorUsage
Sorted workflow formatting requires JSON output and must be the final transformation.
Validation
go test -timeout=30m ./...go build ./...Summary by cubic
Adds an opt-in sorted formatting style to the OpenAPI transform for deterministic JSON output. Previously only a readable format existed; now you can choose
readable(default, unchanged) orsorted(deterministic object key and array ordering) with JSON-only output forsorted.speakeasy openapi transform formataccepts--style readable|sorted(defaultreadable).sortedreads JSON or YAML but only writes JSON; requesting YAML output fails with “sorted formatting only supports JSON output.” Unknown styles are rejected before any files are created. YAML output detection forreadableis case-insensitive (e.g.,.YAML,.YML).format: { style: sorted }. Use JSON output and place the sorted formatting as the final transformation.required,parameters,oneOf,anyOf, andallOf, which can affect SDK method signatures and union ordering.FormatSortedDocumentandFormatSortedFromReader; the transform runner switches on the selected style and surfaces clear substep messaging.github.com/speakeasy-api/openapito v1.25.0 andgithub.com/speakeasy-api/sdk-gen-configto v1.58.0.Written for commit a8758e0. Summary will update on new commits.