node.js - How do I add a Request Model for a POST end point in serverless framework -


how add request model post end point appears in api gateway when export api ios? can manually add request model in aws, since deployed through server less need in there. see there's responsemodels defining endpoints, can't see requestmodels?

my s-functions.json has this

"endpoints": [     {       "path": "blog/graphql",       "method": "post",       "type": "aws",       "authorizationtype": "aws_iam",       "authorizerfunction": false,       "apikeyrequired": false,       "requestparameters": {},       "requesttemplates": {         "application/json": "{\"query\" : $input.json(\"$\")}"       },       "responses": {         "400": {           "statuscode": "400"         },         "default": {           "statuscode": "200",           "responseparameters": {},           "responsemodels": {},           "responsetemplates": {},           "application/json": ""         }       }     }   ] 

in aws apigateway need manually add request model as

{     "title": "example schema",     "type": "object",     "properties": {         "query": {             "type": "string"         }     },     "required": ["query"] } 

when export api ios correct method in order send graphql query , works.

but, since want deploy serverless deploy, can't keep adding manually.

and need api endpoint call go through apigateway sdk fro ios in order use cognito credentials, rather manually doing https.

it looks serverless project's lib/endpoint.js doesn't include entry requestmodels, project actively maintained perhaps can raise issue on github them add support. thought might useful share aws cli approach in meantime.

you create request models same way create response models, having created them there isn't simple command equivalent aws apigateway put-method-response associate request models method. seems missing feature of aws cli.

however, got working using aws apigateway update-method. need have created model request first, , command adds method.

aws apigateway update-method \   --region $region \   --rest-api-id "$rest_api_id" \   --resource-id "$resource_id" \   --http-method $method \   --patch-operations "op=add,path=/requestmodels/application~1json,value=${request_model_name}" 

note odd application~1json construct stop slash in application/json being interpreted part of path.

incidentally tried , failed json file argument --patch-operations working. if can shed light on why file leads error below i'd love hear it.

$ cat patch.json {     "patchoperations":[{         "op" : "add",         "path" : "/requestmodels/application~1json",         "value" : "testrequest"     }] } $ aws apigateway update-method \   --rest-api-id abc123 \   --resource-id def456 \   --http-method post \   --patch-operations "file://patch.json" error parsing parameter '--patch-operations': invalid json: expecting property name enclosed in double quotes: line 1 column 2 (char 1) json received: { 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -