Transform openapi.yml to html file. Kotlin - kotlin

I have an openapi generator plugin in my Kotlin project.
id("org.openapi.generator") version ("5.2.1")
...
tasks {
named<Test>("test") {
useJUnitPlatform()
dependsOn("openApiValidate")
}
named<org.openapitools.generator.gradle.plugin.tasks.ValidateTask>("openApiValidate") {
inputSpec.value("$rootDir/openapi.yml") // any openapi.yml can be provided
recommend.value(true)
}
named<org.openapitools.generator.gradle.plugin.tasks.GenerateTask>("openApiGenerate") {
generatorName.value("kotlin")
configOptions.put("idea", "true")
packageName.value("com.creatiosion.spider")
inputSpec.value("$rootDir/openapi.yml") // any openapi.yml can be provided
}
}
So there is a generated Api and an openapi.yml that the is generated from.
Is there a plugin to also generate a swagger html?
I need sth like Swagger Editor but in my project https://editor.swagger.io/

Related

How to customize WAR plugin in subproject in Gradle build script (Kotlin)

I create a Gradle project with several sub-modules, and one module needs war plugin, I just want to customize the web app directory, but the code does not work:
apply {
plugin("war")
plugin("org.gretty")
}
// cannot work
tasks.getByName("war") {
from("src/main/webfiles")
}
// cannot work either
tasks.war {
webAppDirName = "src/main/webfiles"
}
//... other code
This is how I code in the sub-project subproject.gradle.kts file, How to solve this? Thanks for any help!
Solved with the code:
configure<WarPluginConvention>{
webAppDirName = "src/main/webfiles"
}

Change Kotlin Javascript output directory

I have just started using Kotlin to produce Javascript, but cannot find a way to change the Javascript output directory.
This is specifically for a nodejs target, and using Gradle with Kotlin script.
There is an example given in the Kotlin docs for a browser target:
kotlin.target.browser {
distribution {
directory = File("$projectDir/output/")
}
}
but there does not seem to be an equivalent for kotlin.target.nodejs
This is now easy (Kotlin 1.40):
https://kotlinlang.org/docs/reference/js-project-setup.html#distribution-target-directory
kotlin {
js {
browser {
distribution {
directory = File("$projectDir/output/")
}
}
binaries.executable()
// . . .
}
}
Unfortunately, there are no possibilities to do this with NodeJS. I created an issue - https://youtrack.jetbrains.com/issue/KT-40416.

Check for dependencies update with kotlin-dsl

