# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
"""Tests ensuring codebase style compliance for the OpenAPI specification."""

import os
import yaml


def check_swagger_style(yaml_spec):
    """Check if the swagger definition is correctly formatted."""
    with open(yaml_spec, 'r') as file_stream:
        try:
            yaml.safe_load(file_stream)
        # pylint: disable=broad-except
        except Exception as exception:
            print(str(exception))


def test_firecracker_swagger():
    """Fail if Firecracker swagger specification is malformed."""
    yaml_spec = os.path.normpath(
        os.path.join(os.getcwd(), '../src/api_server/swagger/firecracker.yaml')
    )
    check_swagger_style(yaml_spec)

@@ -206,18 +206,50 @@
 rt yaml%0A
+import framework.utils as utils
 %0A%0A
+%0A
 def chec
@@ -246,31 +246,28 @@
 %0A%0Adef check_
-swagger
+yaml
 _style(yaml_
@@ -552,16 +552,301 @@
 ion))%0A%0A%0A
+def validate_swagger(swagger_spec):%0A    %22%22%22Fail if OpenApi spec is not followed.%22%22%22%0A    validate_cmd = 'swagger-cli validate %7B%7D'.format(swagger_spec)%0A    retcode, stdout, _ = utils.run_cmd(validate_cmd)%0A%0A    # Verify validity.%0A    assert %22is valid%22 in stdout%0A    assert retcode == 0%0A%0A%0A
 def test
@@ -939,20 +939,23 @@
 %22%22%22%0A    
-yaml
+swagger
 _spec = 
@@ -1072,26 +1072,61 @@
 eck_
-swagger_style(yaml
+yaml_style(swagger_spec)%0A    validate_swagger(swagger
 _spe

add swagger spec validation