Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"elasticsearch": "^11.0.1",
"jquery.rateit": "^1.0.23",
"js-yaml": "^3.6.1",
"simple-statistics": "^2.0.0-beta1"
"simple-statistics": "^2.0.0-beta1",
"swagger-parser": "^3.4.1"
},
"devDependencies": {},
"scripts": {
Expand Down
19 changes: 19 additions & 0 deletions server/methods/swagger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import SwaggerParser from 'swagger-parser';

Meteor.methods({
// Validate Swagger JSON/YAML
// Params: URL or file path to Swagger file
// Returns: true if valid else false
validateSwagger: function(url) {
SwaggerParser.validate(url)
.then(function(api){
console.log("Your API is valid!");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably do not need to show any console logs, since this code runs on the server. We will use the return value of this function to show an alert to the user.

console.log("API name: %s, Version: %s", api.info.title, api.info.version);
return true;
})
.catch(function(err){
console.log(err);
return false;
Copy link
Copy Markdown
Contributor

@brylie brylie May 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we return valid or invalid from this function? Right now it is ambiguous how to use this function, or what true or false means given the method name. E.g.

// From client code
Meteor.call("validateSwagger", function (error, response) {
  if (error) {
    // handle the error
    // e.g. we can pass the validation message here as an error
    // See: http://docs.meteor.com/api/methods.html#Meteor-Error
  } else {
    if (response === 'valid') {
      // Swagger file is valid
    }
  }
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not use here strings cause we have boolean value: "valid" or "invalid". I could though change method name to "isValidSwagger" if that implies the functionality better.

});
}
});