Skip to content

Commit 80154b1

Browse files
authored
fix required request body missing not rendering (#2644)
1 parent bff31a2 commit 80154b1

File tree

12 files changed

+56
-43
lines changed

12 files changed

+56
-43
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "openapi-workspaces",
33
"license": "MIT",
44
"private": true,
5-
"version": "0.53.19",
5+
"version": "0.53.20",
66
"workspaces": [
77
"projects/json-pointer-helpers",
88
"projects/openapi-io",

projects/fastify-capture/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@useoptic/fastify-capture",
33
"license": "MIT",
44
"packageManager": "[email protected]",
5-
"version": "0.53.19",
5+
"version": "0.53.20",
66
"main": "build/index.js",
77
"types": "build/index.d.ts",
88
"files": [

projects/json-pointer-helpers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@useoptic/json-pointer-helpers",
33
"license": "MIT",
44
"packageManager": "[email protected]",
5-
"version": "0.53.19",
5+
"version": "0.53.20",
66
"main": "build/index.js",
77
"types": "build/index.d.ts",
88
"files": [

projects/openapi-io/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@useoptic/openapi-io",
33
"license": "MIT",
44
"packageManager": "[email protected]",
5-
"version": "0.53.19",
5+
"version": "0.53.20",
66
"main": "build/index.js",
77
"types": "build/index.d.ts",
88
"files": [

projects/openapi-utilities/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@useoptic/openapi-utilities",
33
"license": "MIT",
44
"packageManager": "[email protected]",
5-
"version": "0.53.19",
5+
"version": "0.53.20",
66
"main": "build/index.js",
77
"types": "build/index.d.ts",
88
"files": [

projects/optic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@useoptic/optic",
33
"license": "MIT",
44
"packageManager": "[email protected]",
5-
"version": "0.53.19",
5+
"version": "0.53.20",
66
"main": "build/index.js",
77
"types": "build/index.d.ts",
88
"files": [

projects/optic/src/__tests__/integration/__snapshots__/capture.test.ts.snap

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,11 +1869,12 @@ GET /books
18691869
[200 response body] 'author_id' is now type number (/properties/books/items/properties/author_id)
18701870
[200 response body] 'status' now has enum value 'hold' (/properties/books/items/properties/status/enum)
18711871
[200 response body] schema (/properties/books/items/properties/price/maximum) with keyword 'maximum' and parameters {"comparison":"<=","limit":6} received invalid values 10, 15
1872-
[31m ⛔️ schema could not be automatically updated. Update the schema manually at [4mopenapi.yml:55:1281[24m[39m
1872+
[31m ⛔️ schema could not be automatically updated. Update the schema manually at [4mopenapi.yml:56:1304[24m[39m
18731873
POST /books
18741874
✓ Request Body, ✓ 200 response
18751875
[200 response body] body has been added
18761876
[request body] 'price' is now type string (/properties/price)
1877+
[request body] body is now optional
18771878
18781879
Learning path patterns for unmatched requests...
18791880
Documenting new operations:
@@ -1893,6 +1894,7 @@ paths:
18931894
/books:
18941895
post:
18951896
requestBody:
1897+
required: false
18961898
content:
18971899
application/json:
18981900
schema:
@@ -2083,11 +2085,12 @@ GET /books
20832085
[200 response body] 'author_id' is now type number (/properties/books/items/properties/author_id)
20842086
[200 response body] 'status' now has enum value 'hold' (/properties/books/items/properties/status/enum)
20852087
[200 response body] schema (/properties/books/items/properties/price/maximum) with keyword 'maximum' and parameters {"comparison":"<=","limit":6} received invalid values 10, 15
2086-
[31m ⛔️ schema could not be automatically updated. Update the schema manually at [4mopenapi.yml:55:1281[24m[39m
2088+
[31m ⛔️ schema could not be automatically updated. Update the schema manually at [4mopenapi.yml:56:1304[24m[39m
20872089
POST /books
20882090
✓ Request Body, ✓ 200 response
20892091
[200 response body] body has been added
20902092
[request body] 'price' is now type string (/properties/price)
2093+
[request body] body is now optional
20912094
20922095
4 unmatched requests
20932096
@@ -2105,6 +2108,7 @@ paths:
21052108
/books:
21062109
post:
21072110
requestBody:
2111+
required: false
21082112
content:
21092113
application/json:
21102114
schema:
@@ -2233,54 +2237,55 @@ GET /books
22332237
[200 response body] 'updated_at' is not documented (/properties/books/items/properties)
22342238
[200 response body] 'author_id' does not match type number. Received 6nTxAFM5ck4Hob77hGQoL (/properties/books/items/properties/author_id)
22352239
 Diff  'author_id' did not match schema
2236-
[90m43 |[39m properties:
2237-
[90m44 |[39m id:
2238-
[90m45 |[39m type: string
2239-
[90m46 |[39m [1m[33m author_id: [41m[Actual] "6nTxAFM5ck4Hob77hGQoL"[49m[39m[22m
2240-
[90m47 |[39m type: number
2241-
[90m48 |[39m status:
2242-
[90m49 |[39m type: string
2240+
[90m44 |[39m properties:
2241+
[90m45 |[39m id:
2242+
[90m46 |[39m type: string
2243+
[90m47 |[39m [1m[33m author_id: [41m[Actual] "6nTxAFM5ck4Hob77hGQoL"[49m[39m[22m
2244+
[90m48 |[39m type: number
2245+
[90m49 |[39m status:
2246+
[90m50 |[39m type: string
22432247
$workspace$/openapi.yml
22442248
22452249
[200 response body] 'status' missing enum value 'hold' (/properties/books/items/properties/status/enum)
22462250
 Diff  'status' does not have enum value hold
2247-
[90m47 |[39m type: number
2248-
[90m48 |[39m status:
2249-
[90m49 |[39m type: string
2250-
[90m50 |[39m [1m[33m enum: [41mmissing enum value 'hold'[49m[39m[22m
2251-
[90m51 |[39m - ready
2252-
[90m52 |[39m - not_ready
2253-
[90m53 |[39m price:
2251+
[90m48 |[39m type: number
2252+
[90m49 |[39m status:
2253+
[90m50 |[39m type: string
2254+
[90m51 |[39m [1m[33m enum: [41mmissing enum value 'hold'[49m[39m[22m
2255+
[90m52 |[39m - ready
2256+
[90m53 |[39m - not_ready
2257+
[90m54 |[39m price:
22542258
$workspace$/openapi.yml
22552259
22562260
[200 response body] schema (/properties/books/items/properties/price/maximum) with keyword 'maximum' and parameters {"comparison":"<=","limit":6} received invalid values 10, 15
22572261
 Diff  interaction did not match schema
2258-
[90m52 |[39m - not_ready
2259-
[90m53 |[39m price:
2260-
[90m54 |[39m type: number
2261-
[90m55 |[39m [1m[33m maximum: 6 [41m[Actual] 10, 15[49m[39m[22m
2262-
[90m56 |[39m minimum: 2
2263-
[90m57 |[39m required:
2264-
[90m58 |[39m - id
2262+
[90m53 |[39m - not_ready
2263+
[90m54 |[39m price:
2264+
[90m55 |[39m type: number
2265+
[90m56 |[39m [1m[33m maximum: 6 [41m[Actual] 10, 15[49m[39m[22m
2266+
[90m57 |[39m minimum: 2
2267+
[90m58 |[39m required:
2268+
[90m59 |[39m - id
22652269
$workspace$/openapi.yml
22662270
22672271
POST /books
22682272
× Request Body
22692273
[200 response body] body is not documented
22702274
[request body] 'price' does not match type string. Received 1 (/properties/price)
22712275
 Diff  'price' did not match schema
2272-
[90m15 |[39m properties:
2273-
[90m16 |[39m name:
2274-
[90m17 |[39m type: string
2275-
[90m18 |[39m [1m[33m price: [41m[Actual] 1[49m[39m[22m
2276-
[90m19 |[39m type: string
2277-
[90m20 |[39m author_id:
2278-
[90m21 |[39m type: string
2276+
[90m16 |[39m properties:
2277+
[90m17 |[39m name:
2278+
[90m18 |[39m type: string
2279+
[90m19 |[39m [1m[33m price: [41m[Actual] 1[49m[39m[22m
2280+
[90m20 |[39m type: string
2281+
[90m21 |[39m author_id:
2282+
[90m22 |[39m type: string
22792283
$workspace$/openapi.yml
22802284
2285+
[request body] body is required and missing
22812286
2282-
100.0% coverage of your documented operations. 4 requests did not match a documented path (6 total requests).
2283-
12 diffs detected in documented operations
2287+
100.0% coverage of your documented operations. 4 requests did not match a documented path (7 total requests).
2288+
13 diffs detected in documented operations
22842289
22852290
New endpoints are only added in interactive mode. Run 'optic capture openapi.yml --update interactive' to add new endpoints
22862291
"
@@ -2300,9 +2305,10 @@ POST /books
23002305
× Request Body
23012306
[200 response body] body is not documented
23022307
[request body] 'price' does not match type string. Received 1 (/properties/price)
2308+
[request body] body is required and missing
23032309
2304-
100.0% coverage of your documented operations. 4 requests did not match a documented path (6 total requests).
2305-
8 diffs detected in documented operations
2310+
100.0% coverage of your documented operations. 4 requests did not match a documented path (7 total requests).
2311+
9 diffs detected in documented operations
23062312
23072313
New endpoints are only added in interactive mode. Run 'optic capture openapi.yml --update interactive' to add new endpoints
23082314
"

projects/optic/src/__tests__/integration/workspaces/capture/with-server/openapi.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ paths:
77
/books:
88
post:
99
requestBody:
10+
required: true
1011
content:
1112
application/json:
1213
schema:

projects/optic/src/__tests__/integration/workspaces/capture/with-server/optic.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ capture:
4242
name: asd
4343
price: 1
4444
author_id: 6nTxAFM5ck4Hob77hGQoL
45+
- path: /books
46+
method: POST
4547
- path: /authors
4648
method: GET
4749
openapi-prefixed-url.yml:

projects/optic/src/commands/capture/actions/documented.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ function summarizePatch(
6464
const { diff, path, groupedOperations } = patch;
6565
const color = options.mode === 'update' ? chalk.green : chalk.red;
6666
if (!diff || groupedOperations.length === 0) return [];
67-
if (
67+
if (diff.kind === 'MissingRequestBody') {
68+
const action =
69+
options.mode === 'update' ? 'is now optional' : 'is required and missing';
70+
return [color(`[request body] body ${action}`)];
71+
} else if (
6872
diff.kind === 'UnmatchdResponseBody' ||
6973
diff.kind === 'UnmatchedRequestBody' ||
7074
diff.kind === 'UnmatchedResponseStatusCode'

0 commit comments

Comments
 (0)