Skip to content

Commit 046d595

Browse files
restfulheadPatrick Ruhkopf
authored andcommitted
feat: add exclusions
1 parent a9f6117 commit 046d595

File tree

12 files changed

+330
-84
lines changed

12 files changed

+330
-84
lines changed

example/host.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
{
22
"version": "2.0",
33
"logging": {
4+
"logLevel": {
5+
"default": "Information",
6+
"Function": "Debug"
7+
},
48
"applicationInsights": {
59
"samplingSettings": {
6-
"isEnabled": true,
10+
"isEnabled": false,
711
"excludedTypes": "Request"
812
}
913
}

example/package-lock.json

Lines changed: 5 additions & 5 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
@@ -29,7 +29,7 @@
2929
"eslint-import-resolver-typescript": "3.6.1",
3030
"eslint-plugin-unused-imports": "3.0.0",
3131
"prettier": "3.1.1",
32-
"typescript": "^4.0.0",
32+
"typescript": "5.3.3",
3333
"rimraf": "^5.0.0"
3434
},
3535
"main": "dist/src/functions/*.js"

example/src/functions/test.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as fs from 'fs'
22
import * as yaml from 'js-yaml'
3-
import { app, HttpResponseInit, InvocationContext } from '@azure/functions'
4-
import { setupValidation, ParsedRequestBodyHttpRequest } from '@restfulhead/azure-functions-nodejs-openapi-validator'
3+
import { app, HttpRequest, HttpResponseInit, InvocationContext } from '@azure/functions'
4+
import { setupValidation } from '@restfulhead/azure-functions-nodejs-openapi-validator'
55

66
/***
77
* Load the OpenAPI spec from a file and setup the validator
88
*/
9-
const openApiContent = fs.readFileSync(`${__dirname}/../../../../test/fixtures/openapi.yaml`, 'utf8')
9+
const openApiContent = fs.readFileSync(`${__dirname}/../../../src/openapi.yaml`, 'utf8')
1010
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1111
const openApiSpec = yaml.load(openApiContent) as any
1212

@@ -21,20 +21,29 @@ app.hook.postInvocation(async () => {
2121
await new Promise((resolve) => setTimeout(resolve, 50))
2222
})
2323

24-
// eslint-disable-next-line require-await
25-
export async function putUser(
26-
request: ParsedRequestBodyHttpRequest<{ name: string }>,
27-
context: InvocationContext
28-
): Promise<HttpResponseInit> {
24+
export async function postUser(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
2925
context.log(`Http function processed request for url "${request.url}"`)
3026

31-
const name = request.parsedBody.name
27+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
28+
const requestBody: any = await request.json()
3229

33-
return { body: `Hello, ${name}!` }
30+
return { jsonBody: { name: requestBody.name, id: '123' }, status: 201 }
3431
}
3532

36-
app.put('post-users-uid', {
33+
export function getUser(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
34+
context.log(`Http function processed request for url "${request.url}"`)
35+
36+
return Promise.resolve({ body: JSON.stringify({ name: 'jane doe', id: '456' }) })
37+
}
38+
39+
app.post('post-users', {
40+
route: 'users',
41+
authLevel: 'anonymous',
42+
handler: postUser,
43+
})
44+
45+
app.get('get-users-uid', {
3746
route: 'users/{uid}',
3847
authLevel: 'anonymous',
39-
handler: putUser,
48+
handler: getUser,
4049
})

example/src/openapi.yaml

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
openapi: '3.0.0'
2+
info:
3+
title: Test API
4+
version: '1.0'
5+
security:
6+
- apiKeyHeader: []
7+
- apiKeyQuery: []
8+
9+
paths:
10+
'/users':
11+
post:
12+
parameters:
13+
- name: uid
14+
in: path
15+
required: true
16+
schema:
17+
type: string
18+
requestBody:
19+
content:
20+
application/json:
21+
schema:
22+
$ref: '#/components/schemas/PutUserRequest'
23+
required: true
24+
responses:
25+
'201':
26+
description: CREATED
27+
content:
28+
application/json:
29+
schema:
30+
$ref: '#/components/schemas/UserResponse'
31+
'400':
32+
$ref: '#/components/responses/ResponseError'
33+
'500':
34+
$ref: '#/components/responses/ResponseError'
35+
'/users/{uid}':
36+
get:
37+
parameters:
38+
- name: uid
39+
in: path
40+
required: true
41+
schema:
42+
type: string
43+
- name: optionalparam
44+
in: query
45+
schema:
46+
type: string
47+
- name: requirednumberparam
48+
in: query
49+
required: true
50+
schema:
51+
type: number
52+
- name: integerparam
53+
in: query
54+
required: false
55+
schema:
56+
type: integer
57+
minimum: 1
58+
maximum: 5
59+
responses:
60+
'200':
61+
description: OK
62+
content:
63+
application/json:
64+
schema:
65+
$ref: '#/components/schemas/UserResponse'
66+
'400':
67+
$ref: '#/components/responses/ResponseError'
68+
'500':
69+
$ref: '#/components/responses/ResponseError'
70+
71+
72+
components:
73+
responses:
74+
ResponseError:
75+
description: An unexpected server error occurred
76+
content:
77+
application/json:
78+
schema:
79+
$ref: '#/components/schemas/Failure'
80+
81+
schemas:
82+
Links:
83+
type: object
84+
additionalProperties:
85+
type: string
86+
Failure:
87+
type: object
88+
required:
89+
- errors
90+
properties:
91+
errors:
92+
type: array
93+
items:
94+
'$ref': '#/components/schemas/ApiError'
95+
uniqueItems: true
96+
ApiError:
97+
type: object
98+
required:
99+
- status
100+
- code
101+
- title
102+
properties:
103+
id:
104+
description: A unique identifier for this particular occurrence of the problem.
105+
type: string
106+
links:
107+
'$ref': '#/components/schemas/Links'
108+
status:
109+
description: The HTTP status code applicable to this problem
110+
type: integer
111+
minimum: 100
112+
maximum: 599
113+
code:
114+
description: An application-specific error code, expressed as a string value.
115+
type: string
116+
enum: ["Unknown", "Validation", "Validation-required", "Validation-maxLength", "Validation-minLength", "Validation-type", "Validation-maximum", "Validation-minimum"]
117+
title:
118+
description: A short, human-readable summary of the problem. It **SHOULD NOT**
119+
change from occurrence to occurrence of the problem, except for purposes
120+
of localization.
121+
type: string
122+
detail:
123+
description: A human-readable explanation specific to this occurrence of the
124+
problem.
125+
type: string
126+
source:
127+
type: object
128+
properties:
129+
pointer:
130+
description: A JSON Pointer [RFC6901] to the associated entity in the
131+
request document [e.g. "/data" for a primary data object, or "/data/attributes/title"
132+
for a specific attribute].
133+
type: string
134+
parameter:
135+
description: A string indicating which query parameter caused the error.
136+
type: string
137+
138+
PageParam:
139+
type: object
140+
properties:
141+
limit:
142+
type: integer
143+
offset:
144+
type: integer
145+
nextLink:
146+
type: string
147+
148+
OffsetPagination:
149+
type: object
150+
required:
151+
- total
152+
properties:
153+
total:
154+
type: integer
155+
limit:
156+
type: integer
157+
offset:
158+
type: integer
159+
160+
PutUserRequest:
161+
type: object
162+
required:
163+
- name
164+
properties:
165+
name:
166+
type: string
167+
168+
UserResponse:
169+
type: object
170+
required:
171+
- name
172+
- id
173+
properties:
174+
name:
175+
type: string
176+
id:
177+
type: string

package-lock.json

Lines changed: 6 additions & 6 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
@@ -57,7 +57,7 @@
5757
"prettier": "3.1.1",
5858
"ts-jest": "29.1.1",
5959
"ts-loader": "9.5.1",
60-
"typescript": "^4.0.0",
60+
"typescript": "5.3.3",
6161
"webpack": "5.89.0",
6262
"webpack-cli": "5.1.4"
6363
},

0 commit comments

Comments
 (0)