Comments (4)
Could you be more specific by providing some example?
from php-swagger-test.
Now thinking about it, title is a little bit misleading, but anyway
Let's assume we have this as a swagger-json file (actual host is unavailable to the global internet, so I replaced it).
"swagger": "2.0",
"schemes": [
"http"
],
"info": {
"version": "1.0.0",
"title": "Library"
},
"host": "books.example.com",
"tags": [
{
"name": "Books",
"description": "Receiving information about books"
}
],
"paths": {
"bookinfo": {
"get": {
"tags": [
"Library"
],
"summary": "Returns information of one book",
"produces": [
"application/json"
],
"parameters": [
{
"name": "book",
"in": "query",
"description": "Book ID",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean"
},
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/Book"
}
}
}
}
}
}
}
}
},
"definitions": {
"Book": {
"type": "object",
"properties": {
"tag_id": {
"type": "string"
},
"title": {
"type": "string"
},
"where_is": {
"type": "string"
},
"taking_date": {
"type": "string"
},
"image_url": {
"type": "string"
}
}
}
}
}
However, properties of Book model are actually nullable (as far as actual API and DB connected to it are concerned, it's valid that it can be either a string or null), but if you execute such test
public function testGetBook()
{
$this->request
->withMethod('GET')
->withPath('/bookinfo');
try {
$this->assertRequest($this->request);
$response = $this->request->send();
} catch (\Exception $e) {
$this->fail('Failed - ' . $e->getMessage());
}
}
And if it returns null as one of the properties of an object in response array, it causes test to throw out an exception.
From looking through source code of your module, method assertRequest uses instance of SwaggerSchema it creates itself (which has such flag disabled by default), even if request was specified to use another schema and/or with AllowNullValues flag enabled, and there is no way to enable it within SwaggerTestInstance.
Overriding $this->swaggerSchema causes other issues (can replicate them if needed), so that is not an option for me
from php-swagger-test.
Hello, for some unexplained reason I missed your answer. I am sorry for that. So, for this issue I am adding the possibility of you override the SwaggerSchema.
Your code now could be:
<?php
public function testGetBook()
{
$schema = new SwaggerSchema(.......)
$this->request
->withSwaggerSchema($schema)
->withMethod('GET')
->withPath('/bookinfo');
try {
$response = $this->assertRequest($this->request);
} catch (\Exception $e) {
$this->fail('Failed - ' . $e->getMessage());
}
}
You do not need to call send()
because the assertRequest()
already do this.
from php-swagger-test.
Merged to branch oas30
from php-swagger-test.
Related Issues (20)
- issue while consuming json HOT 3
- Referenced parameters compatibility HOT 4
- Variables in servers object HOT 3
- ByJG\ApiTools\Exception\GenericSwaggerException: Not all cases are defined. HOT 10
- Not supported PHPUnit 8.5 HOT 7
- nullable value matching HOT 2
- Typo: getDefintion should be getDefinition HOT 5
- Unable to run successful tests for the repo (PHPStorm 2020.1) HOT 3
- Error matching ResponseBody without 'content' HOT 9
- Library does not support 'oneOf', 'anyOf', 'allOf' and 'not' HOT 24
- Referencing to components in external JSON files is missing HOT 1
- Library as trait(s) instead of inheritance class HOT 3
- Splitting out the request/response validation from the actual request
- Responses using ref aren't supported
- PHP 8 Compatibility HOT 5
- Guidance on setting up basic functional tests
- Add label #hacktoberfest to project HOT 3
- PHP 8.1 deprecation warning HOT 5
- Nullable does not work with 'oneOf'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-swagger-test.