Skip to content

Commit d544d6c

Browse files
authored
Merge pull request #2473 from SEKOIA-IO/fix/apidoc/body_parameters
fix(apidoc): Show body parameters as well
2 parents c677380 + 947e4f0 commit d544d6c

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

docs/javascript/openapi-viewer.min.js

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

lib/openapi-viewer/src/openapi/swagger-converter.js

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,48 @@ export function convert_swagger_to_openapi(swagger) {
3636
)
3737
)
3838
return;
39+
40+
if (endpoint.parameters && endpoint.parameters.length > 0) {
41+
// Extract body parameters for non-GET methods
42+
const bodyParams = endpoint.parameters.filter(
43+
p =>
44+
method.toLowerCase() !== "get" &&
45+
!p.name.includes("[") &&
46+
!p.name.includes("]") &&
47+
!p.description?.toLowerCase().includes("filter")
48+
);
49+
50+
// Remove body parameters from the endpoint parameters
51+
endpoint.parameters = endpoint.parameters.filter(
52+
p => !bodyParams.includes(p)
53+
);
3954

40-
if (endpoint.parameters) {
41-
// Enforce non-querystring params for every methods other than GET
42-
if (method !== "get") {
43-
for (const p of endpoint.parameters) {
44-
if (p.in === "query") p.in = "body";
45-
}
55+
// Incorporate common params defined at path level
56+
if (commonParams) {
57+
endpoint.parameters = [
58+
...(endpoint.parameters || []),
59+
...commonParams,
60+
];
61+
}
62+
63+
// Convert body parameters to OpenAPI requestBody
64+
if (bodyParams && bodyParams.length > 0) {
65+
endpoint.requestBody = {
66+
required: bodyParams.filter(p => p.required).map(p => p.name),
67+
content: {
68+
"application/json": {
69+
schema: {
70+
type: "object",
71+
properties: Object.fromEntries(
72+
bodyParams.map(p => [p.name, p])
73+
),
74+
},
75+
},
76+
},
77+
};
4678
}
4779
}
48-
49-
// Incorporate common params defined at path level
50-
if (commonParams) {
51-
endpoint.parameters = [
52-
...(endpoint.parameters || []),
53-
...commonParams,
54-
];
55-
}
56-
80+
5781
Object.entries(endpoint.responses).forEach(([code, res]) => {
5882
if (!res.schema) return;
5983
res.content = {

0 commit comments

Comments
 (0)