Skip to content

Commit d243b10

Browse files
committed
test(explorer): add multipartEncoding.yaml demo for encoding.contentType support
Three endpoints covering: - File part with explicit contentType - JSON metadata + binary file (canonical #1247 use-case) - Mixed parts (some with encoding, some without) Servers point to HTTPBin so the actual request parts can be inspected in the response body. Related to #1247
1 parent 3a88588 commit d243b10

1 file changed

Lines changed: 144 additions & 0 deletions

File tree

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
openapi: 3.1.0
2+
info:
3+
title: Multipart Encoding Demo API
4+
description: |
5+
Demonstrates OAS `encoding.contentType` support for `multipart/form-data` parts.
6+
7+
Per the OAS spec, the `encoding` object lets you declare the Content-Type for
8+
individual form parts. Without this fix, all parts sent `application/octet-stream`
9+
regardless of the declared encoding.
10+
11+
**Cases covered:**
12+
- File part with explicit `contentType` (e.g. `text/plain`, `image/png`)
13+
- String/JSON part with explicit `contentType: application/json`
14+
- Multiple parts with mixed encoding
15+
- Parts without encoding (default browser behaviour)
16+
version: 1.0.0
17+
servers:
18+
- url: https://httpbin.org
19+
description: HTTPBin (inspect actual request parts in the response)
20+
tags:
21+
- name: multipartEncoding
22+
description: Multipart encoding content-type tests
23+
paths:
24+
/post/file-with-content-type:
25+
post:
26+
tags:
27+
- multipartEncoding
28+
summary: File part with explicit contentType
29+
description: |
30+
Verifies that a binary file part declared with `encoding.contentType: text/plain`
31+
is sent with `Content-Type: text/plain` rather than `application/octet-stream`.
32+
33+
Upload any file — check the generated code snippet and (via HTTPBin) the actual
34+
request to confirm the part Content-Type is `text/plain`.
35+
36+
Schema:
37+
```yaml
38+
encoding:
39+
file:
40+
contentType: text/plain
41+
```
42+
requestBody:
43+
required: true
44+
content:
45+
multipart/form-data:
46+
schema:
47+
type: object
48+
properties:
49+
file:
50+
description: The file to upload.
51+
type: string
52+
format: binary
53+
required:
54+
- file
55+
encoding:
56+
file:
57+
contentType: text/plain
58+
responses:
59+
"200":
60+
description: Request echoed by HTTPBin — inspect `files` for Content-Type
61+
62+
/post/json-metadata-and-file:
63+
post:
64+
tags:
65+
- multipartEncoding
66+
summary: JSON metadata part + binary file part
67+
description: |
68+
Verifies that:
69+
- The `metadata` string part is sent with `Content-Type: application/json`
70+
- The `file` binary part is sent with `Content-Type: image/png`
71+
72+
This is the canonical use-case from issue #1247.
73+
74+
Schema:
75+
```yaml
76+
encoding:
77+
metadata:
78+
contentType: application/json
79+
file:
80+
contentType: image/png
81+
```
82+
requestBody:
83+
required: true
84+
content:
85+
multipart/form-data:
86+
schema:
87+
type: object
88+
properties:
89+
metadata:
90+
description: JSON metadata for the file.
91+
type: string
92+
file:
93+
description: The file to upload.
94+
type: string
95+
format: binary
96+
required:
97+
- metadata
98+
- file
99+
encoding:
100+
metadata:
101+
contentType: application/json
102+
file:
103+
contentType: image/png
104+
responses:
105+
"200":
106+
description: Request echoed by HTTPBin — inspect part Content-Types
107+
108+
/post/mixed-encoding:
109+
post:
110+
tags:
111+
- multipartEncoding
112+
summary: Mixed — some parts with encoding, some without
113+
description: |
114+
Verifies that parts without an `encoding` entry use the browser default
115+
while parts with `encoding.contentType` use the declared value.
116+
117+
- `label` — no encoding declared → default (`text/plain`)
118+
- `data` — `contentType: application/json`
119+
- `attachment` — `contentType: application/octet-stream` (explicit)
120+
requestBody:
121+
required: true
122+
content:
123+
multipart/form-data:
124+
schema:
125+
type: object
126+
properties:
127+
label:
128+
description: A plain text label (no encoding declared).
129+
type: string
130+
data:
131+
description: A JSON payload sent as application/json.
132+
type: string
133+
attachment:
134+
description: A file sent as application/octet-stream.
135+
type: string
136+
format: binary
137+
encoding:
138+
data:
139+
contentType: application/json
140+
attachment:
141+
contentType: application/octet-stream
142+
responses:
143+
"200":
144+
description: Request echoed by HTTPBin — inspect part Content-Types

0 commit comments

Comments
 (0)