Using Swagger - UI 3XX
I would like to simply know if this is possible and if so, how:
We currently have a need to hide the definition URL path that Swagger - UI displays.
I know it's not possible to remove this URL and I'm not looking to do that, all I'm wanting to do is to hide /mask the text box from the client viewing this page.
Looking at the new Swagger docs here, there are some awesome tricks and extras you can add, however - nothing I can see in relation to my query.
I'm pretty sure, I could interrogate the HTML, find the id of the element in question and manually change the display of it within the index.html, I would much rather prefer using a build in method, if one exists before getting to that possible solution.
i.e. Something like this is possible and works:
<style> .download-url-input { display: none !important; } </style>
Is this even possible?
In Swagger UI 3.x, you can hide the top bar in one the following ways.
Option 1
Edit dist\index.html and find this code:
const ui = SwaggerUIBundle({
url: "http://petstore.swagger.io/v2/swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
Remove layout, SwaggerUIStandalonePreset and SwaggerUIBundle.plugins.DownloadUrl, so that the constructor looks like this:
const ui = SwaggerUIBundle({
url: "http://petstore.swagger.io/v2/swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis
]
})
(Source)
Option 2 - Recompile Code
You can also recompile Swagger UI without the top bar plugin as explained here and rebuilding it. You will need Node.js 6.x and npm 3.x.
Edit src/standalone/index.js and remove TopbarPlugin from presets:
// import TopbarPlugin from "plugins/topbar" // <----------
import ConfigsPlugin from "plugins/configs"
// the Standalone preset
let preset = [
// TopbarPlugin, // <----------
ConfigsPlugin,
() => {
return {
components: { StandaloneLayout }
}
}
]
Rebuild Swagger UI – in the project's root directory run
npm install
then
npm run build
Now your dist\index.html does not have a top bar.
For the version 3.x add slice function to:
SwaggerUIStandalonePreset.slice(1)
In the version 4.x (inside swagger-initializer.js file) set layout to "BaseLayout"
window.ui = SwaggerUIBundle({
url: "./swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "BaseLayout" // <<< here
});
Related
Recently I had to update our jquery version from 1.x to 3.5. With that I also had to update Jquery UI to 1.12. I used the opportunity to import our js dependencies as node_modules instead of just having a copy in our repository.
When running our WebApp within the IDE everything works fine and as expected. However, as soon as I build the .exe with pyInstaller (running a grunt task to minify everything into a single app.min.js), I get the error message "g.sortable is not a function". The same problem occurs with jquery.transit.
package.json:
{
"dependencies": {
// snip
"jquery": "3.5.1",
"jquery-ui": "1.12.1",
"jquery.iframe-transport": "1.0.0",
"jquery.transit": "0.9.12",
}
}
configuration.js:
require.config({
paths: {
// snip
'ui.sortable': '<...>/3rdparty/js/node_modules/angular-ui-sortable/dist/sortable',
'jquery': '<...>/3rdparty/js/node_modules/jquery/dist/jquery',
'jquery.transit': '<...>/3rdparty/js/node_modules/jquery.transit/jquery.transit',
'jquery-ui': '<...>/3rdparty/js/node_modules/jquery-ui-dist/jquery-ui',
}
})
Gruntfile.js:
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('<...>/3rdparty/js/package.json'),
requirejs: {
compile: {
options: {
baseUrl: '<...>/js',
mainConfigFile: '<...>/js/configuration.js',
optimize: 'none'
}
}
},
ts: { ... },
sass: { ... },
uglify: {
'js': {
files: [
{
expand: true,
src: [
'app/**/*.js',
'!app/**/3rdparty/**/*.js',
'!app/<...>/js/configuration.js',
'!app/<...>/js/patch.js'
]
}
],
options: {
compress: true,
mangle: false
}
}
}
});
};
Again, the javascript files seem to work together properly as there is no problem when I start the webservice in pycharm. It's only when I compile and minify everything that the jquery UI widgets stop working. Other external libraries for whose I started using npm work perfectly fine.
I am kinda clueless at this point.
So, the solution to my problem was to just
import 'jquery.transit';
import 'jquery.ui';
In one of my TypeScript files. Apparently in the whole project that never happened anywhere. It worked before my updates because the jqueryUI version we used had the AMD part of it commented out.
I've written a simple Angular PWA, that I have added on my iPhone to the Homescreen. To remove the Safari Toolbar, I have already included in my index.html:
<meta name="apple-mobile-web-app-capable" content="yes">
See Image "1", the Toolbar is gone. The Problem is: when I hit the "Start"-Button on Image 1, the Angular App routes to a new Component (the URL changes from https://example.com/foo to https://example.com/foo/bar), and some other Toolbar pops up (see Image "2").
Is there any way to prevent iOS from showing this Toolbar at Image 2? Thank you!
Image 1:
Image 2:
I did find a solution myself:
It seems like iOS shows this Toolbar if the Host or Path of a URL changes, so I checked if it also takes the URL Fragment (https://en.wikipedia.org/wiki/URL#Syntax) into account, and it does not! Yay!
So my solution for an Angular-based Webapp is to configure Hash-based LocationStrategy like this in your AppModule:
import {HashLocationStrategy, LocationStrategy} from "#angular/common";
#NgModule({
declarations: [
...
],
imports: [
...
],
providers: [
{ provide: LocationStrategy, useClass: HashLocationStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule { }
This way no Toolbar pops up, if I change the Route in Angular.
I ran into this as well when creating a PWA in Angular 8. The solution was
#NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true })]
})
in my app-routing.module.ts
I'm currently building a Yeoman generator, and although I seem to have mastered the basics, I'm struggling to figure out how to include various dependencies only when the user chooses to include them.
After looking at some existing generators, I've worked out that a checkbox prompt is the standard way of allowing users to select which dependencies they'd like to include in their new app:
var prompts = [{
type: 'checkbox',
name: 'features',
message: 'What more would you like?',
choices: [{
name: 'Sass',
value: 'includeSass',
checked: true
}, {
name: 'Bootstrap',
value: 'includeBootstrap',
checked: true
}, {
name: 'Modernizr',
value: 'includeModernizr',
checked: true
}]
}];
From here on in though, I'm stumped. What I'd like is to allow users to choose what dependencies they'd like to include both using bower, and NPM (through the package.json file).
How would I go about doing this?
Thanks in advance for any help!
Making sure to only include the dependencies the user needs is a good practice!
The easiest way - and also the way the official generators do it - is to make the package.json you're generating a template. The template can then include arbitrary conditions to mix and match the packages you need.
The first step is to export the answers from the prompt, so they're available in the template:
this.prompt(prompts, function (answers) {
var features = answers.features;
function hasFeature(feat) {
return features && features.indexOf(feat) !== -1;
}
this.includeSass = hasFeature('includeSass');
this.includeBootstrap = hasFeature('includeBootstrap');
this.includeModernizr = hasFeature('includeModernizr');
}.bind(this));
The template for the example would then look something like this. The <% ... %> syntax is actual JavaScript and is executed before the result is written to disk.
templates/_package.json
{
"name": "<%= _.slugify(appname) %>",
"dependencies": {
"my-dependency-a": "^0.4.5",<% if (includeModernizr) { %>
"modernizr": "^0.11.0",<% } %><% if (includeBootstrap) { %>
"bootstrap": "^3.3.4",<% } %>
"my-dependency-b": "^0.5.0"
},
"engines": {
"node": ">=0.10.0"
}
}
Back in your generator code, make sure to generate this file from the template:
packageJSON: function () {
this.template('_package.json', 'package.json');
}
And as a final step, you want to actually run npm install in the generated directory. There's a helper available for Yeoman, that does this for you:
this.on('end', function () {
this.installDependencies();
});
If you look at the generator-webapp code that does this, there are a few more subtleties to handle cases where the user might not want to install the dependencies automatically and special handling for test frameworks. But for the case you describe, the above is completely sufficient.
I hope this helps. :)
I'm using UI-Grid 3.0 unstable on an angular page that is loading data via Restangular. So far most of it seems to be ok. I am using the selection module along with it and I'm having difficulty with pages that are loading the {enableFiltering: true} gridOptions in that most of the pages are not showing the input box on the grid.
I invoke the ui-grid on the html page using:
<div class="gridStyle" ui-grid="gridOptions" ui-grid-selection></div>
and my gridOptions in my controller looks like this.
$scope.gridOptions = {
enableFiltering: true,
data: 'data',
columnDefs: [
{field: 'name', displayName: 'Name'},
{field: 'date', displayName: 'Date', cellFilter: 'date:\'MM-dd-yyyy\''}
],
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
}
};
I honestly can't figure out why its not appearing on the page.
I don't understand 100% the problem, but I could go around it by overriding some css. The height in css were 100% and I changed them to auto.
.ui-grid-header-cell{
height:auto;
}
.ui-grid-cell-contents {
height: auto;
}
I hope this would be helpful.
This an awful hack, but I always use the filters, so I just tracked the container that was the wrong height. I had lost hours to this trying to find the cause and using all the suggested fixes.
The container turned out to have the class "ui-grid-header-canvas", so I just set the height to 54px after the grid had sized itself.(after I set the data)
$(".ui-grid-header-canvas").css("height","54px")
Sorry, but it works and I have a deadline..
I'm trying to add an h4 tag to the refinerycms wysiwyg editor. How do i do this? Not finding any documentation on this.
I'm assuming i have to do something with this config var:
config.wymeditor_whitelist_tags = {}
The following instructions apply to versions 2.x.x and 3.x.x of Refinery CMS.
However, in version 3.x.x you will need to use custom_visual_editor_boot_options instead of custom_wymeditor_boot_options.
Using this file: https://github.com/refinery/refinerycms/blob/master/core/app/assets/javascripts/admin.js you can specify custom options for WYMeditor in Refinery.
First, you need to override the file:
bundle exec rake refinery:override javascript=admin
Now, open app/assets/javascripts/admin.js and edit it to be like the following:
// Use this to customize the wymeditor boot process
// Just mirror the options specified in boot_wym.js with the new options here.
// This will completely override anything specified in boot_wym.js for that key.
// e.g. skin: 'something_else'
if (typeof(custom_wymeditor_boot_options) == "undefined") {
custom_wymeditor_boot_options = {
containersItems: [
{'name': 'h1', 'title':'Heading_1', 'css':'wym_containers_h1'}
, {'name': 'h2', 'title':'Heading_2', 'css':'wym_containers_h2'}
, {'name': 'h3', 'title':'Heading_3', 'css':'wym_containers_h3'}
, {'name': 'h4', 'title':'Heading_4', 'css':'wym_containers_h4'}
, {'name': 'p', 'title':'Paragraph', 'css':'wym_containers_p'}
]
};
}
Note that what you are doing is overriding boot_wym.js.erb which only specifies h1, h2, h3 and p as container tags. See: https://github.com/refinery/refinerycms/blob/2-0-stable/core/app/assets/javascripts/refinery/boot_wym.js.erb#L49-L54
Any options that you specify inside custom_wymeditor_boot_options override anything inside wymeditor_boot_options in boot_wym.js.erb so make sure that it's valid Javascript or else the editors won't load at all.
Hope that helps; let me know if you need anything clarified.
Phil