-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix OpenAPI YAML converts strings to boolean (#5456)
Problem: yaml 1.1 treats some string as other types of value. Check out: https://perlpunk.github.io/yaml-test-schema/schemas.html Fix: #5377 Solution: make serialization compatible with YAML 1.1 Todo: test other types (in next PR).
- Loading branch information
Showing
4 changed files
with
93 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
changeKind: fix | ||
packages: | ||
- "@typespec/openapi3" | ||
--- | ||
|
||
Fix: OpenAPI YAML converts strings to boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { emitOpenApiWithDiagnostics } from "./test-host.js"; | ||
|
||
describe("Scalar formats of serialized document in YAML", () => { | ||
it("should add single quote for y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF", async () => { | ||
const [_, __, content] = await emitOpenApiWithDiagnostics(` | ||
enum TestEnum { | ||
y: "y", | ||
Y: "Y", | ||
yes: "yes", | ||
Yes: "Yes", | ||
YES: "YES", | ||
yEs: "yEs", | ||
n: "n", | ||
N: "N", | ||
no: "no", | ||
No: "No", | ||
NO: "NO", | ||
nO: "nO", | ||
"true": "true", | ||
True: "True", | ||
TRUE: "TRUE", | ||
tRUE: "tRUE", | ||
"false": "false", | ||
False: "False", | ||
FALSE: "FALSE", | ||
fALSE: "fALSE", | ||
on: "on", | ||
On: "On", | ||
ON: "ON", | ||
oN: "oN", | ||
off: "off", | ||
Off: "Off", | ||
OFF: "OFF", | ||
oFF: "oFF" | ||
} | ||
`); | ||
expect(content).toBe(`openapi: 3.0.0 | ||
info: | ||
title: (title) | ||
version: 0.0.0 | ||
tags: [] | ||
paths: {} | ||
components: | ||
schemas: | ||
TestEnum: | ||
type: string | ||
enum: | ||
- 'y' | ||
- 'Y' | ||
- 'yes' | ||
- 'Yes' | ||
- 'YES' | ||
- yEs | ||
- 'n' | ||
- 'N' | ||
- 'no' | ||
- 'No' | ||
- 'NO' | ||
- nO | ||
- 'true' | ||
- 'True' | ||
- 'TRUE' | ||
- tRUE | ||
- 'false' | ||
- 'False' | ||
- 'FALSE' | ||
- fALSE | ||
- 'on' | ||
- 'On' | ||
- 'ON' | ||
- oN | ||
- 'off' | ||
- 'Off' | ||
- 'OFF' | ||
- oFF | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters