How to get a version of UI5 framework within the controller? - sapui5

I want to retrieve an UI5 version (e.g. 1.97.0-SNAPSHOT) inside of controller. The simplest way is to get a value of sap.ui.version, but it's a global variable, which I want to avoid.
I thought, sap.ui.VersionInfo would be a right choice, but looking at its API, I can't find any method, related to the retrieval of the UI5 version.
I also checked the controller's internals (not too deep) and sap.ui.Device, but no version number.
How can I retrieve the UI5 framework version without using a global variable?

If you're using OpenUI5, require sap/ui/core/Core and get an instance of sap/base/util/Version via Core.getConfiguration().getVersion().
In case of SAPUI5, however, the patch version is not always same as the version of SAPUI5 core (sap.ui.core) since SAPUI5-exclusive libraries may contain patches in addition to OpenUI5 libraries. See this graphic SAPUI5 library patch versions (e.g. v1.96). To get the correct SAPUI5 version reliably, require the module sap/ui/VersionInfo. Its method load() will return a promise that resolves with an object - same as https://<host>/resources/sap-ui-version.json - containing all information about the current framework including its version.
// VersionInfo required from "sap/ui/VersionInfo"
// VersionUtil required from "sap/base/util/Version"
// Within an async function:
const { version } = await VersionInfo.load();
const versionUtil = new VersionUtil(version);
As you can see, it's also possible to combine the retrieved version string with the module sap/base/util/Version which provides methods such as getMajor(), getMinor(), getPatch(), compareTo(...), inRange(...), etc.
See section "SAPUI5 Version vs. OpenUI5 Version (Core Version)" from the documentation topic Versioning and Maintenance of SAPUI5.
⚠️ Known issue
When using the module sap/ui/VersionInfo in a standalone UI5 app (e.g. built with ui5 build self-contained -a), the top version value from the generated resources/sap-ui-version.json is the app version instead of the version of the framework. There is currently no reliable way for standalone SAPUI5 apps to determine the correct patch version.
See the issue SAP/ui5-tooling#353.

Related

OpenAPI (aka Swagger) in Azure Functions V2

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.

Yii2 is it possible to run rest action within the app itself?

I have created a REST project in yii2 and i have some yaml data that should be stored in the database. These are crowd data, that is authorized people can add new yaml files and our app will parse those data and store in database.
But these data might change in the future (i.e. add/delete columns) which would rely on version of the REST api (v1.0, v2.0 etc)
Thus i would like to call the appropriate rest action to do it.
I know there is the function $controller->run() but how do i use it to make a POST or a PUT request?
Is there any alternative to using yii httpclient?
Thanks
If I am not wrong, you want to execute different action depending on the version of the API.
For that, you can create modules inside your frontend/backend directory and name the modules as per your versions. Whenever you have a new version create a new module and upgrade the version name. Thus you always get the proper versioning. So v1, v2.. will be modules in your project.
The good thing about this is that you can have same action name in different modules under same controller name. Thus if in version 1 you have 5 columns and the api is like /v1/data then you can have 7 columns in version 2 and the api can be like /v2/data.
For more details on modules: http://www.yiiframework.com/doc-2.0/guide-structure-modules.html

How to specify SonarQube rule description as a markdown/html resource file instead of using annotation?

I have my custom rule, let's say with AEM-1 key. So, as it is done here, I make my AEM-1.html resource file with some simple html content and it does not get's picked up by SonarQube 5.1. It refuses to start, because no description is provided for the rule.
I tried different packages names, tried to look for convention in source code etc. What's missing? Is there any documentation on that?
The naming convention is org/sonar/l10n/{plugin key}_{language}/rules/{repository key}/{rule key}.html.
It was documented in http://docs.sonarqube.org/display/DEV/Internationalization at the time rule descriptions supported localization. That's not the case anymore since version 4.2, but these HTML bundles are still supported.
The correct way since version 4.3 is to use the low-level API org.sonar.api.server.rule.RulesDefinition. It allows you to implement any kind over layer over it (xml, json, annotations, ...).

How could I include a plugin system for my Dart app?

