Swagger UI Express with API Versioning - node.js

I am using swagger-ui-express and swagger-jsdoc for API Documentation of my node app. The point here is that I have two versions of API in my App and I want to document both of them. I have seen that in .NET Core there is an option available to define the specs and choose one from a dropdown in top bar. I am looking for a similar solution
As a dropdown can be seen in top bar I want similar via swagger-ui-express. Is it possible or if anybody has implemented the same for API Versioning?
Looking forward to your responses.

The solution I propose is not specific to API versioning, but you can have a dropdown of URLs the end-user can choose from. According to the docs, you would need to pass a swaggerOptions object:
const swaggerOptions = {
explorer: true,
swaggerOptions: {
urls: [
{
url: 'https://v1/swagger.json',
name: 'v1'
},
{
url: 'https://v2/swagger.json',
name: 'v2'
}
]
}
}

Related

Shopify API: Retrieve Orders with a specific DiscountCode

I am currently working on a project that creates Discount Codes via API and I need to retrieve which orders have used a specified Discount Code (ex: TESTCODE123). I couldn't find the documentation or API endpoint mentioned in the Shopify API pages. Is it possible to guide me on this?
You will need to use Admin GraphQL for this and rely on the query parameter to filter them out.
Example:
{
orders(first: 10, query:"discount_code:TESTCODE123"){
edges {
node {
id
}
}
}
}
You can refer the docs here: https://shopify.dev/docs/admin-api/graphql/reference/queryroot?api[version]=2020-01

How can I enable GitHub preview features, like topics?

I'm using Apps - listRepos to get a list of all the repositories installed on my Probot GitHub application.
I want the response data to include the GitHub topics for each repository. This is currently only available as a preview feature:
The topics property for repositories on GitHub is currently available for developers to preview. To view the topics property in calls that return repository results, you must provide a custom media type in the Accept header:
application/vnd.github.mercy-preview+json
So I think I want to "provide a custom media type in the Accept header".
Is there a way to enable GitHub preview features in Probot? Perhaps by somehow setting RequestOptions?
Success: I added a headers object to my listRepos() call.
const repositories = await octokit.paginate(
octokit.apps.listRepos({
per_page: 100,
headers: {
accept: 'application/vnd.github.machine-man-preview+json,application/vnd.github.mercy-preview+json'
}
}),
res => res.data.repositories // Pull out only the list of repositories from each response.
);

Postmark: Send email with template

I am trying to send a template email with Postmark in Node.js
I created a template on the Postmark App website. I've looked through their documentation, but cannot find any way to go about sending a templated email.
Documentation Sources:
http://blog.postmarkapp.com/post/125849089273/special-delivery-postmark-templates
http://developer.postmarkapp.com/developer-api-templates.html
I've tried a variety of methods, including:
client.emailWithTemplate("jenny#example.com",
"bob#example.com",<template-id>, {
"link" : "https://example.com/reset?key=secret",
"recipient_name" : "Jenny"
});
TypeError: Object # has no method 'emailWithTemplate'
client.sendEmail({
"TemplateModel" : {
"customer_name" : "Jenny",
},
"TemplateId" : 6882,
"From": "info#formulastocks.com",
"To": "lrroberts0122#gmail.com",
}, function(error, success) {
if(error) {
console.log(error);
} else {
console.log(success);
}
});
Console Log Error: { status: 422,
message: 'A \'TemplateId\' must not be used when sending a non-templated email.',
code: 1123 }
Thanks!
I'm the current maintainer of the node.js library (as well as one of the engineers that worked on Postmark Templates).
One of the possible reasons the original snippet doesn't work is that you could be using an older version of Postmark.js. We added the template endpoint capabilities in version 1.2.1 of the node.js package.
In the package.json file for your project you should make sure to update it to use version 1.2.1 or greater of the postmark.js library. If you've been using an older version of the library, you'll also need to run npm update
Also note that if you click "Edit Template" in the Postmark UI, and then "API Snippets," the UI provides a completed snippet for a number of languages (including node.js).
If all else fails, please contact support and we'll be happy to help you solve this issue.

Is there a library compatible with Hapi for fine-grained ACL / User permissions?

Looking to use HapiJS as our API server. We need fine-grained user permissions, e.g. "User A can edit field B" "User C can view field D" for a given model / resource.
Before we start building something I've been looking to see if something like this has already been done that is compatible with Hapi.
I have just read an article where the ACL permissions are validated using the build-in scopes.
Here is the link to the mentioned article :
https://blog.andyet.com/2015/06/16/harnessing-hapi-scopes/
And to resume quickly (using the example from the above link), you get a user object that looks like so :
{
"username": "han",
"scope": ["door-trash-compactor"]
}
The scope can be generated by whatever is backing your ACL for this user. In this case you have the resource door with id trash-compactor that can be checked like so :
server.route({
method: 'GET',
route: '/doors/{door_id}',
config: {
handler: function (request, reply) {
reply(request.params.door_id ' door is closed');
},
auth: {
scope: ['door-{params.door_id}']
}
}
});
The scope door-{params.door_id} will be translated to door-trash-compactor which will then be validated. Han's request to the trash compactor door will be valid and he will get the door is closed message.
The blog post is well written (much better then this summary) and describes this in better detail - would recommend the read.
I've recently been working on an ACL project for hapijs. It should get you a good start. https://www.npmjs.org/package/hapi-authorization

Setting module page as home page in Orchard

I have a module in which I created a custom page with controller and some logic. Works fine. I need that page to function as home page for my site. I found some topics about implementing IHomePageProvider, but that seems to be impossible because I can't find the definition of IHomePageProvider in the Orchard core. So I know there are some topics on this subject, but I didn't manage to find a solution that way, so therefore this question.
That is because it was removed at the same time as the routable part. This is now done using Alias.
When working with Orchard Core (Orchard 2) there is setting with Home Route, which you can specify.
You can set it in your recipe.json file:
{
"name": "settings",
"HomeRoute": {
"Action": "Index",
"Controller": "ControllerName",
"Area": "AreaName"
}
}
or probablly later:
RouteValueDictionary newHomeRouteValue = ...;
var site = await _siteService.GetSiteSettingsAsync();
site.HomeRoute = newHomeRouteValue;
await _siteService.UpdateSiteSettingsAsync(site);
You can define a home Route and Controller associated with this route. Take a look how it's accomplished in the CulturePicker module: HomeRoutes and LocalizableHomeController

Resources