Esempio n. 1
0
def update(api_version: str, config_files: str, input_file: str, output_file: str, generate: bool = False):
    """
    Updates OpenAPI spec based on current input file plus running configuration from apps.
    """
    logger.info(__name__, "openapi.update")
    if generate:
        api.setup(generate_mode=True)
    api.load_api_file(input_file)
    _update_api_spec(config_files)
    api.save_api_file(output_file, api_version)
Esempio n. 2
0
def create(api_version: str, title: str, description: str, config_files: str,
           output_file: str, generate: bool):
    """
    Creates OpenAPI spec file
    """
    logger.info(__name__, "openapi.update")
    if generate:
        api.setup(generate_mode=True)
    api.init_empty_spec(api_version, title, description)
    _update_api_spec(config_files)
    api.static_spec = api.spec
    api.save_api_file(output_file, api_version)
Esempio n. 3
0
def test_save_api_file(mock_api_spec):  # noqa: F811
    api.clear()
    file_name = f"/tmp/{str(uuid.uuid4())}.json"
    api.spec = mock_api_spec
    api.static_spec = deepcopy(mock_api_spec)
    api.save_api_file(file_name, api_version=mock_api_spec['info']['version'])
    with open(file_name, 'r') as fp:
        check_spec = json.load(fp)
    assert check_spec == mock_api_spec

    with pytest.raises(APIError):
        api.static_spec['info']['title'] = 'Simulating API Change'
        api.save_api_file(file_name,
                          api_version=mock_api_spec['info']['version'])

    api.save_api_file(file_name, api_version='9.9.9')
    with open(file_name, 'r') as fp:
        check_spec = json.load(fp)
    assert check_spec == mock_api_spec
    assert check_spec['info']['version'] == '9.9.9'
    os.remove(file_name)