I have a Qt application containing a Webkit module and using Dart (compiled to JS). It's like a bare-bones browser written in Qt. The application basically replaces certain text on the webpage with different text. I want users to be able to make their own Dart files to replace their own text with their own different text.
Any recommendations for approaches to creating a plugin system?
I think that this question needs a little clarification: are you asking about using Dart for scripting Qt applications (where Dart plays the role of a scripting language), or are you asking about a plugin system for Dart application that is compiled to JS and used in a Qt application, probably via QtScript (in which case, the role of a scripting language is played by JavaScript)?
I presume that it is the latter variant (and I don't know enough about Qt to be able to answer about the former variant anyway).
Let's assume that all plugins for the Dart application are available at the build time of that Qt application, so that you don't need to compile Dart to JS dynamically. Then, if you compile a Dart script, resulting JS will include all necessary code from its #imports. All you need is to create a proper script that imports all plugins and calls them (importing isn't enough, as dead code will be eliminated).
Maybe an example will be more instructive. Let's say that you want to allow plugins to do some work on a web page. One way you might structure it is that every plugin will be a separate #library with a top-level function of a well known name (say doWork). Example of a plugin:
// my_awesome_plugin.dart
#library('My Awesome Plugin')
doWork(page) {
page.replaceAll('JavaScript is great', 'Dart is great');
}
You can have as many plugins of this nature as you wish. Then, you would (at the build time) generate a following simple main script in Dart:
// main.dart
// these lines are automatically generated -- for each plugin file,
// one #import with unique prefix
#import('my_awesome_plugin.dart', prefix: 'plugin1');
#import('another_plugin.dart', prefix: 'plugin2');
main() {
var page = ...; // provided externally, from your Qt app
// and these lines are automatically generated too -- for each plugin,
// call the doWork function (via the prefix)
plugin1.doWork(page);
plugin2.doWork(page);
}
Then, if you compile main.dart to JavaScript, it will include all those plugins.
There are other possibilities to structure the plugin system: each plugin could be a class implementing a specific interface (or inheriting from a specific base class), but the general approach would be the same. At least the approach that I would recommend -- making each plugin a separate library.
You probably don't like the step with generating the main script automatically, and I don't like it either. But currently, Dart only allows one way to dynamically load new code: spawning new isolates. I'm not sure how (or even if) that would work in QtScript, because isolates are implemented as web workers when compiled to JavaScript, so I won't discuss this here.
Things will get more complicated if you want to support compiling Dart scripts at the runtime of your Qt application, but I think that I'm already guessing too much about your project and I might be writing about something you don't really need. So I'll finish it like this for now.

Graceful degradation on iPhone

How do I write a program for iPhone (Objective C++) that runs on OS 2.0 but takes advantage of 3.0 features if they're available?
Example: copy&paste (class UIPasteboard). Nice feature to have, but I don't want to kill backward compatibility. Do I compile against SDK v. 3 or v. 2? If the latter, how do I create an instance of UIPasteboard, considering it's not declared in the headers? If the former, won't some C-linkage functions cause "unresolved reference" upon loading under OS 2.0?
Edit your Target's build settings like this:
Set the Base SDK to the version whose APIs you want to use (e.g. 3.0 or 3.1).
Set the Deployment Target to the lowest OS version you want to support (e.g. 2.2.1).
When building, you compile against the Base SDK. For all symbols that defined in your Base SDK but not available in your Deployment Target, you need to add runtime checks to your code to check for their availability. Examples:
Check if UIPasteboard is available:
Class PasteboardClass = NSClassFromString(#"UIPasteboard");
if (PasteboardClass != nil) {
// UIPasteboard is available
}
Check if a specific method is available:
if ([UITableViewCell respondsToSelector:#selector(initWithStyle:reuseIdentifier:)]) {
// ...
}
I didn't try this but i would recommend building against the most recent (3.x) SDK release. So you get any class and method definitions that might be available on the target device.
And in your application you have to check the OS release your application runs on. Based on the target OS you have to decide which Class and Method you should use. After all it is a big mess of conditional code, probably with a lot of additional code to provide missing functionality (i.e. direct access to SQLite instead of using Core-Data). In my experience that should not lead to problems, because most type information is erased at runtime.