OpenAPI (aka Swagger) in Azure Functions V2 - azure-devops

I'm creating a V2 Function App and want to use Swagger/Open API for docs, however it is not yet supported in the Azure Portal for V2 Functions.
Any suggestions on how I can use Swagger with V2 Functions in VSTS to create the docs on each build?

TL;DR - Use the NuGet package to render Open API document and Swagger UI through Azure Functions.
UPDATE (2021-06-04)
Microsoft recently announced the OpenAPI support on Azure Functions during the //Build event.
The Aliencube extension has now been archived and no longer supported. Please use this official extension.
As of today, it's in preview. Although it's in preview, it has more features than the Aliencube one.
Acknowledgement 2: I am still maintaining the official one.
Microsoft hasn’t officially started supporting Open API (or Swagger) yet. But there is a community-driven NuGet package currently available:
Nuget > Aliencube.AzureFunctions.Extensions.OpenApi
And here’s the blog post for it:
Introducing Swagger UI on Azure Functions
Basically its usage is similar to Swashbuckle — using decorators. And it supports both Azure Functions V1 and V2.
Acknowledgement 1: I am the owner of the NuGet package.

For anyone looking into this, Microsoft still hasn't added Open API support for Azure Functions +v2 and there hasn't been any major movement toward it.
I faced this same issue recently and I found a pretty good solution.
If you aren't aware yet, check this out: https://github.com/RicoSuter/NSwag
NSwag is a toolchain that integrates with .NET to produce the Open API documentation and UI, but also generates the respective API clients for you.
I've used this tool for the past 2 years when working with Angular and .NET apps, it saves a lot of time and seamlessly integrates with my whole development workflow.
For Azure Functions +v2, a contributor created a generator that in less than 10 lines of code, allow us to expose the Swagger endpoint for an Azure Function class:
https://github.com/Jusas/NSwag.AzureFunctionsV2
Now, if you design HTTP-Triggered Functions using DI, grouping related operations under the same class and leveraging model binding, you might not even need to apply any custom decorator, it just works!
Here's an example of how one real API would look like:
(ignore the base class. It is part of a personal pattern I follow, unrelated to Swagger)
And this is how it looks like using a swagger UI:

There is official library Azure Functions OpenAPI Extension. It is still in preview, but looks great.

Can you drop your V2 Function to run on v1 of the runtime by starting over with a blank function app first?
The MSDN documents for Create an OpenAPI definition for a function (with a date of 11/2018 interestingly enough) example states:
By default, the function app you create uses version 2.x of the
runtime. You must set the runtime version back to 1.x before you
create your function.
But one can't just move the setting to 1:
To pin your function app to the version 1.x runtime, choose ~1 under
Runtime version. This switch is disabled when you have functions in
your app.
Which implies one must create the Function app, publish/create it, set it to V1 and then put in a function before adding a function app.

Related

Google Actions CLI 3.1.0 version and actions.intent.TEXT

