From 8e3240a16a2acf25b7783e9fcc3e038bd0360d7b Mon Sep 17 00:00:00 2001 From: Travis Prescott Date: Wed, 20 Sep 2023 09:43:26 -0700 Subject: [PATCH] OpenAPI3 - Fix CSV format representation (#2446) Fixes #2234. --- .../openapi3-FixCsvFormat_2023-09-19-21-04.json | 10 ++++++++++ packages/openapi3/src/openapi.ts | 7 ++++++- packages/openapi3/test/parameters.test.ts | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 common/changes/@typespec/openapi3/openapi3-FixCsvFormat_2023-09-19-21-04.json diff --git a/common/changes/@typespec/openapi3/openapi3-FixCsvFormat_2023-09-19-21-04.json b/common/changes/@typespec/openapi3/openapi3-FixCsvFormat_2023-09-19-21-04.json new file mode 100644 index 0000000000..cdcd568687 --- /dev/null +++ b/common/changes/@typespec/openapi3/openapi3-FixCsvFormat_2023-09-19-21-04.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/openapi3", + "comment": "Fix issue with CSV format representation.", + "type": "none" + } + ], + "packageName": "@typespec/openapi3" +} \ No newline at end of file diff --git a/packages/openapi3/src/openapi.ts b/packages/openapi3/src/openapi.ts index ac109efeec..cefb96bced 100644 --- a/packages/openapi3/src/openapi.ts +++ b/packages/openapi3/src/openapi.ts @@ -1162,7 +1162,12 @@ function createOAPIEmitter(program: Program, options: ResolvedOpenAPI3EmitterOpt ph.in = parameter.type; if (parameter.type === "query" || parameter.type === "header") { if (parameter.format === "csv" || parameter.format === "simple") { - ph.style = "simple"; + if (parameter.type === "query") { + ph.style = "form"; + ph.explode = false; + } else { + ph.style = "simple"; + } } else if (parameter.format === "multi" || parameter.format === "form") { if (parameter.type === "header") { reportDiagnostic(program, { diff --git a/packages/openapi3/test/parameters.test.ts b/packages/openapi3/test/parameters.test.ts index 70c7eb7ce7..80b8c6e315 100644 --- a/packages/openapi3/test/parameters.test.ts +++ b/packages/openapi3/test/parameters.test.ts @@ -54,7 +54,8 @@ describe("openapi3: parameters", () => { deepStrictEqual(params[1], { in: "query", name: "$csv", - style: "simple", + style: "form", + explode: false, schema: { type: "array", items: {