Skip to content

Commit

Permalink
test(oas): add more test data for binary data
Browse files Browse the repository at this point in the history
closes #181
  • Loading branch information
derevnjuk committed Feb 24, 2023
1 parent a09813d commit 52601e2
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/oas/tests/DefaultConverter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ describe('DefaultConverter', () => {
input: 'xml-models.swagger.yaml',
expected: 'xml-models.swagger.result.json',
message: 'should properly serialize models to XML (swagger)'
},
{
input: 'binary-body.swagger.yaml',
expected: 'binary-body.swagger.result.json',
message: 'should properly serialize binary types (swagger)'
},
{
input: 'binary-body.oas.yaml',
expected: 'binary-body.oas.result.json',
message: 'should properly serialize binary types (oas)'
}
].forEach(({ input: inputFile, expected: expectedFile, message }) => {
it(message, async () => {
Expand Down
78 changes: 78 additions & 0 deletions packages/oas/tests/fixtures/binary-body.oas.result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[
{
"bodySize": 0,
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/octet-stream"
}
],
"headersSize": 0,
"httpVersion": "HTTP/1.1",
"method": "POST",
"postData": {
"mimeType": "application/octet-stream",
"text": "\u0001\u0002\u0003\u0004\u0005"
},
"queryString": [],
"url": "https://petstore.swagger.io/binary"
},
{
"bodySize": 0,
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/octet-stream"
}
],
"headersSize": 0,
"httpVersion": "HTTP/1.1",
"method": "POST",
"postData": {
"mimeType": "application/octet-stream",
"text": "ZHVtbXkgYmluYXJ5IHNhbXBsZQA="
},
"queryString": [],
"url": "https://petstore.swagger.io/byte"
},
{
"bodySize": 0,
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/octet-stream"
}
],
"headersSize": 0,
"httpVersion": "HTTP/1.1",
"method": "POST",
"postData": {
"mimeType": "application/octet-stream",
"text": "ZHVtbXkgYmluYXJ5IHNhbXBsZQA="
},
"queryString": [],
"url": "https://petstore.swagger.io/base64"
},
{
"bodySize": 0,
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "multipart/form-data"
}
],
"headersSize": 0,
"httpVersion": "HTTP/1.1",
"method": "POST",
"postData": {
"mimeType": "multipart/form-data; boundary=956888039105887155673143",
"text": "--956888039105887155673143\r\nContent-Disposition: form-data; name=\"base64\"; filename=\"base64\"\r\nContent-Type: application/octet-stream\r\nContent-Transfer-Encoding: base64\r\n\r\nZHVtbXkgYmluYXJ5IHNhbXBsZQA=\r\n--956888039105887155673143\r\nContent-Disposition: form-data; name=\"binary\"; filename=\"binary\"\r\nContent-Type: application/octet-stream\r\n\r\n\u0001\u0002\u0003\u0004\u0005\r\n--956888039105887155673143\r\nContent-Disposition: form-data; name=\"byte\"; filename=\"byte\"\r\nContent-Type: application/octet-stream\r\nContent-Transfer-Encoding: base64\r\n\r\nZHVtbXkgYmluYXJ5IHNhbXBsZQA=\r\n--956888039105887155673143--"
},
"queryString": [],
"url": "https://petstore.swagger.io/multipart"
}
]
79 changes: 79 additions & 0 deletions packages/oas/tests/fixtures/binary-body.oas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
openapi: 3.0.0
info:
title: Binary Data API
version: 1.0.0
servers:
- url: https://petstore.swagger.io
paths:
/binary:
post:
summary: Upload plain binary data
requestBody:
content:
application/octet-stream:
schema:
type: string
format: binary
required: true
responses:
'200':
description: OK
/byte:
post:
summary: Upload byte data
requestBody:
content:
application/octet-stream:
schema:
type: string
format: byte
required: true
responses:
'200':
description: OK
/base64:
post:
summary: Upload base64 data
requestBody:
content:
application/octet-stream:
schema:
type: string
format: base64
required: true
responses:
'200':
description: OK
/multipart:
post:
summary: Upload multipart/form-data with binary data
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
base64:
type: string
format: base64
binary:
type: string
format: binary
byte:
type: string
format: byte
required:
- base64
- binary
- byte
encoding:
base64:
contentType: application/octet-stream
binary:
contentType: application/octet-stream
byte:
contentType: application/octet-stream
required: true
responses:
'200':
description: OK
78 changes: 78 additions & 0 deletions packages/oas/tests/fixtures/binary-body.swagger.result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[
{
"bodySize": 0,
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/octet-stream"
}
],
"headersSize": 0,
"httpVersion": "HTTP/1.1",
"method": "POST",
"postData": {
"mimeType": "application/octet-stream",
"text": "\u0001\u0002\u0003\u0004\u0005"
},
"queryString": [],
"url": "https://petstore.swagger.io/binary"
},
{
"bodySize": 0,
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/octet-stream"
}
],
"headersSize": 0,
"httpVersion": "HTTP/1.1",
"method": "POST",
"postData": {
"mimeType": "application/octet-stream",
"text": "ZHVtbXkgYmluYXJ5IHNhbXBsZQA="
},
"queryString": [],
"url": "https://petstore.swagger.io/byte"
},
{
"bodySize": 0,
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/octet-stream"
}
],
"headersSize": 0,
"httpVersion": "HTTP/1.1",
"method": "POST",
"postData": {
"mimeType": "application/octet-stream",
"text": "ZHVtbXkgYmluYXJ5IHNhbXBsZQA="
},
"queryString": [],
"url": "https://petstore.swagger.io/base64"
},
{
"bodySize": 0,
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "multipart/form-data"
}
],
"headersSize": 0,
"httpVersion": "HTTP/1.1",
"method": "POST",
"postData": {
"mimeType": "multipart/form-data; boundary=956888039105887155673143",
"text": "--956888039105887155673143\r\nContent-Disposition: form-data; name=\"base64\"\r\n\r\nlorem\r\n--956888039105887155673143\r\nContent-Disposition: form-data; name=\"binary\"\r\n\r\nlorem\r\n--956888039105887155673143\r\nContent-Disposition: form-data; name=\"byte\"\r\n\r\nlorem\r\n--956888039105887155673143--"
},
"queryString": [],
"url": "https://petstore.swagger.io/multipart"
}
]
77 changes: 77 additions & 0 deletions packages/oas/tests/fixtures/binary-body.swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
swagger: '2.0'
info:
version: 1.0.0
title: Binary Data API
host: 'petstore.swagger.io'
schemes:
- https
paths:
/binary:
post:
summary: Upload plain binary data
consumes:
- application/octet-stream
parameters:
- in: body
name: file
required: true
schema:
type: string
format: binary
responses:
'200':
description: OK
/byte:
post:
summary: Upload byte data
consumes:
- application/octet-stream
parameters:
- in: body
name: file
required: true
schema:
type: string
format: byte
responses:
'200':
description: OK
/base64:
post:
summary: Upload base64 data
consumes:
- application/octet-stream
parameters:
- in: body
name: file
required: true
schema:
type: string
format: base64
responses:
'200':
description: OK
/multipart:
post:
summary: Upload multipart/form-data with binary data
consumes:
- multipart/form-data
parameters:
- in: formData
name: base64
type: file
required: true
x-format: base64
- in: formData
name: binary
type: file
required: true
x-format: binary
- in: formData
name: byte
type: file
required: true
x-format: byte
responses:
'200':
description: OK

0 comments on commit 52601e2

Please sign in to comment.