Skip to content

Instantly share code, notes, and snippets.

@SudarAbisheck

SudarAbisheck/base.yml

Last active Mar 21, 2018
Embed
What would you like to do?
Combining multiple Swagger+APIGW using jq
---
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"
# 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
---
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
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
You can’t perform that action at this time.