Skip to content

Commit c7977e8

Browse files
committed
Path-level parameters denormalized
1 parent 0e13689 commit c7977e8

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "OpenAPI",
3-
"version": "0.1.6",
4-
"versionDate": "2019-11-16",
3+
"version": "0.1.7",
4+
"versionDate": "2019-11-30",
55
"author": "hackolade",
66
"engines": {
77
"hackolade": "3.3.0",

reverse_engineering/helpers/dataHelper.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,12 +864,29 @@ const getModelContent = (pathData, fieldOrder, callbacksComponent) => {
864864
const getOpenAPIJsonSchema = (data, fileName, extension) => {
865865
const schema = extension !== '.json' ? commonHelper.convertYamlToJson(data) : data;
866866
const openAPISchema = typeof schema === 'string' ? JSON.parse(schema) : schema;
867-
const openAPISchemaWithModelName = Object.assign({}, openAPISchema, {
867+
const updatedOpenApiSchema = copyPathItemLevelParametersToOperationObject(openAPISchema);
868+
const openAPISchemaWithModelName = Object.assign({}, updatedOpenApiSchema, {
868869
modelName: fileName
869870
});
870871
return openAPISchemaWithModelName;
871872
};
872873

874+
const copyPathItemLevelParametersToOperationObject = (schema) => {
875+
const operations = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'];
876+
if (schema.paths) {
877+
for (const path in schema.paths) {
878+
if (Array.isArray(schema.paths[path].parameters)) {
879+
for (const pathItem in schema.paths[path]) {
880+
if (operations.includes(pathItem)) {
881+
schema.paths[path][pathItem].parameters =
882+
[...schema.paths[path][pathItem].parameters || [], ...schema.paths[path].parameters];
883+
}
884+
}
885+
}
886+
}
887+
}
888+
return schema;
889+
}
873890

874891
const validateOpenAPISchema = (schema) => {
875892
const openapi = schema.openapi;

0 commit comments

Comments
 (0)