Skip to content
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

Validate request bodies using ajv #20

Draft
wants to merge 3 commits into
base: add-post-body-to-har-requests
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
],
"dependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"ajv": "^8.11.0",
"argparse": "^2.0.1",
"chalk": "4.1.2",
"js-yaml": "^4.1.0",
Expand Down
35 changes: 0 additions & 35 deletions scenarios/har/1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ paths:
required: true
schema:
type: integer
format: int64
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #19

For now I'm just going to say that we don't support custom formats.

We will add them once we feel that ajv works for our use case.

responses:
'200':
description: successful operation
Expand Down Expand Up @@ -234,7 +233,6 @@ paths:
required: true
schema:
type: integer
format: int64
- name: name
in: query
description: Name of pet that needs to be updated
Expand Down Expand Up @@ -271,7 +269,6 @@ paths:
required: true
schema:
type: integer
format: int64
responses:
'400':
description: Invalid pet value
Expand All @@ -293,7 +290,6 @@ paths:
required: true
schema:
type: integer
format: int64
- name: additionalMetadata
in: query
description: Additional Metadata
Expand Down Expand Up @@ -334,7 +330,6 @@ paths:
type: object
additionalProperties:
type: integer
format: int32
security:
- api_key: []
/store/order:
Expand Down Expand Up @@ -382,7 +377,6 @@ paths:
required: true
schema:
type: integer
format: int64
responses:
'200':
description: successful operation
Expand Down Expand Up @@ -413,7 +407,6 @@ paths:
required: true
schema:
type: integer
format: int64
responses:
'400':
description: Invalid ID supplied
Expand Down Expand Up @@ -503,12 +496,10 @@ paths:
description: calls per hour allowed by the user
schema:
type: integer
format: int32
X-Expires-After:
description: date in UTC when token expires
schema:
type: string
format: date-time
content:
application/xml:
schema:
Expand Down Expand Up @@ -610,23 +601,18 @@ externalDocs:
components:
schemas:
Order:
x-swagger-router-model: io.swagger.petstore.model.Order
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something we want to support? It's not part of the schema ajv understands out of the box.

It's not hard too add these but I'm not entirerly sure how common they are in the wild!

properties:
id:
type: integer
format: int64
example: 10
petId:
type: integer
format: int64
example: 198772
quantity:
type: integer
format: int32
example: 7
shipDate:
type: string
format: date-time
status:
type: string
description: Order Status
Expand All @@ -637,14 +623,11 @@ components:
example: approved
complete:
type: boolean
xml:
name: order
type: object
Customer:
properties:
id:
type: integer
format: int64
example: 100000
username:
type: string
Expand Down Expand Up @@ -677,24 +660,18 @@ components:
name: address
type: object
Category:
x-swagger-router-model: io.swagger.petstore.model.Category
properties:
id:
type: integer
format: int64
example: 1
name:
type: string
example: Dogs
xml:
name: category
type: object
User:
x-swagger-router-model: io.swagger.petstore.model.User
properties:
id:
type: integer
format: int64
example: 10
username:
type: string
Expand All @@ -716,32 +693,23 @@ components:
example: 12345
userStatus:
type: integer
format: int32
example: 1
description: User Status
xml:
name: user
type: object
Tag:
x-swagger-router-model: io.swagger.petstore.model.Tag
properties:
id:
type: integer
format: int64
name:
type: string
xml:
name: tag
type: object
Pet:
x-swagger-router-model: io.swagger.petstore.model.Pet
required:
- name
- photoUrls
properties:
id:
type: integer
format: int64
example: 10
name:
type: string
Expand Down Expand Up @@ -771,14 +739,11 @@ components:
- available
- pending
- sold
xml:
name: pet
type: object
ApiResponse:
properties:
code:
type: integer
format: int32
type:
type: string
message:
Expand Down
4 changes: 2 additions & 2 deletions scenarios/har/2/http.har
Original file line number Diff line number Diff line change
Expand Up @@ -4231,7 +4231,7 @@
"bodySize": 139,
"postData": {
"mimeType": "application/json",
"text": "{\n \"id\": 10,\n \"petId\": 198772,\n \"quantity\": 7,\n \"shipDate\": \"2022-07-19T08:35:06.175Z\",\n \"status\": \"approved\",\n \"complete\": truasde\n}"
"text": "{\n \"id\": 10,\n \"petId\": 198772,\n \"quantity\": 7,\n \"shipDate\": \"2022-07-19T08:35:06.175Z\",\n \"status\": \"approved\",\n \"complete\": true\n}"
}
},
"response": {
Expand Down Expand Up @@ -9144,4 +9144,4 @@
}
]
}
}
}
Loading