I want to be able to talk with Google Assistant, but connect the Actions project directly to an NLP service I already have running on my server. In other words, NOT use dialogflow.
All the following examples show how to do this.
With Rasa
https://blog.rasa.com/going-beyond-hey-google-building-a-rasa-powered-google-assistant/
With LUIS
https://www.grokkingandroid.com/using-the-actions-sdk/
https://dzone.com/articles/using-the-actions-sdk-for-google-assistant-develop
With Watson
https://www.youtube.com/watch?v=no0R0bSkHXc
They use the actions.intent.MAIN as the invocation and actions.intent.TEXT for all other utterances from the talker.
This is what I need. I don’t want to create a load of intents, with utterance phrases, inside the Action because I just want all the phrases spoken by the talker to be passed to my server, and for my NLP service to deal with them.
So I set up a new Action project, install the Actions CLI and then spend 3 days trying all possible combinations without success, because all these examples are using gactions cli 2.1.3 and Google have now moved on to gactions cli 3.1.0.
Not only have the commands changed, but so too has the file formats and structure.
It appears there is also a new Google Actions Console, and actions.intent.TEXT is no longer available.
My Action is webhook connected to my server, but I cannot figure out how to get the action.intent.TEXT included and working.
Everything I find, even here
Publishing Actions on google without Dialogflow
is pre version update and follows the same pattern.
Can anyone point to an up-to-date, v3.1.0, discussion, tutorial or example about how to send all talker phrases through to an NLP that isn’t dialogflow, or has Google closed that avenue?
Is it possible to somehow go back and use the 2.1 CLI either with the new Console or revert the console back. (I have both CLI versions, I can see how different their commands are)
Is it possible to go back and use 2.1?
There is no way to go back to AoG 2. You probably also don't want to do so - newer features aren't available with v2 and are only available with v3.
Can I use my own NLP with v3?
Yes, although it isn't as obvious, and there are some changes in semantics.
As an overview, what you'll need to do is:
Create a Type that can accept "Free form text". I usually call this type "Any".
In the console, it looks something like this:
Create a Custom Intent that has a single parameter of this Any Type and at least one phrase that captures everything for this parameter. (So you should add one training phrase, highlight the entire phrase, and set it for the parameter. Sometimes I also add additional phrases that includes words that I don't want to capture.) I usually call the Intent "matchAny" and the parameter "any".
In the console, it could be something like this:
Finally, you'll have a Scene that you transition to from the Main invocation. When it matches the "matchAny" Intent, it should call your webhook with a handler name. Your webhook will be called with the "any" parameter set with the user utterance. (Note that the JSON has also changed.
Again, the console might have it looking something like this:
That seems like a lot of work. Isn't there just some way to do all that from the command line?
Yes. You can do all of that in the configuration files that the CLI accesses and then upload it. (You can then also use the console to review the configuration, if necessary, to make sure they're configured as you expect. You can shift back and forth between them as appropriate.)
Google also has a github repository that contains most of the files pre-configured for this sort of setup.
You will need to update the configuration from the repository to handle the webhook correctly (it includes code to illustrate what is happening using the inline code editor) and to add your project ID.

Azure ElasticPool "BadRequest" during creation deployment when using ARM template

I have a task where I need to use ARM template to "setup SQL server with elastic pool and 2 databases (imported from bacpac files) use Microsoft Adventureworks samples."
Most of the template I made using "101-sql-elastic-pool-create" template that is available here: https://github.com/Azure/azure-quickstart-templates/tree/master/101-sql-elastic-pool-create
I used it for the elastic pool setup and used a sample from this documentation (https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-tutorial-deploy-sql-extensions-bacpac) to have the .bacpac imported to the database
But when I try to deploy this template (the template is available to see here: https://github.com/KarlisAG/SQL_ARM/blob/main/azuredeploy.json ) it throws me an error
("Resource Microsoft.Sql/servers/elasticPools 'task4sql/elasticp' failed with message '{ "code": "BadRequest", "message": "An error occurred while processing this request.", "target": null, "details": [], "innererror": [] }' ")
So, the biggest problem is (besides me being an absolute newbie) not knowing what I need to fix, because there is no additional information granted, besides the "BadRequest". For deployment I used two different methods: 1) the automatically generated one from VS when created Azure resource groups, 2) One shown in this documentation, with few of my own changes, so it could work for me ( https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-tutorial-deploy-sql-extensions-bacpac#deploy-the-template ), from where I also got the code part for importing .bacpac to my newly created database. [Both of the are available at the same repository, named "Deploy-AzureResourceGroups.ps1" and "DeployScript.ps1" respectively].
Both of the methods return the same error.
I even manually created these things in Azure portal to see what their template looks like and maybe copy some things that are not present in my template, but from what I saw I have exactly what they automatically generate.
And when I checked the deployment status in Azure portal I can also see that during the elastic pool creation it fails: screenshot from that section available here
So does anyone know how should I have created this type of template, or did I recreate it poorly, or am I missing some small mistake that keeps blocking me?
So after multiple tries it seems that I finally figured out what I was doing wrong. I am still not sure which of the changes made a difference, besides the last one, so I will write what I changed, so other people who could be facing similar issue know what they could do fix the issue.
At first, after #stringfellow noted, I thought that Free Trial is restricting me from doing anything, but after I lowered my DTU multiple times, to the point where it was at 5 (starting from 100), the same issue persisted, so probably it was not the issue (later on I had to change it at minimum to 50). I also changed the Elastic Pool edition from Standard to Basic. But doing these changes still didn't fix the issue.
At last, after answering #NachoMartínez-Aedo comment about the api version, it got me thinking. Because in the code that I posted I used "2020-08-01-preview" api version, but in reality I used "2014-04-01-preview", because when I changed the api version of all my parts to the 2020 one, then powershell told me that (No registered resource provider found for location 'northeurope' and API version '2020-08-01-preview' for type 'servers/databases/extensions'. The supported api-versions are '2014-01-01, 2014-04-01, 2014-04-01-preview'.). And after reading through that again and remembering that when I was looking at some documentation and Azure portals automatically generated templates I knew that I always say them using the 2020 api, not the 2014, which left me confused as to why I couldn't also use the newest version. And reading that error again I saw, that it specifically told that 2020 api version was not supported for the type "servers/databases/extensions", not that all of the parts must be in 2014 version (which is what I thought when I saw that error), so I tried and changed all the 2014 back to 2020 and left the extension api back at 2014 (previously I thought that all api versions should be the same, not sure why, maybe because most of the examples and documentation had everything have the same api version) and the everything worked, even the import part, about which I was worried.
So in the future I am not too sure if there is a better/newer way to import .bacpac file to newly created database with ARM, or just have to leave it as is and in the future use this same approach. Does anyone know?
I got the import extension from here: https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-tutorial-deploy-sql-extensions-bacpac
, where they use examples with 2014 api for the extension, so because of that I tried to use it for all my parts, but only during this answer writing did I realize and look through it again, that they used the 2014 api only for the extension part and not other parts, like server, database, etc.
TL;DR
So basically I needed to use the '2020-08-01-preview' api for everything besides from the extension part, where the newest api version is only '2014-04-01-preview'
I was able to deploy most of your template and use similar parameters in my own subscription. I saw in your screen capture that you are using a Free Trial subscription. I am curious if that has anything to do with the 'BadRequest' due to any sort of DTU limitation.
Here is my deployment, which failed as expected when it tried to import the databases.

Simple API call within the context of DocFx preprocessor

I would like to know if it is possible to make a simple API call (e.g. GitHub API v3) within the context of a DocFx custom template preprocessor. I have been trying all sorts of different approaches, but nothing has fully worked so far.
My goal is to make a call to an API to retrieve some data, and then update the model accordingly to be used in the *.liquid or *.tmpl renderers.
I have tried using the http/https node modules. I have also tried using node-fetch. It results in a docfx build error something like:
Error:Error transforming model ".../index.raw.json" generated from
".../index.md" using "conceptual.html.primary.js". Error running
Transform function inside template preprocessor
According to DocFx documentation, preprocessors follow the ES 5.1 standard. My code conforms to this.
Does anyone know if this is possible?
By the way, I am able to do simple model manipulation just fine, so I understand the basic concepts here with the DocFx preprocessors.
Thanks!
For the benefit of others, I discovered DocFX uses jint which cannot require a Node library directly. Therefore, it appears the plugin route is a better way to go for this use case.

Create new work item type using VSTS Extension

Based on the documentation https://learn.microsoft.com/en-us/vsts/extend/overview?view=vsts#what-makes-up-an-extension, a VSTS extension can be used to extend the work item form.
However, I would like my extension to automatically create a new work item type once it is installed. Is this something that is possible? I can't find any documentation online that suggests how to do it.
Theoretically this is possible, the extension has a "first load" call which you can use to use the rest api to create a custom process or update the existing custom process. The REST Api to change processes isn't public yet, so you'll have to work from using fiddler to watch how the web ui does it.
Due to the way processes are linked to projects, all projects with that process will get the new work item type.
I could not find a lot of documentation online for this, but the VSS web extensions SDK(https://www.npmjs.com/package/vss-web-extension-sdk) has a REST client called 'ProcessDefinitionsRestClient' declared in the typings/tfs.d.ts file. This client has a createWorkItemType method available that looks like this:
createWorkItemType(workItemType: ProcessDefinitionsContracts.WorkItemTypeModel, processId: string): IPromise<ProcessDefinitionsContracts.WorkItemTypeModel>;.
The 'ProcessRestClient' client has methods to create a new/inherited process to which the new WIT can be added.
I have not tried it out yet, and these APIs are still in preview, but maybe they can get you started on the right path.

Plugins in ViewModel

I'm new on MvvmCross and I want to use my plugin in my Model/ViewMode. I use the v3.
In some example I see IMvxServiceConsumer and GetService, but I guess that is the annotation for vNext but it seems to be different in the v3.
So, how can I do that?
Thanks
IMvxServiceConsumer<T> and GetService<T> were replaced with Mvx.Resolve<T> in v3.
Further, v3 provides constructor injection of dependencies - see http://slodge.blogspot.co.uk/2013/03/v3-new-viewmodel-lifecycle.html for information about how this decision was reached.
For plugins, N=8 in the tutorial series gives a quick and easy introduction to using the Location plugin. For more info see:
blog - http://slodge.blogspot.co.uk/2013/05/n8-location-location-location-n1-days.html
youtube - https://www.youtube.com/watch?v=AomjbED9AzM&list=PLR6WI6W1JdeYSXLbm58jwAKYT7RQR31-W&index=10
If you want to write a new plugin, then :
the up-to-date sample is https://github.com/slodge/MvvmCross-Tutorials/tree/master/GoodVibrations
there are some notes on this sample in https://speakerdeck.com/cirrious/plugins-in-mvvmcross