Last active
March 21, 2018 12:30
-
-
Save b1zantine/c1e00cf420132d733de8759adff37d5a to your computer and use it in GitHub Desktop.
Combining multiple Swagger+APIGW using jq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
swagger: 2.0 | |
basePath: /prod | |
info: | |
title: AwsSamExample | |
bschemes: | |
- https | |
paths: | |
/: | |
x-amazon-apigateway-any-method: | |
produces: | |
- application/json | |
responses: | |
'200': | |
description: 200 response | |
schema: | |
$ref: "#/definitions/Empty" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install jq | |
brew install jq | |
# Install PyYAML | |
pip install pyyaml | |
# Converts the YAML files to JSON | |
python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=2)' < base.yml > base.json | |
python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=2)' < ext.yml > ext.json | |
# Merges both json files into a single json | |
jq -s '.[0] * .[1]' ext.json base.json > final.json | |
# Converts the final json file back to yaml | |
python -c 'import sys, yaml, json; yaml.dump(json.load(sys.stdin), sys.stdout, indent=2)' < final.json > final.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
paths: | |
/: | |
x-amazon-apigateway-integration: | |
responses: | |
default: | |
statusCode: 200 | |
# NOTE: ${LambdaFunction} must match the Lambda resourcename | |
uri: | |
Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction.Arn}/invocations" | |
passthroughBehavior: when_no_match | |
httpMethod: POST | |
type: aws_proxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
swagger: 2 | |
basePath: /prod | |
bschemes: [https] | |
info: {title: AwsSamExample} | |
paths: | |
/: | |
x-amazon-apigateway-any-method: | |
produces: [application/json] | |
responses: | |
'200': null | |
description: 200 response | |
schema: {$ref: '#/definitions/Empty'} | |
x-amazon-apigateway-integration: | |
httpMethod: POST | |
passthroughBehavior: when_no_match | |
responses: | |
default: {statusCode: 200} | |
type: aws_proxy | |
uri: {'Fn::Sub': 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction.Arn}/invocations'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment