Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Fixed

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

* 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
Contributed by @cognifloyd

Added
~~~~~

Expand Down
26 changes: 21 additions & 5 deletions st2common/st2common/cmd/validate_api_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from __future__ import absolute_import
import os

import prance
from oslo_config import cfg
from prance import ResolvingParser

from st2common import config
from st2common import log as logging
Expand All @@ -45,6 +45,14 @@
)
)

# When disabled, only load the spec in prance to validate. Otherwise check for x-api-model as well.
# validate-defs is disabled by default until these are resolved:
# https://github.com/StackStorm/st2/issues/3575
# https://github.com/StackStorm/st2/issues/3788
cfg.CONF.register_cli_opt(
cfg.BoolOpt("validate-defs", short="-d", required=False, default=False)
)

cfg.CONF.register_cli_opt(
cfg.BoolOpt("generate", short="-c", required=False, default=False)
)
Expand All @@ -71,6 +79,7 @@ def _validate_definitions(spec):

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

error = True
LOG.error(msg)
Expand All @@ -81,6 +90,7 @@ def _validate_definitions(spec):
def validate_spec():
spec_file = cfg.CONF.spec_file
generate_spec = cfg.CONF.generate
validate_defs = cfg.CONF.validate_defs

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

parser = ResolvingParser(spec_file)
parser = prance.ResolvingParser(spec_file)
spec = parser.specification

if not validate_defs:
return True

return _validate_definitions(spec)


def teartown():
def teardown():
common_teardown()


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

ret = 0
# run the schema through prance to validate openapi spec.
passed = validate_spec()

ret = 0 if passed else 1
except Exception:
LOG.error("Failed to validate openapi.yaml file", exc_info=True)
ret = 1
finally:
teartown()
teardown()

return ret
7 changes: 6 additions & 1 deletion st2common/st2common/models/api/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,17 @@ class PackInstallRequestAPI(BaseAPI):
schema = {
"type": "object",
"properties": {
"packs": {"type": "array"},
"packs": {"type": "array"}, # TODO: add enum
"force": {
"type": "boolean",
"description": "Force pack installation",
"default": False,
},
"skip_dependencies": {
"type": "boolean",
"description": "Set to True to skip pack dependency installations.",
"default": False,
},
},
}

Expand Down
15 changes: 10 additions & 5 deletions st2common/st2common/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,7 @@ paths:
schema:
type: array
items:
$ref: '#/definitions/PackView'
$ref: '#/definitions/DataFilesSubSchema'
examples:
application/json:
ref: 'core.local'
Expand Down Expand Up @@ -2391,7 +2391,7 @@ paths:
description: User performing the operation.
responses:
'200':
description: Policy created successfully.
description: Policy list
schema:
type: array
items:
Expand Down Expand Up @@ -3074,7 +3074,7 @@ paths:
description: User performing the operation.
responses:
'200':
description: List of rules
description: List of runner types
schema:
type: array
items:
Expand Down Expand Up @@ -4883,7 +4883,7 @@ definitions:
type: object
description: Execution result
properties:
$ref: '#/definitions/Execution'
$ref: '#/definitions/Execution/properties'
message:
type: string
AliasMatchAndExecuteInputAPI:
Expand Down Expand Up @@ -5172,8 +5172,9 @@ definitions:
skip_dependencies:
type: boolean
description: Set to True to skip pack dependency installations.
required: false
default: false
required:
- packs
PacksUninstall:
type: object
properties:
Expand All @@ -5198,6 +5199,10 @@ definitions:
type: array
items:
$ref: '#/definitions/PacksContentRegisterType'
fail_on_failure:
type: boolean
description: True to fail on failure
default: true
PacksContentRegisterType:
type: string
enum: ['all',
Expand Down
15 changes: 10 additions & 5 deletions st2common/st2common/openapi.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ paths:
schema:
type: array
items:
$ref: '#/definitions/PackView'
$ref: '#/definitions/DataFilesSubSchema'
examples:
application/json:
ref: 'core.local'
Expand Down Expand Up @@ -2387,7 +2387,7 @@ paths:
description: User performing the operation.
responses:
'200':
description: Policy created successfully.
description: Policy list
schema:
type: array
items:
Expand Down Expand Up @@ -3070,7 +3070,7 @@ paths:
description: User performing the operation.
responses:
'200':
description: List of rules
description: List of runner types
schema:
type: array
items:
Expand Down Expand Up @@ -4879,7 +4879,7 @@ definitions:
type: object
description: Execution result
properties:
$ref: '#/definitions/Execution'
$ref: '#/definitions/Execution/properties'
message:
type: string
AliasMatchAndExecuteInputAPI:
Expand Down Expand Up @@ -5168,8 +5168,9 @@ definitions:
skip_dependencies:
type: boolean
description: Set to True to skip pack dependency installations.
required: false
default: false
required:
- packs
PacksUninstall:
type: object
properties:
Expand All @@ -5194,6 +5195,10 @@ definitions:
type: array
items:
$ref: '#/definitions/PacksContentRegisterType'
fail_on_failure:
type: boolean
description: True to fail on failure
default: true
PacksContentRegisterType:
type: string
enum: ['all',
Expand Down