Skip to content

Commit

Permalink
Merge pull request #2518 from qorelanguage/bugfix/2497_2517_swagger_f…
Browse files Browse the repository at this point in the history
…ixes

Fixed #2497 for requests + fixed #2517
  • Loading branch information
davidnich committed Nov 30, 2017
2 parents d3ad9ca + 950ec84 commit aa6cef1
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 67 deletions.
3 changes: 2 additions & 1 deletion doxygen/lang/900_release_notes.dox.tmpl
Expand Up @@ -65,9 +65,10 @@
- fixed a bug where string value constraints were only enforced in requests but not responses (<a href="https://github.com/qorelanguage/qore/issues/2396">issue 2396</a>)
- fixed a bug where invalid date, binary, and byte values would cause a <tt>500 Internal Server Error</tt> response to be returned instead of a <tt>400 Bad Request</tt> error (<a href="https://github.com/qorelanguage/qore/issues/2397">issue 2397</a>)
- fixed a bug where date values were formatted incorrectly in Swagger responses (<a href="https://github.com/qorelanguage/qore/issues/2409">issue 2409</a>)
- fixed a bug which made it impossible to return data with other content/mime types than json, yamlrpc, FormUrlEncoded or MultipartFormData (<a href="https://github.com/qorelanguage/qore/issues/2497">issue 2497</a>)
- fixed a bug which made it impossible to send data with other content/mime types than json, yamlrpc, FormUrlEncoded or MultipartFormData (<a href="https://github.com/qorelanguage/qore/issues/2497">issue 2497</a>)
- fixed handling of string/binary values (<a href="https://github.com/qorelanguage/qore/issues/2505">issue 2505</a>)
- fixed a bug where consumes property of operations was sometimes ignored (<a href="https://github.com/qorelanguage/qore/issues/2507">issue 2507</a>)
- fixed parsing of responses without Content-Type header (<a href="https://github.com/qorelanguage/qore/issues/2517">issue 2517</a>)
- fixed bugs affecting debugging matching function/method variants and finding statements with special methods and with complex types (<a href="https://github.com/qorelanguage/qore/issues/1865">issue 1865</a>)
- fixed a bug in \c qpp generating hashdecl code in a specific namespace (<a href="https://github.com/qorelanguage/qore/issues/2255">issue 2255</a>)
- fixed an error in a @ref hashdecl "hashdecl" documentation example (<a href="https://github.com/qorelanguage/qore/issues/2299">issue 2299</a>)
Expand Down
138 changes: 102 additions & 36 deletions examples/test/qlib/Swagger/Swagger.qtest
Expand Up @@ -1752,7 +1752,7 @@ public class SwaggerTest inherits QUnit::Test {
),),
"responses": (
"200": (
"description": "successful response",
"description": "success",
),
"409": (
"description": "error",
Expand Down Expand Up @@ -1784,7 +1784,7 @@ public class SwaggerTest inherits QUnit::Test {
),
"responses": (
"200": (
"description": "successful response",
"description": "success",
),
),
"consumes": (
Expand All @@ -1803,54 +1803,79 @@ public class SwaggerTest inherits QUnit::Test {
"get": (
"responses": (
"200": (
"description": "successful response",
"description": "success",
"schema": {
"type": "string",
"format": "binary",
}
),
),
"consumes": (
MimeTypeJson,
),
"produces": (
"image/jpeg",
"image/png",
"consumes": (MimeTypeJson,),
"produces": ("image/jpeg", "image/png"),
),
"post": (
"responses": (
"200": ("description": "success",),
),
"consumes": ("image/png",),
"produces": ("text/plain",),
"parameters": (
{
"in": "body",
"name": "body",
"schema": (
"type": "string",
"format": "binary",
),
},
)
),
);
b.paths."/api/b2507" += (
"post": (
"responses": (
"200": (
"description": "successful response",
"description": "success",
"schema": {
"type": "string",
}
),
),
"consumes": (
MimeTypeJson,
),
"produces": (
MimeTypeJson,
),
"consumes": (MimeTypeJson,),
"produces": (MimeTypeJson,),
"parameters": (
{
"in": "body",
"name": "body",
"schema": (
"type": "object",
"properties": {
"a": {
"type": "string"
}
"a": {"type": "string"}
}
),
},
)
),
);
b.paths."/api/b2517" += (
"post": (
"responses": (
"200": ("description": "success",),
),
"consumes": ("image/jpeg","image/png"),
"produces": ("text/plain",),
"parameters": (
{
"in": "body",
"name": "body",
"schema": (
"type": "string",
"format": "binary",
),
},
)
),
);

remove b.parameters.a.type;

Expand Down Expand Up @@ -2065,7 +2090,7 @@ public class SwaggerTest inherits QUnit::Test {
assertEq(now.format("\"YYYY-MM-DD\""), res.body);
}

# issue #2497
# issue #2497 test response
so = new SwaggerSchema(b);
{
hash<HttpResponseInfo> res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"content-type": "image/jpeg"}, NOTHING);
Expand All @@ -2078,14 +2103,14 @@ public class SwaggerTest inherits QUnit::Test {
assertEq("image/png", res.hdr."content-type");
assertEq(<feedface>, res.body);

res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"ContEnt-type": "image/jpeg"}, NOTHING);
res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"Content-Type": "image/jpeg"}, NOTHING);
assertEq(200, res.code);
assertEq("image/jpeg", res.hdr."ContEnt-type");
assertEq("image/jpeg", res.hdr."Content-Type");
assertEq(<feedface>, res.body);

