diff --git a/internal/bundles/assets/import_openapi_cli.arraiz b/internal/bundles/assets/import_openapi_cli.arraiz index 00d29b5e..a7d7a682 100644 Binary files a/internal/bundles/assets/import_openapi_cli.arraiz and b/internal/bundles/assets/import_openapi_cli.arraiz differ diff --git a/pkg/importer/openapi/simplify_oapi.arrai b/pkg/importer/openapi/simplify_oapi.arrai index 0755207b..ac1d1ee3 100644 --- a/pkg/importer/openapi/simplify_oapi.arrai +++ b/pkg/importer/openapi/simplify_oapi.arrai @@ -26,7 +26,6 @@ let singleSyslStrTag = \tag {'patterns': (a: (elt: [(s: tag)]))}; let schemaSyslTag = \tag {syslAttrs: singleSyslStrTag(tag)}; # FIXME: handle content type on paths, they have precedence rule (e.g. text/* > text/plain) -# FIXME: handle non verbs in path # simplifiedParams moves top level parameters from a path and move it into all operation objects in a path. let simplifiedParams = \oapi @@ -50,12 +49,31 @@ let simplifiedParams = \oapi (nested(top) +> nested(bottom)) => .@value orderby ., } ; + let mergeDesc = \top \bottom + cond { + bottom = '': top, + _: bottom, + } + ; oapi +> { - 'paths': oapi('paths')?:{} >> cond . { - {'parameters': top, ...verbs}: verbs >> . +> {'parameters': (a: mergeParams(top.a, .('parameters')?.a?:{}))}, - _: ., - } + 'paths': oapi('paths')?:{} >> + cond . { + {'parameters': commonParams, ...verbs}: + verbs => cond { + .@ <: httpVerbs: (:.@, @value: .@value +> {'parameters': (a: mergeParams(commonParams.a, .@value('parameters')?.a?:{}))}), + _: ., + }, + _: ., + } >> + cond . { + {'description': commonDesc, ...verbs}: + verbs => cond { + .@ <: httpVerbs: (:.@, @value: .@value +> {'description': (s: mergeDesc(commonDesc.s, .@value('description')?.s?:''))}), + _: ., + }, + _: ., + } where .@ !<: {'parameters', 'description'} } ; diff --git a/pkg/importer/tests/openapi3/params-for-all.sysl b/pkg/importer/tests/openapi3/params-for-all.sysl index 85c97f3c..fd35b71f 100755 --- a/pkg/importer/tests/openapi3/params-for-all.sysl +++ b/pkg/importer/tests/openapi3/params-for-all.sysl @@ -12,5 +12,5 @@ TestApp "Params For All Operations": | has existing parameters return 200 POST?name=string?&special%2Dcharacter=string?: - | Empty parameters + | Common description return 200 diff --git a/pkg/importer/tests/openapi3/params-for-all.yaml b/pkg/importer/tests/openapi3/params-for-all.yaml index a7a7d408..b43aacf7 100644 --- a/pkg/importer/tests/openapi3/params-for-all.yaml +++ b/pkg/importer/tests/openapi3/params-for-all.yaml @@ -3,6 +3,7 @@ info: title: Params For All Operations paths: /param/{id}: + description: Common description parameters: - $ref: "#/components/parameters/name" - name: id @@ -14,7 +15,7 @@ paths: type: string in: query post: - description: Empty parameters + # no parameters or description responses: "200": description: "OK"