Skip to content

Commit

Permalink
Support query params and missing headers / response headers in capture (
Browse files Browse the repository at this point in the history
  • Loading branch information
niclim authored Nov 2, 2023
1 parent 371fcb1 commit f4fec04
Show file tree
Hide file tree
Showing 36 changed files with 6,654 additions and 5,763 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,17 @@ paths:
get:
responses:
{}
parameters:
- schema:
type: string
in: query
name: foo1
required: true
- schema:
type: string
in: query
name: foo2
required: true
/cookies:
get:
responses:
Expand Down Expand Up @@ -377,6 +388,17 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/GetGet200ResponseBody"
parameters:
- schema:
type: string
in: query
name: foo1
required: true
- schema:
type: string
in: query
name: foo2
required: true
/gzip:
get:
responses:
Expand Down Expand Up @@ -451,6 +473,27 @@ paths:
text/html:
schema:
type: string
parameters:
- schema:
type: string
in: query
name: foo1
required: true
- schema:
type: string
in: query
name: foo2
required: true
- schema:
type: string
in: query
name: Content-Type
required: true
- schema:
type: string
in: query
name: test
required: true
/status/{status}:
parameters:
- in: path
Expand Down Expand Up @@ -494,6 +537,42 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/GetTimeTime200ResponseBody"
parameters:
- schema:
type: string
in: query
name: timestamp
required: false
- schema:
type: string
in: query
name: format
required: true
- schema:
type: string
in: query
name: unit
required: true
- schema:
type: string
in: query
name: years
required: true
- schema:
type: string
in: query
name: target
required: true
- schema:
type: string
in: query
name: start
required: true
- schema:
type: string
in: query
name: end
required: true
/transform/collection:
post:
responses:
Expand All @@ -508,6 +587,17 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/PostTransformCollectionRequestBody"
parameters:
- schema:
type: string
in: query
name: from
required: true
- schema:
type: string
in: query
name: to
required: true
components:
schemas:
GetBooks200ResponseBody:
Expand Down Expand Up @@ -1861,16 +1951,12 @@ GET /books/{bookId}
[200 response body] 'status' is not documented (/properties)
[200 response body] 'price' is not documented (/properties)
GET /books
× 200 response
[200 response body] 'name' is not documented (/properties/books/items/properties)
[200 response body] 'author_id' is not documented (/properties/books/items/properties)
[200 response body] 'status' is not documented (/properties/books/items/properties)
[200 response body] 'price' is not documented (/properties/books/items/properties)
[200 response body] 'created_at' is not documented (/properties/books/items/properties)
[200 response body] 'updated_at' is not documented (/properties/books/items/properties)
200 response
[404 response body] body is not documented
[query parameter] list is not documented
100.0% coverage of your documented operations. 2 requests did not match a documented path (6 total requests).
8 diffs detected in documented operations
83.3% coverage of your documented operations. 2 requests did not match a documented path (6 total requests).
4 diffs detected in documented operations
New endpoints are only added in interactive mode. Run 'optic capture openapi-with-overlapping-paths.yml --update interactive' to add new endpoints
"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ capture:
ready_endpoint: /healthcheck
requests:
send:
- path: /books
- path: /books?list=all
method: GET
- path: /books/asd
method: GET
Expand Down
27 changes: 24 additions & 3 deletions projects/optic/src/commands/capture/actions/documented.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import chalk from 'chalk';
import path from 'path';
import { jsonPointerHelpers } from '@useoptic/json-pointer-helpers';
import { ParseResult } from '../../../utils/spec-loaders';
import {
Expand Down Expand Up @@ -63,6 +62,7 @@ function summarizePatch(
const { jsonLike: spec, sourcemap } = parseResult;
const pointerLogger = jsonPointerLogger(sourcemap);
const { diff, path, groupedOperations } = patch;
const color = options.mode === 'update' ? chalk.green : chalk.red;
if (!diff || groupedOperations.length === 0) return [];
if (
diff.kind === 'UnmatchdResponseBody' ||
Expand All @@ -75,8 +75,30 @@ function summarizePatch(
: `[${diff.statusCode} response body]`;
const action =
options.mode === 'update' ? 'has been added' : 'is not documented';
const color = options.mode === 'update' ? chalk.green : chalk.red;
return [color(`${location} body ${action}`)];
} else if (
diff.kind === 'UnmatchedRequestParameter' ||
diff.kind === 'UnmatchedResponseHeader'
) {
const location =
diff.kind === 'UnmatchedRequestParameter'
? `[${diff.in} parameter]`
: `[${diff.statusCode} response header]`;

const action =
options.mode === 'update' ? 'has been added' : 'is not documented';
return [color(`${location} ${diff.name} ${action}`)];
} else if (
diff.kind === 'MissingRequiredRequiredParameter' ||
diff.kind === 'MissingRequiredResponseHeader'
) {
const location =
diff.kind === 'MissingRequiredRequiredParameter'
? `[${diff.in} parameter]`
: `[${diff.statusCode} response header]`;
const action =
options.mode === 'update' ? 'is now optional' : 'is required and missing';
return [color(`${location} ${diff.name} ${action}`)];
} else {
const location = locationFromPath(path);

Expand All @@ -92,7 +114,6 @@ function summarizePatch(

const action =
options.mode === 'update' ? 'has been added' : 'is not documented';
const color = options.mode === 'update' ? chalk.green : chalk.red;
const propertyLocation =
options.mode === 'update'
? `(${diff.propertyPath})`
Expand Down
Loading

0 comments on commit f4fec04

Please sign in to comment.