res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"ConteNt-TYpe": "image/png"}, NOTHING);
res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"Content-Type": "image/png"}, NOTHING);
assertEq(200, res.code);
assertEq("image/png", res.hdr."ConteNt-TYpe");
assertEq("image/png", res.hdr."Content-Type");
assertEq(<feedface>, res.body);
}
# issue #2497 test response parsing with Content-Types that cannot be deserialized
Expand All @@ -2106,14 +2131,14 @@ public class SwaggerTest inherits QUnit::Test {
assertEq("image/png", res.hdr."content-type");
assertEq(<feedface>, res.body);

res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"ContEnt-type": "image/jpeg"}, ("*/*",));
res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"Content-Type": "image/jpeg"}, ("*/*",));
assertEq(200, res.code);
assertEq("image/jpeg", res.hdr."ContEnt-type");
assertEq("image/jpeg", res.hdr."Content-Type");
assertEq(<feedface>, res.body);

res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"ConteNt-TYpe": "image/png"}, ("*/*",));
res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"Content-Type": "image/png"}, ("*/*",));
assertEq(200, res.code);
assertEq("image/png", res.hdr."ConteNt-TYpe");
assertEq("image/png", res.hdr."Content-Type");
assertEq(<feedface>, res.body);
}
{
Expand All @@ -2127,14 +2152,14 @@ public class SwaggerTest inherits QUnit::Test {
assertEq("image/png", res.hdr."content-type");
assertEq(<feedface>, res.body);

res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"ContEnt-type": "image/jpeg"}, ("image/*",));
res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"Content-Type": "image/jpeg"}, ("image/*",));
assertEq(200, res.code);
assertEq("image/jpeg", res.hdr."ContEnt-type");
assertEq("image/jpeg", res.hdr."Content-Type");
assertEq(<feedface>, res.body);

res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"ConteNt-TYpe": "image/png"}, ("image/*",));
res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"Content-Type": "image/png"}, ("image/*",));
assertEq(200, res.code);
assertEq("image/png", res.hdr."ConteNt-TYpe");
assertEq("image/png", res.hdr."Content-Type");
assertEq(<feedface>, res.body);
}
{
Expand All @@ -2149,14 +2174,14 @@ public class SwaggerTest inherits QUnit::Test {
assertEq("image/png", res.hdr."content-type");
assertEq(<feedface>, res.body);

res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"ContEnt-type": "image/jpeg"}, contentTypes);
res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"Content-Type": "image/jpeg"}, contentTypes);
assertEq(200, res.code);
assertEq("image/jpeg", res.hdr."ContEnt-type");
assertEq("image/jpeg", res.hdr."Content-Type");
assertEq(<feedface>, res.body);

res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"ConteNt-TYpe": "image/png"}, contentTypes);
res = so.processResponse("get", "/api/b2497", 200, <feedface>, {"Content-Type": "image/png"}, contentTypes);
assertEq(200, res.code);
assertEq("image/png", res.hdr."ConteNt-TYpe");
assertEq("image/png", res.hdr."Content-Type");
assertEq(<feedface>, res.body);
}
{
Expand All @@ -2166,6 +2191,30 @@ public class SwaggerTest inherits QUnit::Test {
assertThrows("ACCEPT-ERROR", \so.processResponse(), ("get", "/api/b2497", 200, <feedface>, NOTHING, contentTypes));
}

# issue #2497 test request
{
hash<RestRequestClientInfo> res = so.processRequest("post", "/api/b2497", <feedface>, {"content-type": "image/png"}, NOTHING);
assertEq("/api/b2497", res.uri_path);
assertEq("image/png", res.content);
assertEq(<feedface>, res.body);

res = so.processRequest("post", "/api/b2497", <feedface>, {"Content-Type": "image/png"}, NOTHING);
assertEq("/api/b2497", res.uri_path);
assertEq("image/png", res.content);
assertEq(<feedface>, res.body);
}
{
hash<RestRequestClientInfo> res = so.processRequest("post", "/api/b2497", <feedface>, {"content-type": "image/png"}, ("image/png",));
assertEq("/api/b2497", res.uri_path);
assertEq("image/png", res.content);
assertEq(<feedface>, res.body);

res = so.processRequest("post", "/api/b2497", <feedface>, {"Content-Type": "image/png"}, ("image/png",));
assertEq("/api/b2497", res.uri_path);
assertEq("image/png", res.content);
assertEq(<feedface>, res.body);
}

# issue #2507
so = new SwaggerSchema(b);
{
Expand All @@ -2191,6 +2240,23 @@ public class SwaggerTest inherits QUnit::Test {
assertEq("string", rsh.body);
assertThrows("DESERIALIZATION-ERROR", \so.parseResponse(), ("post", res.uri_path, 200, "\"string\"", ("content-type": MimeTypeYamlRpc)));
}

# issue #2517
so = new SwaggerSchema(b);
{
hash hdr = {
"http_version": "1.1",
"status_code": 200,
"status_message": "OK",
"server": "Qorus-HTTP-Server/0.3.11.1",
"connection": "Keep-Alive",
"date": "Thu, 30 Nov 2017 12:59:55 GMT",
"content-length": "0",
};
hash<RestResponseClientInfo> res = so.parseResponse("post", "/api/b2517", 200, NOTHING, hdr);
assertEq(200, res.code);
assertEq(NOTHING, res.body);
}
}

{
Expand Down

0 comments on commit aa6cef1

Please sign in to comment.