def create_models(client, module, rest_api_id, schemas):
"""
Creates models based on schemas.
"""
models = None
try:
for model in schemas.keys():
schema = schemas[model]
schema.update({
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"title": "{0} schema".format(model)
})
models = client.create_model(
restApiId=rest_api_id,
name=model,
description='added by Ansible module',
contentType='application/json',
schema=json.dumps(schema)
)
except (ClientError, ParamValidationError, MissingParametersError) as e:
#TODO: should report warning or update existing model
if not e.response['Error']['Code'] == 'ConflictException':
module.fail_json(msg='Error creating API model {0}: {1}'.format(model, e))
return models
评论列表
文章目录