Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIGateway Model Schema does not work with Join #784

Open
tomkerswill opened this issue Aug 14, 2017 · 3 comments
Open

APIGateway Model Schema does not work with Join #784

tomkerswill opened this issue Aug 14, 2017 · 3 comments

Comments

@tomkerswill
Copy link

Hi

I have a model schema, and want to use Join within the schema to pull in the correct absolute reference to another model schema.

(Note - to simplify, I have actually just used Join here to join some strings to make up the URL).

What seems to happen is that Troposphere converts the JSON into a string, but doesn't like the Join function.

test_schema = t.add_resource(Model( "test", Name = "test", ContentType="application/json", RestApiId=Ref(testApi), Schema={ "$schema": "http://json-schema.org/draft-04/schema#", "title": "test", "id": "/test", "type": "object", "properties": { "_id": {"type": "string"}, "trades": { "type": "array", "items": [{"$ref": Join("",["https://apigateway.amazonaws.com/restapis/", "abc123456", "/models/testreference"] ) } ] } } } ))

I've also tried using the "Fn::Join" native Cloudformation JSON, and that does allow the JSON file to be built without error, but escapes the Fn::Join into a string, so that when CloudFormation runs, it just treats that as the reference without doing the join.

@gkrizek
Copy link
Contributor

gkrizek commented Oct 5, 2017

@tomkerswill Have you tried putting the Join statement at the beginning of your JSON to include the entire JSON document in the Join statement? You would have the escape your quotations in the JSON document.

...
Schema=Join("", ["\"$schema\": \"http://json-schema.org/draft-04/schema#\", \"title\": \"test\", \"id\": \"/test\", \"type\": \"object\", \"properties\": { \"_id\": {\"type\": \"string\"}, \"trades\": { \"type\": \"array\", \"items\": [{\"$ref\": \"https://apigateway.amazonaws.com/restapis/", "abc123456", "/models/testreference\" } ] } } } "])
...

Not sure it would work.... Just an idea

@churnikorn
Copy link

churnikorn commented Dec 8, 2017

Hi, did anyone ever get this to work? It's been super painful since we only find out if it isn't working via attempted creations (vs just rendering/validating the template) even once the Join is serializable. A working example would be much appreciated!

@thejohnlin
Copy link

thejohnlin commented Dec 11, 2017

I think this has to do with the validation step (apigateway.Model.validate()) performing a json.dumps() on the entire Schema attribute when it's a dictionary. If the json_checker leaves the troposphere types (like Ref or Join) alone, troposphere is able to render the template. I'm hoping to address this with #946.

From the failed test condition I'm seeing right now from test_cloudwatch.py, it seems cloudwatch.Dashboard would exhibit the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants