Skip to content

Commit 68817aa

Browse files
authored
Merge pull request linode#87 from alioso/DLC-178
DLC-178 fixing errors with sample body output and add missing allOf
2 parents 7e9de0e + 9e49071 commit 68817aa

File tree

8 files changed

+19906
-80
lines changed

8 files changed

+19906
-80
lines changed

gatsby-browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exports.shouldUpdateScroll = ({ routerProps: { location } }) => {
1515
() =>
1616
document.getElementById(location.hash.substr(1)).scrollIntoView({
1717
block: "start",
18-
behavior: transitionDelay <= 480 ? "auto" : "smooth"
18+
behavior: windowWidth <= 480 ? "auto" : "smooth"
1919
}),
2020
transitionDelay
2121
);

index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

package-lock.json

Lines changed: 19384 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"axios": "^0.18.0",
1010
"crypto": "^1.0.1",
1111
"gatsby": "^2.9.2",
12+
"gatsby-cli": "^2.7.50",
1213
"gatsby-image": "^2.0.29",
1314
"gatsby-plugin-catch-links": "^2.1.2",
1415
"gatsby-plugin-google-tagmanager": "^2.1.9",

src/components/2_molecules/ResponseItemElements.js

Lines changed: 79 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const ResponseItemElements = props => {
2323
)
2424
.map((p, i) => {
2525
const l = context.content.application_json.schema.properties[p];
26+
// console.log(l);
2627
return (
2728
l && (
2829
<div key={i} className="response-wrapper">
@@ -64,69 +65,92 @@ export const ResponseItemElements = props => {
6465
</div>
6566
)}
6667
{l.items && (
67-
<div className="px-4 mt-4 mb-4 ml-4 subResponse">
68-
{l.items.properties &&
69-
Object.keys(l.items.properties).map((value, index) => {
70-
const data = l.items.properties[value];
71-
return (
72-
data && (
73-
<div key={index} className="response-wrapper">
74-
<div className="lg:flex mb-4">
75-
<div className="w-full lg:w-1/4">
76-
<b
77-
className={
78-
data.deprecated && "line-through"
79-
}
80-
>
81-
{value}
82-
</b>
83-
{data.x_linode_filterable && <Filterable />}
84-
{data.nullable && <Nullable />}
85-
</div>
86-
<div className="w-full lg:w-3/4">
87-
<div>
88-
<div className="text-sm text-grey-darkest leading-text-sm">
89-
{data.type && data.type}
90-
{data.pattern && (
91-
<span className="tag">
92-
{data.pattern}
93-
</span>
68+
<>
69+
<div className="px-4 mt-4 mb-4 ml-4 subResponse">
70+
{l.items.properties &&
71+
Object.keys(l.items.properties).map(
72+
(value, index) => {
73+
const data = l.items.properties[value];
74+
// console.log(data);
75+
return (
76+
data && (
77+
<div key={index} className="response-wrapper">
78+
<div className="lg:flex mb-4">
79+
<div className="w-full lg:w-1/4">
80+
<b
81+
className={
82+
data.deprecated && "line-through"
83+
}
84+
>
85+
{value}
86+
</b>
87+
{data.x_linode_filterable && (
88+
<Filterable />
9489
)}
90+
{data.nullable && <Nullable />}
9591
</div>
96-
{data.enum && <Enum dataSource={data} />}
97-
{data.deprecated && <Deprecated />}
98-
<div>
99-
<Markdown
100-
source={data.description}
101-
escapeHtml={false}
102-
className="api-desc"
103-
/>
92+
<div className="w-full lg:w-3/4">
93+
<div>
94+
<div className="text-sm text-grey-darkest leading-text-sm">
95+
{data.type && data.type}
96+
{data.pattern && (
97+
<span className="tag">
98+
{data.pattern}
99+
</span>
100+
)}
101+
</div>
102+
{data.enum && (
103+
<Enum dataSource={data} />
104+
)}
105+
{data.deprecated && <Deprecated />}
106+
<div>
107+
<Markdown
108+
source={data.description}
109+
escapeHtml={false}
110+
className="api-desc"
111+
/>
112+
</div>
113+
</div>
104114
</div>
105115
</div>
106-
</div>
107-
</div>
108-
{data.oneOf && (
109-
<div className="px-4 mt-4 mb-4 ml-4 subResponse">
110-
{data.oneOf.map((data, i) => {
111-
return (
116+
{data.oneOf && (
117+
<div className="px-4 mt-4 mb-4 ml-4 subResponse">
118+
{data.oneOf.map((data, i) => {
119+
return (
120+
<SubResponse
121+
dataSource={data.properties}
122+
key={i}
123+
/>
124+
);
125+
})}
126+
</div>
127+
)}
128+
{data.properties && (
129+
<div className="px-4 mt-4 mb-4 ml-4 subResponse">
112130
<SubResponse
113131
dataSource={data.properties}
114-
key={i}
115132
/>
116-
);
117-
})}
118-
</div>
119-
)}
120-
{data.properties && (
121-
<div className="px-4 mt-4 mb-4 ml-4 subResponse">
122-
<SubResponse dataSource={data.properties} />
133+
</div>
134+
)}
123135
</div>
124-
)}
125-
</div>
126-
)
127-
);
128-
})}
129-
</div>
136+
)
137+
);
138+
}
139+
)}
140+
</div>
141+
{l.items.allOf && (
142+
<div className="px-4 mt-4 mb-4 ml-4 subResponse">
143+
{l.items.allOf.map((data, i) => {
144+
return (
145+
<SubResponse
146+
dataSource={data.properties}
147+
key={i}
148+
/>
149+
);
150+
})}
151+
</div>
152+
)}
153+
</>
130154
)}
131155
</div>
132156
)

src/components/2_molecules/ResponseSampleBody.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getOr } from "lodash/fp";
22
import React from "react";
33
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
44
import { atomDark } from "react-syntax-highlighter/dist/esm/styles/prism";
5+
import { allOf } from "./allOf";
56

67
export const ResponseSampleBody = props => {
78
const { context, response } = props;
@@ -47,7 +48,7 @@ export const ResponseSampleBody = props => {
4748
const data = l.properties[e];
4849
return `
4950
"${e}": ${
50-
data.example
51+
data.example !== undefined
5152
? JSON.stringify(data.example)
5253
: data.type === "object" && data.properties
5354
? `{
@@ -59,6 +60,8 @@ export const ResponseSampleBody = props => {
5960
? `"${s}": ${
6061
dps.example
6162
? JSON.stringify(dps.example)
63+
: dps.type === "array"
64+
? `[]`
6265
: dps.type === "object" &&
6366
dps.properties
6467
? `{
@@ -72,15 +75,15 @@ export const ResponseSampleBody = props => {
7275
? `"${s2}": ${JSON.stringify(
7376
dps2.example
7477
? dps2.example
75-
: ""
78+
: '""'
7679
)}`
77-
: "";
80+
: '""';
7881
})}}`
79-
: ""
82+
: '""'
8083
}`
81-
: "";
84+
: '""';
8285
})}}`
83-
: ""
86+
: '""'
8487
}
8588
`;
8689
}) +
@@ -156,6 +159,16 @@ export const ResponseSampleBody = props => {
156159
: "";
157160
})}}`
158161
: "") +
162+
(l.items &&
163+
l.items.allOf &&
164+
l.items.allOf[0].properties &&
165+
l.items.allOf[1] &&
166+
l.items.allOf[1].properties
167+
? allOf(
168+
l.items.allOf[0].properties,
169+
l.items.allOf[1].properties
170+
)
171+
: "") +
159172
(l.type === "array" || l.type === "object" || p === "errors"
160173
? `]`
161174
: "")

src/components/2_molecules/allOf.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const accumulator = (or, ov) => {
2+
return Object.keys(or).reduce((acc, currentKey) => {
3+
if (!!ov[currentKey]) {
4+
acc[currentKey] = ov[currentKey];
5+
} else {
6+
acc[currentKey] = or[currentKey];
7+
}
8+
return acc;
9+
}, {});
10+
};
11+
12+
export const allOf = (origin, override) => {
13+
const data = accumulator(origin, override);
14+
return data
15+
? `{
16+
${Object.keys(data)
17+
.filter(dp4 => data[dp4] !== null)
18+
.map(e3 => {
19+
const dps3 = data[e3];
20+
return dps3 && dps3.type !== "array"
21+
? `"${e3}": ${JSON.stringify(dps3.example ? dps3.example : "")}`
22+
: dps3.type === "array"
23+
? `"${e3}": []`
24+
: "";
25+
})}}`
26+
: "";
27+
};

0 commit comments

Comments
 (0)