-
Notifications
You must be signed in to change notification settings - Fork 156
feat(parser): add built-in schemas #1788
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
Changes from all commits
aa66d8c
64c3eb1
c5127f9
f0464ab
f353c7f
4a66dec
633ce9a
6078cb0
5bcab2e
0e9db61
fefe01a
c06989b
a4d3852
7a2a203
689ef45
7e0dd71
067fd82
04fd892
694f389
1408bb9
60b139b
1fdac46
f6d09d2
3f8f4bb
ccb51e1
208a66f
d8919d3
8eefbe8
eceea76
f67a8e1
955d277
f165302
06d5467
1af893a
a9cfa6a
2d671d0
7cdcc0b
dd39001
bd0cefe
7b33250
51219a8
bbf5ac3
d8a040f
254ebd7
e0dcf23
0b6d570
f453246
455b329
228217e
e330e51
8ce4af6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,4 @@ | |
}, | ||
"body": "{\"user\":\"xyz\",\"productId\":\"123456789\"}", | ||
"isBase64Encoded": false | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
"name": "foo", | ||
"productId": 10000 | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
"name": "Foo" | ||
}, | ||
"productId": 10000 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,4 @@ | |
"awsRegion": "us-east-2" | ||
} | ||
] | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { z } from 'zod'; | ||
|
||
const AlbSchema = z.object({ | ||
httpMethod: z.string(), | ||
path: z.string(), | ||
body: z.string(), | ||
isBase64Encoded: z.boolean(), | ||
headers: z.record(z.string(), z.string()).optional(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that both Is this to allow the multi value extension later? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, once you turn on multi header, you can't pass headers, thus examples with multi-values break. pt-py did not test this case, or I could not find it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have looked into possible options and atm there is no straight forward way to have multiple mutually exclusive key/value pairs. It's not impossible, just needs more dedicated time to go through few options and pick the best. I'd suggest to move forward as it is now and come back later. |
||
queryStringParameters: z.record(z.string(), z.string()).optional(), | ||
requestContext: z.object({ | ||
elb: z.object({ | ||
targetGroupArn: z.string(), | ||
}), | ||
}), | ||
}); | ||
|
||
const AlbMultiValueHeadersSchema = AlbSchema.extend({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The schema includes also multi value query string parameters, should we name this something more generic i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The semantic link between the schema and the feature is in wording Multi-Value Header, thus I assume it's easier to connect the feature in the service and the schema values. I'd suggest to keep it. |
||
multiValueHeaders: z.record(z.string(), z.array(z.string())), | ||
multiValueQueryStringParameters: z.record(z.string(), z.array(z.string())), | ||
}); | ||
|
||
export { AlbSchema, AlbMultiValueHeadersSchema }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { z } from 'zod'; | ||
|
||
const APIGatewayCert = z.object({ | ||
clientCertPem: z.string(), | ||
subjectDN: z.string(), | ||
issuerDN: z.string(), | ||
serialNumber: z.string(), | ||
validity: z.object({ | ||
notBefore: z.string(), | ||
notAfter: z.string(), | ||
}), | ||
}); | ||
|
||
const APIGatewayEventIdentity = z.object({ | ||
accessKey: z.string().nullish(), | ||
accountId: z.string().nullish(), | ||
apiKey: z.string().nullish(), | ||
apiKeyId: z.string().nullish(), | ||
caller: z.string().nullish(), | ||
cognitoAuthenticationProvider: z.string().nullish(), | ||
cognitoAuthenticationType: z.string().nullish(), | ||
cognitoIdentityId: z.string().nullish(), | ||
cognitoIdentityPoolId: z.string().nullish(), | ||
principalOrgId: z.string().nullish(), | ||
sourceIp: z.string().ip().optional(), | ||
user: z.string().nullish(), | ||
userAgent: z.string().nullish(), | ||
userArn: z.string().nullish(), | ||
clientCert: APIGatewayCert.nullish(), | ||
}); | ||
|
||
const APIGatewayEventRequestContext = z | ||
.object({ | ||
accountId: z.string(), | ||
apiId: z.string(), | ||
authorizer: z | ||
.object({ | ||
claims: z.record(z.string(), z.any()).nullish(), | ||
scopes: z.array(z.string()).nullish(), | ||
}) | ||
.nullish(), | ||
stage: z.string(), | ||
protocol: z.string(), | ||
identity: APIGatewayEventIdentity, | ||
requestId: z.string(), | ||
requestTime: z.string(), | ||
requestTimeEpoch: z.number(), | ||
resourceId: z.string().nullish(), | ||
resourcePath: z.string(), | ||
domainName: z.string().nullish(), | ||
domainPrefix: z.string().nullish(), | ||
extendedRequestId: z.string().nullish(), | ||
httpMethod: z.enum([ | ||
'GET', | ||
'POST', | ||
'PUT', | ||
'PATCH', | ||
'DELETE', | ||
'HEAD', | ||
'OPTIONS', | ||
]), | ||
path: z.string(), | ||
connectedAt: z.number().nullish(), | ||
connectionId: z.string().nullish(), | ||
eventType: z.enum(['CONNECT', 'MESSAGE', 'DISCONNECT']).nullish(), | ||
messageDirection: z.string().nullish(), | ||
messageId: z.string().nullish(), | ||
routeKey: z.string().nullish(), | ||
operationName: z.string().nullish(), | ||
}) | ||
.refine( | ||
(input) => { | ||
return ( | ||
!input.messageId || (input.messageId && input.eventType === 'MESSAGE') | ||
); | ||
}, | ||
{ | ||
message: 'messageId is available only when `eventType` is MESSAGE', | ||
} | ||
); | ||
|
||
const APIGatewayProxyEventSchema = z.object({ | ||
version: z.string().optional(), | ||
authorizationToken: z.string().optional(), | ||
identitySource: z.string().optional(), | ||
methodArn: z.string().optional(), | ||
type: z.enum(['TOKEN', 'REQUEST']).optional(), | ||
resource: z.string(), | ||
path: z.string(), | ||
httpMethod: z.enum([ | ||
dreamorosi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'GET', | ||
'POST', | ||
'PUT', | ||
'PATCH', | ||
'DELETE', | ||
'HEAD', | ||
'OPTIONS', | ||
]), | ||
headers: z.record(z.string()).optional(), | ||
dreamorosi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
queryStringParameters: z.record(z.string()).optional(), | ||
multiValueHeaders: z.record(z.array(z.string())).optional(), | ||
dreamorosi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
multiValueQueryStringParameters: z.record(z.array(z.string())).optional(), | ||
requestContext: APIGatewayEventRequestContext, | ||
pathParameters: z.record(z.string()).optional().nullish(), | ||
stageVariables: z.record(z.string()).optional().nullish(), | ||
isBase64Encoded: z.boolean().optional(), | ||
body: z.string().optional(), | ||
dreamorosi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
export { APIGatewayProxyEventSchema, APIGatewayCert }; |
Uh oh!
There was an error while loading. Please reload this page.