Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit60d131b

Browse files
authored
fix: show siblings schema with oneOf (#2576)
1 parenta7607ea commit60d131b

File tree

3 files changed

+89
-5
lines changed

3 files changed

+89
-5
lines changed

‎src/services/OpenAPIParser.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,18 @@ export class OpenAPIParser {
364364

365365
constallOf=schema.allOf;
366366
for(leti=0;i<allOf.length;i++){
367-
constsub=allOf[i];
368-
if(Array.isArray(sub.oneOf)){
367+
const{ oneOf, ...sub}=allOf[i];
368+
if(!oneOf){
369+
continue;
370+
}
371+
if(Array.isArray(oneOf)){
369372
constbeforeAllOf=allOf.slice(0,i);
370373
constafterAllOf=allOf.slice(i+1);
374+
constsiblingValues=Object.keys(sub).length>0 ?[sub] :[];
371375
return{
372-
oneOf:sub.oneOf.map((part:OpenAPISchema)=>{
376+
oneOf:oneOf.map((part:OpenAPISchema)=>{
373377
return{
374-
allOf:[...beforeAllOf,part, ...afterAllOf],
378+
allOf:[...beforeAllOf,...siblingValues,part, ...afterAllOf],
375379
'x-refsStack':refsStack,
376380
};
377381
}),

‎src/services/__tests__/__snapshots__/OpenAPIParser.test.ts.snap‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ exports[`Models Schema should hoist oneOfs when mergin allOf 1`] = `
2121
"oneOf": [
2222
{
2323
"allOf": [
24+
{
25+
"properties": {
26+
"id": {
27+
"description":"The user's ID",
28+
"type":"integer",
29+
},
30+
},
31+
},
2432
{
2533
"properties": {
2634
"username": {
@@ -61,6 +69,14 @@ exports[`Models Schema should hoist oneOfs when mergin allOf 1`] = `
6169
},
6270
{
6371
"allOf": [
72+
{
73+
"properties": {
74+
"id": {
75+
"description":"The user's ID",
76+
"type":"integer",
77+
},
78+
},
79+
},
6480
{
6581
"properties": {
6682
"email": {
@@ -99,6 +115,55 @@ exports[`Models Schema should hoist oneOfs when mergin allOf 1`] = `
99115
],
100116
"x-refsStack":undefined,
101117
},
118+
{
119+
"allOf": [
120+
{
121+
"properties": {
122+
"id": {
123+
"description":"The user's ID",
124+
"type":"integer",
125+
},
126+
},
127+
},
128+
{
129+
"properties": {
130+
"id": {
131+
"description":"The user's ID",
132+
"format":"uuid",
133+
"type":"string",
134+
},
135+
},
136+
},
137+
{
138+
"properties": {
139+
"extra": {
140+
"type":"string",
141+
},
142+
},
143+
},
144+
{
145+
"oneOf": [
146+
{
147+
"properties": {
148+
"password": {
149+
"description":"The user's password",
150+
"type":"string",
151+
},
152+
},
153+
},
154+
{
155+
"properties": {
156+
"mobile": {
157+
"description":"The user's mobile",
158+
"type":"string",
159+
},
160+
},
161+
},
162+
],
163+
},
164+
],
165+
"x-refsStack":undefined,
166+
},
102167
],
103168
}
104169
`;

‎src/services/__tests__/fixtures/oneOfHoist.json‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
"test": {
1010
"allOf": [
1111
{
12+
"properties": {
13+
"id": {
14+
"description":"The user's ID",
15+
"type":"integer"
16+
}
17+
},
1218
"oneOf": [
1319
{
1420
"properties": {
@@ -25,6 +31,15 @@
2531
"type":"string"
2632
}
2733
}
34+
},
35+
{
36+
"properties": {
37+
"id": {
38+
"description":"The user's ID",
39+
"type":"string",
40+
"format":"uuid"
41+
}
42+
}
2843
}
2944
]
3045
},
@@ -59,4 +74,4 @@
5974
}
6075
}
6176
}
62-
}
77+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp