Skip to content

Commit

Permalink
openapi3 import: handle path level descriptions (#939)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriehSchneier authored Aug 26, 2024
1 parent 81b6e1c commit f6f3f79
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
Binary file modified internal/bundles/assets/import_openapi_cli.arraiz
Binary file not shown.
28 changes: 23 additions & 5 deletions pkg/importer/openapi/simplify_oapi.arrai
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'}
}
;

Expand Down
2 changes: 1 addition & 1 deletion pkg/importer/tests/openapi3/params-for-all.sysl
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion pkg/importer/tests/openapi3/params-for-all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ info:
title: Params For All Operations
paths:
/param/{id}:
description: Common description
parameters:
- $ref: "#/components/parameters/name"
- name: id
Expand All @@ -14,7 +15,7 @@ paths:
type: string
in: query
post:
description: Empty parameters
# no parameters or description
responses:
"200":
description: "OK"
Expand Down

0 comments on commit f6f3f79

Please sign in to comment.