-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow comma separated values in the query parameters (#135)
* Added support for comma separated query params * Only explode if the schema type is an array
- Loading branch information
Showing
3 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
{ | ||
"openapi": "3.0.0", | ||
"info": { | ||
"title": "Numbers.v1", | ||
"version": "1.0" | ||
}, | ||
"servers": [ | ||
{ | ||
"url": "http://localhost:3000" | ||
} | ||
], | ||
"paths": { | ||
"/users": { | ||
"get": { | ||
"summary": "Get users", | ||
"tags": [], | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "number", | ||
"description": "User ID", | ||
"example": 1 | ||
}, | ||
"name": { | ||
"type": "string", | ||
"description": "User name", | ||
"example": "Adam Campbell" | ||
}, | ||
"email": { | ||
"type": "string", | ||
"description": "User email address", | ||
"format": "email", | ||
"example": "[email protected]" | ||
} | ||
} | ||
} | ||
}, | ||
"examples": { | ||
"example-1": { | ||
"value": [ | ||
{ | ||
"id": 1, | ||
"name": "Adam Campbell", | ||
"email": "[email protected]" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"422": { | ||
"description": "Unprocessable entity", | ||
"content": { | ||
"application/problem+json": { | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "number", | ||
"description": "User ID", | ||
"example": 1 | ||
}, | ||
"name": { | ||
"type": "string", | ||
"description": "User name", | ||
"example": "Adam Campbell" | ||
}, | ||
"email": { | ||
"type": "string", | ||
"description": "User email address", | ||
"format": "email", | ||
"example": "[email protected]" | ||
} | ||
} | ||
} | ||
}, | ||
"examples": { | ||
"example-1": { | ||
"value": [ | ||
{ | ||
"id": 1, | ||
"name": "Adam Campbell", | ||
"email": "[email protected]" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"operationId": "get-users", | ||
"parameters": [ | ||
{ | ||
"name": "include", | ||
"in": "query", | ||
"description": "", | ||
"example": "foo,bar", | ||
"explode": false, | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
"enum": ["foo", "bar"] | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -656,6 +656,27 @@ public function test_numeric_values() | |
->assertValidResponse(); | ||
} | ||
|
||
public function test_comma_separated_values() | ||
{ | ||
Spectator::using('CommaSeparatedString.v1.json'); | ||
|
||
Route::get('/users', function () { | ||
return [ | ||
[ | ||
'id' => 1, | ||
'name' => 'Jim', | ||
'email' => '[email protected]', | ||
], | ||
]; | ||
}) | ||
->middleware(Middleware::class); | ||
|
||
$this->getJson('/users?include=foo,bar') | ||
->assertStatus(200) | ||
->assertValidRequest() | ||
->assertValidResponse(); | ||
} | ||
|
||
public function nullableObjectProvider(): array | ||
{ | ||
return [ | ||
|