Skip to content

Commit

Permalink
Fix: Shared route body should use anyOf instead of oneOf (#2366)
Browse files Browse the repository at this point in the history
fix [#2303](#2303)

We don't know if those bodies are mutually exclusive so `anyOf` is more
correct.

---------

Co-authored-by: Microsoft Auto Changeset Bot <[email protected]>
  • Loading branch information
timotheeguerin and Microsoft Auto Changeset Bot authored Sep 6, 2023
1 parent 18356ee commit f4a0488
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
10 changes: 10 additions & 0 deletions common/changes/@typespec/openapi3/fix-oneof_2023-09-05-20-13.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/openapi3",
"comment": "Use `anyOf` instead of `oneOf` for shared route with different request/response bodies",
"type": "none"
}
],
"packageName": "@typespec/openapi3"
}
4 changes: 2 additions & 2 deletions packages/openapi3/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ function createOAPIEmitter(program: Program, options: ResolvedOpenAPI3EmitterOpt
obj.content[contentType] = { schema: schema[0] };
} else {
obj.content[contentType] = {
schema: { oneOf: schema },
schema: { anyOf: schema },
};
}
}
Expand Down Expand Up @@ -1056,7 +1056,7 @@ function createOAPIEmitter(program: Program, options: ResolvedOpenAPI3EmitterOpt
content[contentType] = { schema: schemaArray[0] };
} else {
content[contentType] = {
schema: { oneOf: schemaArray },
schema: { anyOf: schemaArray },
};
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/openapi3/test/return-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ describe("openapi3: return types", () => {
content: {
"application/json": {
schema: {
oneOf: [
anyOf: [
{
$ref: "#/components/schemas/A",
},
Expand Down Expand Up @@ -653,7 +653,7 @@ describe("openapi3: return types", () => {
content: {
"application/json": {
schema: {
oneOf: [
anyOf: [
{
$ref: "#/components/schemas/A",
},
Expand Down Expand Up @@ -692,7 +692,7 @@ describe("openapi3: return types", () => {
content: {
"application/json": {
schema: {
oneOf: [
anyOf: [
{
$ref: "#/components/schemas/A",
},
Expand Down
12 changes: 6 additions & 6 deletions packages/openapi3/test/shared-routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe("openapi3: shared routes", () => {
content: {
"application/json": {
schema: {
oneOf: [
anyOf: [
{
type: "integer",
format: "int32",
Expand Down Expand Up @@ -255,7 +255,7 @@ describe("openapi3: shared routes", () => {
content: {
"application/json": {
schema: {
oneOf: [
anyOf: [
{
type: "integer",
format: "int32",
Expand All @@ -273,7 +273,7 @@ describe("openapi3: shared routes", () => {
content: {
"application/json": {
schema: {
oneOf: [
anyOf: [
{
type: "integer",
format: "int32",
Expand Down Expand Up @@ -315,7 +315,7 @@ describe("openapi3: shared routes", () => {
content: {
"application/json": {
schema: {
oneOf: [
anyOf: [
{
properties: {
a: { $ref: "#/components/schemas/A" },
Expand Down Expand Up @@ -358,7 +358,7 @@ describe("openapi3: shared routes", () => {
content: {
"application/json": {
schema: {
oneOf: [
anyOf: [
{
type: "integer",
format: "int32",
Expand All @@ -377,7 +377,7 @@ describe("openapi3: shared routes", () => {
content: {
"application/json": {
schema: {
oneOf: [
anyOf: [
{
type: "integer",
format: "int32",
Expand Down

0 comments on commit f4a0488

Please sign in to comment.