Skip to content

Commit d0937f9

Browse files
authored
Merge pull request #5709: Fix and reenable prance-based openapi spec validation
2 parents 7638512 + 710137f commit d0937f9

File tree

5 files changed

+50
-16
lines changed

5 files changed

+50
-16
lines changed

CHANGELOG.rst

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Fixed
2929

3030
* Fixed eventlet monkey patching so more of the unit tests work under pytest. #5689
3131

32+
* Fix and reenable prance-based openapi spec validation, but make our custom ``x-api-model`` validation optional as the spec is out-of-date. #5709
33+
Contributed by @cognifloyd
34+
3235
Added
3336
~~~~~
3437

st2common/st2common/cmd/validate_api_spec.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
from __future__ import absolute_import
2323
import os
2424

25+
import prance
2526
from oslo_config import cfg
26-
from prance import ResolvingParser
2727

2828
from st2common import config
2929
from st2common import log as logging
@@ -45,6 +45,14 @@
4545
)
4646
)
4747

48+
# When disabled, only load the spec in prance to validate. Otherwise check for x-api-model as well.
49+
# validate-defs is disabled by default until these are resolved:
50+
# https://github.com/StackStorm/st2/issues/3575
51+
# https://github.com/StackStorm/st2/issues/3788
52+
cfg.CONF.register_cli_opt(
53+
cfg.BoolOpt("validate-defs", short="-d", required=False, default=False)
54+
)
55+
4856
cfg.CONF.register_cli_opt(
4957
cfg.BoolOpt("generate", short="-c", required=False, default=False)
5058
)
@@ -71,6 +79,7 @@ def _validate_definitions(spec):
7179

7280
if verbose:
7381
LOG.info("Supplied definition for model %s: \n\n%s.", model, definition)
82+
msg += "\n"
7483

7584
error = True
7685
LOG.error(msg)
@@ -81,6 +90,7 @@ def _validate_definitions(spec):
8190
def validate_spec():
8291
spec_file = cfg.CONF.spec_file
8392
generate_spec = cfg.CONF.generate
93+
validate_defs = cfg.CONF.validate_defs
8494

8595
if not os.path.exists(spec_file) and not generate_spec:
8696
msg = (
@@ -100,13 +110,16 @@ def validate_spec():
100110
f.write(spec_string)
101111
f.flush()
102112

103-
parser = ResolvingParser(spec_file)
113+
parser = prance.ResolvingParser(spec_file)
104114
spec = parser.specification
105115

116+
if not validate_defs:
117+
return True
118+
106119
return _validate_definitions(spec)
107120

108121

109-
def teartown():
122+
def teardown():
110123
common_teardown()
111124

112125

@@ -118,11 +131,14 @@ def main():
118131
# The spec loader do not allow duplicate keys.
119132
spec_loader.load_spec("st2common", "openapi.yaml.j2")
120133

121-
ret = 0
134+
# run the schema through prance to validate openapi spec.
135+
passed = validate_spec()
136+
137+
ret = 0 if passed else 1
122138
except Exception:
123139
LOG.error("Failed to validate openapi.yaml file", exc_info=True)
124140
ret = 1
125141
finally:
126-
teartown()
142+
teardown()
127143

128144
return ret

st2common/st2common/models/api/pack.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,17 @@ class PackInstallRequestAPI(BaseAPI):
383383
schema = {
384384
"type": "object",
385385
"properties": {
386-
"packs": {"type": "array"},
386+
"packs": {"type": "array"}, # TODO: add enum
387387
"force": {
388388
"type": "boolean",
389389
"description": "Force pack installation",
390390
"default": False,
391391
},
392+
"skip_dependencies": {
393+
"type": "boolean",
394+
"description": "Set to True to skip pack dependency installations.",
395+
"default": False,
396+
},
392397
},
393398
}
394399

st2common/st2common/openapi.yaml

+10-5
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,7 @@ paths:
19981998
schema:
19991999
type: array
20002000
items:
2001-
$ref: '#/definitions/PackView'
2001+
$ref: '#/definitions/DataFilesSubSchema'
20022002
examples:
20032003
application/json:
20042004
ref: 'core.local'
@@ -2391,7 +2391,7 @@ paths:
23912391
description: User performing the operation.
23922392
responses:
23932393
'200':
2394-
description: Policy created successfully.
2394+
description: Policy list
23952395
schema:
23962396
type: array
23972397
items:
@@ -3074,7 +3074,7 @@ paths:
30743074
description: User performing the operation.
30753075
responses:
30763076
'200':
3077-
description: List of rules
3077+
description: List of runner types
30783078
schema:
30793079
type: array
30803080
items:
@@ -4883,7 +4883,7 @@ definitions:
48834883
type: object
48844884
description: Execution result
48854885
properties:
4886-
$ref: '#/definitions/Execution'
4886+
$ref: '#/definitions/Execution/properties'
48874887
message:
48884888
type: string
48894889
AliasMatchAndExecuteInputAPI:
@@ -5172,8 +5172,9 @@ definitions:
51725172
skip_dependencies:
51735173
type: boolean
51745174
description: Set to True to skip pack dependency installations.
5175-
required: false
51765175
default: false
5176+
required:
5177+
- packs
51775178
PacksUninstall:
51785179
type: object
51795180
properties:
@@ -5198,6 +5199,10 @@ definitions:
51985199
type: array
51995200
items:
52005201
$ref: '#/definitions/PacksContentRegisterType'
5202+
fail_on_failure:
5203+
type: boolean
5204+
description: True to fail on failure
5205+
default: true
52015206
PacksContentRegisterType:
52025207
type: string
52035208
enum: ['all',

st2common/st2common/openapi.yaml.j2

+10-5
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,7 @@ paths:
19941994
schema:
19951995
type: array
19961996
items:
1997-
$ref: '#/definitions/PackView'
1997+
$ref: '#/definitions/DataFilesSubSchema'
19981998
examples:
19991999
application/json:
20002000
ref: 'core.local'
@@ -2387,7 +2387,7 @@ paths:
23872387
description: User performing the operation.
23882388
responses:
23892389
'200':
2390-
description: Policy created successfully.
2390+
description: Policy list
23912391
schema:
23922392
type: array
23932393
items:
@@ -3070,7 +3070,7 @@ paths:
30703070
description: User performing the operation.
30713071
responses:
30723072
'200':
3073-
description: List of rules
3073+
description: List of runner types
30743074
schema:
30753075
type: array
30763076
items:
@@ -4879,7 +4879,7 @@ definitions:
48794879
type: object
48804880
description: Execution result
48814881
properties:
4882-
$ref: '#/definitions/Execution'
4882+
$ref: '#/definitions/Execution/properties'
48834883
message:
48844884
type: string
48854885
AliasMatchAndExecuteInputAPI:
@@ -5168,8 +5168,9 @@ definitions:
51685168
skip_dependencies:
51695169
type: boolean
51705170
description: Set to True to skip pack dependency installations.
5171-
required: false
51725171
default: false
5172+
required:
5173+
- packs
51735174
PacksUninstall:
51745175
type: object
51755176
properties:
@@ -5194,6 +5195,10 @@ definitions:
51945195
type: array
51955196
items:
51965197
$ref: '#/definitions/PacksContentRegisterType'
5198+
fail_on_failure:
5199+
type: boolean
5200+
description: True to fail on failure
5201+
default: true
51975202
PacksContentRegisterType:
51985203
type: string
51995204
enum: ['all',

0 commit comments

Comments
 (0)