This question has already been asked before, however the solution is still unknown... Kotlin DSL build scripts dependency updates
With the new implementation of kotlin-dsl. Now the imports looks like this.
implementation Koin.core
implementation Koin.android
and the buildSrc.
object Versions{
const val koin = "2.0.1"
}
object Koin {
val core = "org.koin:koin-core:${Versions.koin}"
val android = "org.koin:koin-android:${Versions.koin}"
val scope = "org.koin:koin-androidx-scope:${Versions.koin}"
val viewModel = "org.koin:koin-androidx-viewmodel:${Versions.koin}"
val extension = "org.koin:koin-androidx-ext:${Versions.koin}"
val test = "org.koin:koin-test:${Versions.koin}"
}
in this case Koin is using a previous version, but i know that there's a new version https://github.com/InsertKoinIO/koin
anyone knows how to check if the dependencies has a newer version with kotlin-dsl?
I've tested this Gradle Dependencies Update Check Plugin on my Android/Kotlin DSL build (with a separate Versions class with versions definitions) and it works fine for me:
CheckDependencyUpdates Gradle Plugin
(I've also tested that it works with a traditional Groovy-DSL project)
To install the plugin (copied from linked page) add the following to your build.gradle.kts. Note that I've removed the version number from this as it will, unlike the page I've linked to, get out of date:
plugins {
id("name.remal.check-dependency-updates")
}
To run the update check (copied from gradle tasks) run the following:
gradle checkDependencyUpdates
You will see an output section similar to the following:
New dependency version: com.android.tools.build:aapt2: 3.6.1-6040484 -> 3.6.3-6040484
New dependency version: com.android.tools.lint:lint-gradle: 26.6.1 -> 26.6.3
I made this plugin. Dependency Updates Commenter.
Just apply plugin and add annotation to the dependency properties and execute commentDependencyUpdates task. This is the example:
object Junit {
const val junit = "junit:junit:4.12"
}
import io.github.zeroarst.dependencyupdatescommenter.CommentUpdates
object Junit {
// Available versions:
// 4.13-rc-2
// 4.13-rc-1
// 4.13-beta-3
// 4.13-beta-2
// 4.13-beta-1
#CommentUpdates
const val junit = "junit:junit:4.12"
}

Aurelia library js file in Bundle but is resolved as static file

My project structure is as follows:
src
..lib
....someLibrary.js
bundles.js:
"bundles": {
"dist/app-build": {
"includes": [
"[**/*.js]",
"**/*.html!text",
"**/*.css!text"
],
"options": {
"sourceMaps": 'inline'
"inject": true,
"minify": true,
"depCache": true,
"rev": true
}
},
The project builds fine, but when I check app-build.js I don't find a definition for lib/someLibrary.js. I am using typescript for my own project so I assume this has something to do with that, how can I mix regular js files and output from my transpiled TS files into the same app-build bundle?
Update
So I tried to split the 'build-system' gulp task into two tasks: 'build-typescript' which is the same as 'build-system' was before, then I created 'build-libs' which looks like so:
gulp.task('build-libs', function() {
return gulp.src(paths.root + '**/*.js')
.pipe(plumber({errorHandler: notify.onError('Error: <%= error.message %>')}))
.pipe(changed(paths.output, {extension: '.js'}))
.pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: '/src' }).on('error', gutil.log))
.pipe(gulp.dest(paths.output));
});
I then added to my dist/app-build bundle config: "lib/someLibrary.min.js"
And now my app-build.js does have the library defined, however when I try to use the library in one of my views using:
<require from="lib/someLibrary.min.js">
I get an error:
Failed to load resource: the server responded with a status of 404 (Static File '/dist/lib/someLibrary.min.html' not found)
What?!?? Why is it looking for html when nowhere is html ever involved in this whole scenario? Why is something that should be easy this hard?
Update2
So apparently 'require' does not work with javascript files. I changed to use the 'script' tag, however it seems these get stripped out when rendered by Aurelia. I am at a loss as to how to get Aurelia to do what I want it to.
Ok so after much frustration and disbelief at how hard something so simple could be, in addition to the changes to the build tasks mentioned above (which includes the javascript library file that has no npm/jspm package into the app-bundle) I created a modified version of this solution which looks as follows:
import { bindable, bindingMode, customElement, noView } from 'aurelia-framework';
#noView()
#customElement('scriptinjector')
export class ScriptInjector {
#bindable public url;
#bindable public isLocal;
#bindable public isAsync;
#bindable({ defaultBindingMode: bindingMode.oneWay }) protected scripttag;
public attached() {
if (this.url) {
this.scripttag = document.createElement('script');
if (this.isAsync) {
this.scripttag.async = true;
}
if (this.isLocal) {
const code = 'System.import(\'' + this.url + '\').then(null, console.error.bind(console));';
this.scripttag.text = code;
} else {
this.scripttag.setAttribute('src', this.url);
}
document.body.appendChild(this.scripttag);
}
}
public detached() {
if (this.scripttag) {
this.scripttag.remove();
}
}
}
To use it, simply add the following tag to the view where you want the script library to be used as follows:
<scriptinjector url="lib/bootstrap-toc.js" is-local.bind='true'></scriptinjector>
This will keep the original scriptinjector functionality which allows you to add remote 3rd party libraries to your Aurelia app but it will also allow you to load any local 3rd party libraries that you have bundled with your app.
Hope this helps someone.

How to inject external JS library into a module?

I'm using SeedStack to create a web application. In order to do that, I use W20 to develop my frontend. I need specific JavaScript libraries into that project. How can I inject an external javascript library into it ? I want to use Chart.js http://www.chartjs.org/ to visualize data into charts. To do that, I suppose that I have to inject ChartJS as a dependency module in Angular.
Thank you for your help.
Before getting to the specific answer, please note that SeedStack already has an add-on for charts. As for integrating a library with W20, you have two main things to do:
Configure RequireJS to load the JS file and be able to inject it as a dependency.
Integrate the library with the AngularJS framework, which is often done by writing some directive.
Fortunately for you, Angular directives are already available for Chart.js, thanks to the angular-chart.js library. You just need to configure RequireJS to load it. Add a requireConfig section to the manifest of one of your fragments:
{
"id": "my-fragment",
...
"requireConfig": {
"paths": {
"{angular-chart.js}": "${components-path:bower_components}/angular-chart.js/dist",
"{chart.js}": "${components-path:bower_components}/chart.js/dist"
},
"map": {
"{angular-chart.js}/angular-chart": {
"angular": "{angular}/angular",
"chart": "{chart.js}/Chart"
}
}
}
}
The paths section declares locations of the two Chart.js libraries. Note that we use a variable named components-path with a default value of bower_components here. This is useful when using the W20 bridge add-on.
The map section declares a mapping between the expected and the real paths for dependencies of angular-chart.js.
You can then use the angular-chart.js library according to its documentation:
define([
'{angular}/angular',
'{angular-chart.js}/angular-chart',
], function(angular) {
var module = angular.module('myModule', ['ngResource', 'chart.js']);
module.controller('ContentController', [ '$scope', function($scope) {
// your JS code here
// (with your markup in a corresponding angular template)
}]);
});