File tree Expand file tree Collapse file tree 6 files changed +76
-6
lines changed
__tests__/fixtures/oas-references Expand file tree Collapse file tree 6 files changed +76
-6
lines changed Original file line number Diff line number Diff line change 4242 },
4343 "type" : " error"
4444 },
45+ {
46+ "code" : " request.query.incompatible" ,
47+ "message" : " Value is incompatible with the parameter defined in the spec file: must have required property 'value'" ,
48+ "mockDetails" : {
49+ "interactionDescription" : " should fail with missing parameters" ,
50+ "interactionState" : " [none]" ,
51+ "location" : " [root].interactions[1]" ,
52+ "value" : {
53+ "description" : " should fail with missing parameters" ,
54+ "providerState" : " " ,
55+ "request" : {
56+ "method" : " POST" ,
57+ "path" : " /login" ,
58+ "headers" : {
59+ "Content-Type" : " application/json"
60+ },
61+ "body" : {
62+ "username" : " bob"
63+ }
64+ },
65+ "response" : {
66+ "status" : 201 ,
67+ "body" : {
68+ "id" : " 123"
69+ }
70+ }
71+ }
72+ },
73+ "specDetails" : {
74+ "location" : " [root].paths./login.post.parameters[1]" ,
75+ "pathMethod" : " post" ,
76+ "pathName" : " /login" ,
77+ "value" : {
78+ "in" : " query" ,
79+ "name" : " nested" ,
80+ "required" : true ,
81+ "schema" : {
82+ "type" : " string"
83+ }
84+ }
85+ },
86+ "type" : " error"
87+ },
4588 {
4689 "code" : " request.body.incompatible" ,
4790 "message" : " Request body is incompatible with the request body schema in the spec file: must have required property 'username'" ,
Original file line number Diff line number Diff line change 88 post :
99 parameters :
1010 - $ref : " #/components/parameters/Request.Param"
11+ - $ref : " #/components/parameters/nested.param~1with~0tilde"
1112 requestBody :
1213 $ref : " #/components/requestBodies/Request.Body"
1314 responses :
@@ -22,6 +23,12 @@ components:
2223 required : true
2324 schema :
2425 type : string
26+ " nested.param/with~tilde " :
27+ in : query
28+ name : nested
29+ required : true
30+ schema :
31+ type : string
2532 requestBodies :
2633 Request.Body :
2734 content :
Original file line number Diff line number Diff line change 88 "request" : {
99 "method" : " POST" ,
1010 "path" : " /login" ,
11- "query" : " account=foo" ,
11+ "query" : " account=foo&nested=bar " ,
1212 "headers" : {
1313 "Content-Type" : " application/json"
1414 },
4949 "request" : {
5050 "method" : " POST" ,
5151 "path" : " /login" ,
52- "query" : " account=foo" ,
52+ "query" : " account=foo&nested=bar " ,
5353 "headers" : {
5454 "Content-Type" : " application/json"
5555 },
6868 "request" : {
6969 "method" : " POST" ,
7070 "path" : " /login" ,
71- "query" : " account=foo" ,
71+ "query" : " account=foo&nested=bar " ,
7272 "headers" : {
7373 "Content-Type" : " application/json"
7474 },
Original file line number Diff line number Diff line change 1515 },
1616 "type" : " error"
1717 },
18+ {
19+ "code" : " request.query.incompatible" ,
20+ "message" : " Value is incompatible with the parameter defined in the spec file: must be string" ,
21+ "mockDetails" : {
22+ "interactionDescription" : " should fail with missing parameters" ,
23+ "interactionState" : " [none]" ,
24+ "location" : " [root].interactions[1].request.query.nested."
25+ },
26+ "specDetails" : {
27+ "location" : " [root].paths./login.post.parameters[1].schema.type" ,
28+ "pathMethod" : " post" ,
29+ "pathName" : " /login" ,
30+ "value" : " string"
31+ },
32+ "type" : " error"
33+ },
1834 {
1935 "code" : " request.body.incompatible" ,
2036 "message" : " Request body is incompatible with the request body schema in the spec file: must have required property 'username'" ,
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import addFormats from "ajv-formats";
44import Router , { HTTPMethod } from "find-my-way" ;
55import { uniqWith } from "lodash-es" ;
66import { cleanPathParameter } from "./utils/parameters" ;
7+ import { dereferenceOas } from "../utils/schema" ;
78
89export function setupAjv ( options : Options ) : Ajv {
910 const ajv = new Ajv ( options ) ;
@@ -51,7 +52,7 @@ export function setupRouter(
5152 [
5253 ...( operation . parameters || [ ] ) ,
5354 ...( oas . paths [ oasPath ] . parameters || [ ] ) ,
54- ] as OpenAPIV3 . ParameterObject [ ] ,
55+ ] . map ( ( p ) => dereferenceOas ( p , oas as OpenAPIV3 . Document ) ) ,
5556 ( a , b ) => `${ a . name } ${ a . in } ` === `${ b . name } ${ b . in } ` ,
5657 ) ;
5758 if ( parameters . length ) {
Original file line number Diff line number Diff line change @@ -2,13 +2,16 @@ import type { OpenAPIV3 } from "openapi-types";
22import type { SchemaObject } from "ajv" ;
33import { each , get } from "lodash-es" ;
44
5+ const unescape = ( subpath : string ) =>
6+ subpath . replaceAll ( "~1" , "/" ) . replaceAll ( "~0" , "~" ) ;
7+
58export const splitPath = ( path : string ) => {
69 if ( path . startsWith ( "#/" ) ) {
7- return path . substring ( 2 ) . split ( "/" ) ;
10+ return path . substring ( 2 ) . split ( "/" ) . map ( unescape ) ;
811 }
912
1013 if ( path . startsWith ( "/" ) ) {
11- return path . substring ( 1 ) . split ( "/" ) ;
14+ return path . substring ( 1 ) . split ( "/" ) . map ( unescape ) ;
1215 }
1316
1417 return path ;
You can’t perform that action at this time.
0 commit comments