Skip to content

Commit 94e709f

Browse files
committed
chore: upgrade azfn sdk
1 parent 575c45b commit 94e709f

File tree

7 files changed

+28
-38
lines changed

7 files changed

+28
-38
lines changed

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "Attach to Node Functions",
5+
"name": "Debug Functions app",
66
"type": "node",
77
"request": "attach",
88
"port": 9229,
99
"preLaunchTask": "func: host start"
1010
},
1111
{
12-
"name": "Test current file",
12+
"name": "Unit test current file",
1313
"type": "node",
1414
"request": "launch",
1515
"program": "${workspaceFolder}/node_modules/jest/bin/jest",

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
# Azure Functions Open API specification validation
1+
# Azure Functions Open API v3 specification validation
22

3-
This library contains an Open API validator and an Azure Functions v4 hook that validates http function requests.
3+
This library contains an Open API v3 validator and an Azure Functions v4 hook that validates http function requests.
44

55
It identifies the Azure function route and tries to find a matching route in the Open API specification. It then validates query parameters,
66
the request body and response body against the schema.
77

8-
(Note: This library does not validate the Open API specification itself. I suggest you use another tool for this for now.)
8+
## Caveats
9+
10+
* Early version: Bugs most likely exist. Bug fixes welcome and more test cases very welcom. :-)
11+
* So far only tested with Open API specifications in v3
12+
* This library does not validate the Open API specification itself. I suggest you use another tool for this for now.
913

1014
## Getting started
1115

@@ -59,9 +63,12 @@ setupValidation(openApiSpec, {
5963
To run the example function app locally from VSCode, make sure to install the Azure Functions and Azurite extensions.
6064
Then start Azurite via the `Azurite: Start` VSCode task.
6165

62-
Build the library `npm run build` or use `npm run watch` to hotdeploy changes.
66+
Build the library `npm run build` or use `npm run watch` to hotdeploy changes. (Warning: This didn't always work for me in practice.)
67+
68+
Start the function app by running the VScode launch configuration `Debug Functions app`.
6369

64-
Start the function app by running the VScode launch configuration "Attach to Node Functions".
70+
Then send some requests to the API, for example:
71+
`curl -X POST -H "Content-Type: application/json" -d '{"name":"hi"}' http://localhost:7071/api/users`
6572

6673
## License
6774

example/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"test": "echo \"No tests yet...\""
1414
},
1515
"dependencies": {
16-
"@azure/functions": "^4.0.0",
16+
"@azure/functions": "^4.2.0",
1717
"@restfulhead/azure-functions-nodejs-openapi-validator": "../src",
1818
"js-yaml": "^4.1.0"
1919
},

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"watch": "webpack --watch --mode development"
3434
},
3535
"dependencies": {
36-
"@azure/functions": "^4.0.0",
36+
"@azure/functions": "^4.2.0",
3737
"ajv": "^8.12.0",
3838
"ajv-draft-04": "^1.0.0",
3939
"allof-merge": "^0.6.1"

src/app.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,12 @@ export function setupValidation(
112112

113113
let parsedBody = undefined
114114
if (request.body) {
115-
const textBody = await origRequest.text()
116-
parsedBody = JSON.parse(textBody)
117-
118-
const headers: Record<string, string> = {}
119-
origRequest.headers?.forEach((value, key) => {
120-
headers[key] = value
121-
})
122-
123-
const query: Record<string, string> = {}
124-
origRequest.query?.forEach((value, key) => {
125-
query[key] = value
126-
})
127-
128115
// a copy is necessary, because the request body can only be consumed once
129116
// see https://github.com/Azure/azure-functions-nodejs-library/issues/79#issuecomment-1875214147
130-
request = new HttpRequest({
131-
method: origRequest.method,
132-
url: origRequest.url,
133-
body: { string: textBody },
134-
headers,
135-
query,
136-
params: origRequest.params,
137-
})
117+
request = origRequest.clone()
118+
119+
const textBody = await origRequest.text()
120+
parsedBody = JSON.parse(textBody)
138121
}
139122

140123
const reqBodyValResult = validator.validateRequestBody(

0 commit comments

Comments
 (0)