This file contains hidden or 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
//find the root resource | |
List<Resource> resources = gateway | |
.getResources(new GetResourcesRequest().withRestApiId(targetRestApi.getId())).getItems(); | |
Resource rootResource = resources.stream().filter(resource -> resource.getPath().equals(File.separator)).findFirst().orElseThrow(RuntimeException::new); | |
// add our resource with a path and save its id | |
String resourceId=gateway.createResource(new CreateResourceRequest().withParentId(rootResourceId).withRestApiId(targetRestApiId) | |
.withPathPart(pathPart)).getId(); |
This file contains hidden or 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
/* our model variable should include some json schema model like | |
{ | |
"type":"object", | |
"properties":{ | |
"a":{"type":"integer"}, | |
"b":{"type":"integer"}, | |
"op":{"type":"string"} | |
}, | |
"title":"Input" | |
} |
This file contains hidden or 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
Map<String, String> modelName = new HashMap<String, String>() {{ | |
put("application/json", inputModelName); | |
}}; | |
gateway.putMethod(new PutMethodRequest().withResourceId(resourceId) | |
.withRestApiId(targetRestApiId) | |
.withAuthorizationType("NONE") | |
.withRequestModels(modelName) | |
.withHttpMethod("POST")); |
This file contains hidden or 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
Map<String, String> modelName = new HashMap<String, String>() {{ | |
put("application/json", outputModelName); | |
}}; | |
//rootResource was found previously | |
gateway.putMethodResponse(new PutMethodResponseRequest() | |
.withHttpMethod("POST") | |
.withResponseModels(modelName) | |
.withRestApiId(targetRestApiId) | |
.withResourceId(rootResource) |
This file contains hidden or 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
AWSLambda awsLambda = AWSLambdaClientBuilder.standard() | |
.withCredentials(new AWSStaticCredentialsProvider(awsCreds)).withRegion(region).build(); | |
FunctionConfiguration targetFunction = awsLambda.getFunction(new GetFunctionRequest().withFunctionName(lambdaName)).getConfiguration(); |
This file contains hidden or 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
gateway.putIntegration(new PutIntegrationRequest() | |
.withCredentials(lambdaExecutionRole) | |
.withIntegrationHttpMethod("POST") | |
.withHttpMethod("POST") | |
.withType(IntegrationType.AWS) | |
.withRestApiId(targetRestApiId) | |
.withResourceId(rootResourceId) | |
.withPassthroughBehavior("WHEN_NO_MATCH") | |
.withUri(String.format(URI_TEMPLATE, targetFunction.getFunctionArn()))); |
This file contains hidden or 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
gateway.putIntegrationResponse(new PutIntegrationResponseRequest().withRestApiId(targetRestApiId) | |
.withResourceId(rootResourceId) | |
.withHttpMethod("POST") | |
.withStatusCode("200")); |
This file contains hidden or 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
gateway.createDeployment(new CreateDeploymentRequest() | |
.withRestApiId(targetRestApi.getId()) | |
.withStageName(deploymentStageName)); |
This file contains hidden or 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
export function requiredIf(requiredIf:boolean): ValidatorFn { | |
return (control: AbstractControl): ValidationErrors | null => { | |
let value = c.value; | |
if ((value == null || value == undefined || value == "") && requiredIf) { | |
return { | |
requiredIf: {condition:requiredIf} | |
}; |
This file contains hidden or 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
export function requiredIf(requiredIf:{value:boolean}): ValidatorFn { | |
return (control: AbstractControl): ValidationErrors | null => { | |
let value = control.value; | |
if ((value == null || value == undefined || value == "") && requiredIf.value) { | |
return { | |
requiredIf: {condition:requiredIf.value} | |
}; | |
} |