Skip to content

Commit

Permalink
Merge pull request #2339 from qorelanguage/bugfix/2338_swagger_info_v…
Browse files Browse the repository at this point in the history
…ersion

Swagger module fixes for #2338, #2341 and #2342
  • Loading branch information
davidnich committed Oct 26, 2017
2 parents 207072a + 259501b commit 2c1fb1b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
3 changes: 3 additions & 0 deletions doxygen/lang/900_release_notes.dox.tmpl
Expand Up @@ -18,6 +18,9 @@
- fixed a bug in documentation post-processing for @ref hashdecl "hashdecl" declarations (<a href="https://github.com/qorelanguage/qore/issues/2298">issue 2298</a>)
- <q href="../../modules/SqlUtil/html.indexhtml">SqlUtil</a> module changes
- implemented support for custom column operators (<a href="https://github.com/qorelanguage/qore/issues/2314">issue 2314</a>)
- <a href="../../modules/Swagger/html/index.html">Swagger</a> module fixes:
- fixed handling of string type date and date-time formats (<a href="https://github.com/qorelanguage/qore/issues/2341">issue 2341</a>)
- fixed example value for binary type (<a href="https://github.com/qorelanguage/qore/issues/2342">issue 2342</a>)
- added missing comparison methods in the <a href="../../modules/QUnit/html/index.html">QUnit</a> module (<a href="https://github.com/qorelanguage/qore/issues/1588">issue 1588</a>):
- \c Test::assertRegex()
- \c Test::assertNRegex()
Expand Down
4 changes: 3 additions & 1 deletion examples/test/qlib/Swagger/Swagger.qtest
Expand Up @@ -651,7 +651,9 @@ public class SwaggerTest inherits QUnit::Test {
assertThrows("REQUIRED-FIELD-MISSING", "\"version\".*missing", loadyaml, my_make_yaml(base + {"info": {"title": "a"}}));
assertThrows("REQUIRED-FIELD-MISSING", "\"title\".*missing", loadyaml, my_make_yaml(base + {"info": {"version": "a"}}));
assertThrows("INVALID-FIELD-TYPE", "title", loadyaml, my_make_yaml(base + {"info": {"title": 5, "version": "a"}}));
assertThrows("INVALID-FIELD-TYPE", "version", loadyaml, my_make_yaml(base + {"info": {"title": "a", "version": 5}}));
assertThrows("INVALID-FIELD-TYPE", "version", loadyaml, my_make_yaml(base + {"info": {"title": "a", "version": 1.0}}));
loadyaml(my_make_yaml(base + {"info": {"title": "a", "version": "1.0.0"}}));
loadyaml(my_make_yaml(base + {"info": {"title": "a", "version": "1.0"}}));

info = ValidInfoObject + {"description": 5};
assertThrows("INVALID-FIELD-TYPE", loadyaml, my_make_yaml(base + {"info": info}));
Expand Down
39 changes: 34 additions & 5 deletions qlib/Swagger.qm
Expand Up @@ -53,7 +53,7 @@
%requires(reexport) RestSchemaValidator >= 1.0

module Swagger {
version = "0.1";
version = "1.0.1";
desc = "Swagger module providing functionality for Swagger 2.0 schema definitions";
author = "Ondrej Musil <ondrej.musil@qoretechnologies.com>, David Nichols <david.nichols@qoretechnologies.com>";
url = "http://qore.org";
Expand Down Expand Up @@ -152,6 +152,10 @@ RestHandler handler(NOTHING, swagger);

@section swagger_relnotes Swagger Module Release Notes

@subsection swagger_1_0_1 Swagger v1.0.1
- fixed handling of string type date and date-time formats (<a href="https://github.com/qorelanguage/qore/issues/2341">issue 2341</a>)
- fixed example value for binary type (<a href="https://github.com/qorelanguage/qore/issues/2342">issue 2342</a>)

@subsection swagger_1_0 Swagger v1.0

- initial release of the %Swagger module
Expand Down Expand Up @@ -355,9 +359,9 @@ class SchemaBase {
case "string": {
switch (format) {
case "byte":
case "binary": return "<deadbeef>";
case "date": return now_us();
case "date-time": return now_us();
case "binary": return <feedface>;
case "date": return 1987-05-23;
case "date-time": return 1987-05-23T07:45:30Z;
default:
return "value";
}
Expand Down Expand Up @@ -3230,7 +3234,11 @@ public class SchemaObject inherits ObjectBase, SchemaBase {

str += "{\n";
foreach hash h in (properties.pairIterator()) {
string pstr = sprintf("%y: %s", h.key, h.value.getQoreExample(\rv, h.key, False));
string pstr;
if (h.value.type == "string" && (h.value.format =~ /date(-time)?/))
pstr = sprintf("%y: date(%s)", h.key, h.value.getQoreExample(\rv, h.key, False));
else
pstr = sprintf("%y: %s", h.key, h.value.getQoreExample(\rv, h.key, False));
# add 4 spaces to the beginning of each line
str += foldl $1 + "\n" + $2, (map " " + $1, pstr.split("\n"));
str += ",\n";
Expand Down Expand Up @@ -3648,6 +3656,27 @@ namespace Priv {
get_value(objType, name, typeCode, val, \target);
}

#! Check and assign a required field.
/**
@param objType type of object (e.g. "External Documentation")
@param oh Object hash
@param name field name
@param typeCodes possible field typeCodes
@param target where to assign the field's value

@throws INVALID-FIELD-TYPE field has invalid type
@throws REQUIRED-FIELD-MISSING required field is missing
*/
sub required_field(string objType, hash oh, string name, hash<string, bool> typeCodes, reference<any> target) {
if (!oh.hasKey(name))
throw "REQUIRED-FIELD-MISSING", sprintf("%s Object: %y field is missing; fields present: %y", objType, name, keys oh);
any val = oh{name};

if (!typeCodes{val.typeCode()})
throw "INVALID-FIELD-TYPE", sprintf("%s Object: %y field has invalid type %y", objType, name, val.type());
get_value(objType, name, val.typeCode(), val, \target);
}

#! Check and assign a field.
/**
@param objType type of object (e.g. "External Documentation" or "Parameter")
Expand Down

0 comments on commit 2c1fb1b

Please sign in to comment.