Remove petstore spec when starting swagger editor - swagger-editor

I am using Swagger Editor locally in my machine.
When I start the Swagger Editor, it shows the spec for petstore by default at startup.
I want to remove that and show a blank editor. Is there a way to do that at startup.

A simple workaround is to run the editor with the ?url= parameter where the URL points to an empty page (no HTTP response body), such as http://httpbin.org/status/200.
http://editor.swagger.io/?url=http://httpbin.org/status/200
This will open a blank editor.
Alternatively, you can modify the editor's source code and build your own version. You will need Node.js 6.x and npm 3.x (as of time of this writing).
The default editor contents seems to be set here:
https://github.com/swagger-api/swagger-editor/blob/master/src/plugins/local-storage/index.js#L29
In src\plugins\local-storage\index.js, replace
import PetstoreYaml from "./petstore"
with
const PetstoreYaml = ""
Rebuild the editor:
npm run build

Insert url property into swagger-editor's index.html like swagger-ui's it.
detail
Open custom yaml spec in swagger editor on startup · Issue #1727 · swagger-api/swagger-editor
You can use Swagger-UI's config options to load in your own definiton: there's url for fetching a remote document, and spec for passing in a JavaScript object directly. Swagger-Editor passes these options directly to its underlying Swagger-UI instance.

Use the following js code to remove the default content in swagger editor.
editor = SwaggerEditorBundle({
dom_id: "#swagger-editor",
layout: "StandaloneLayout",
presets: [SwaggerEditorStandalonePreset]
});
window.editor = editor;
// The line to remove the content in swagger editor
editor.specActions.updateSpec(' ');

If you are using docker image (docker pull swaggerapi/swagger-editor) to run locally the swagger editor, then provide your own local json or yaml file as below:
$ ls
teapi-openapi.yaml
$sudo docker run -d -p 9800:8080 -v $(pwd):/tmp -e SWAGGER_FILE=/tmp/teapi-openapi.yaml swaggerapi/swagger-editor
To access:
http://<IP>:9800/
where, ip is machine IP where swagger editor image is running, Replace 9800 with any port on which you want to access

Starting from the next release v1.4.1, the following property will be added to disable the swagger-ui default petstore url:
springdoc.swagger-ui.disable-swagger-default-url=true
Copied from
https://github.com/springdoc/springdoc-openapi/issues/714#issuecomment-640215759

These two properties worked for me:
springdoc.swagger-ui.disable-swagger-default-url=true
springdoc.swagger-ui.url=/v1/api-docs (<-- your API docs URL)

Related

Where is client-dependencies-gradle exposing depedencies?

I am using client-dependencies-gradle plugin (to install polymer).
clientDependencies {
bower {
'jquery'('2.0.0')
}
npm {
"#polymer/paper-checkbox"("^3.0.0-pre.12")
"#polymer/polymer"("^3.0.0-pre.12")
"#webcomponents/webcomponentsjs"("^1.2.0")
}
}
I see that the depedencies are installed (i.e. the diretory build/client-cache/npm/#polymer/ is populated).
I do not find documentation about how client depedencies are acccesed from client application.
For example,
curl localhost:8080/#webcomponents/webcomponentsjs/b6e46ee59e51fe258423440aa58327d5/webcomponents-lite.js
curl localhost:8080/jquery/jquery.js
Where is the client supposed to see these files?
The solution was to modify the configuration of spring static content location. I did it by adding the following line to application.properties. The default is:
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
I just appended classpath:/vendor/ to make spring look for static content there too.
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/vendor/
The /src/assets/vendor directory is mapped to the url http://localhost:8080/. For example jquery that is installed under /usr/assets/vendor/jquery/jquery.js is located at http://localhost:8080/jquery/jquery.js

Generate Swagger json at Build time

I'm working on a ASP.NET Core WebAPI project and I'm trying to find a way to generate swagger json at build time ?
As i'm working with 4 environments, i'd like to have 4 swagger.json with a different name of my choice, like:
swagger_{appName}dev{buildNumber}.json
swagger_{appName}demo{buildNumber}.json
swagger_{appName}int{buildNumber}.json
swagger_{appName}staging{buildNumber}.json
Is it also possible to edit the fields in the json ? I'd like to edit (depending of the environment) the following fields : host, schemes and basePath.
I'm using Swashbuckle.AspNetCore but it appears it doesn't have an option to do such task or am I wrong ?
Thanks in advance
You have the option of generating OpenApi json file(s) from the command line without deploying using the Swashbuckle.AspNetCore.Cli nuget package.
The command will look something like this and can be added as a "post build" script
dotnet <nugetpackages>\Swashbuckle.AspNetCore.Cli\bin\$(Configuration)\netcoreapp<ver>\dotnet-swagger.dll tofile --host http://localhost --output swagger.json <bin>\<AssemblyName>.dll v1
more details can be found here https://github.com/domaindrivendev/Swashbuckle.AspNetCore#swashbuckleaspnetcorecli
I'm not sure about generating separate files for each environment offhand
The simple way is using PowerShell task to update json file and save with another name.
Simple workflow:
Read the file through Get-Content script
Using ConvertFrom-Json to converts content to object
Set the property value to update object
Using ConvertTo-Json to convert an object to a JSON-formatted string
Using Set-Content to write content to a file
For detail code, you can refer to this thread: how do I update json file using powershell.
The build number value is stored in the predefined variable: Build.BuildNumber (PowerShell: $env:BUILD_BUILDNUMBER)

Is there a JSX formatter for sublime text?

I'm using Sublime Text as a text editor.
There's a jsFormat for formatting javascript files but I can't find one for JSX.
How you guys deal with formatting JSX?
Update 4
Check prettier, not that configurable as esformatter, but currently used to format some big projects (like React itself)
Update 3
Check sublime jsfmt. If you add esformatter-jsx to the config and install the package inside the forlder for sublime-jsfmt. You will be able to format JSX files directly from Sublime. Here is a guide for that
Update 2
from the command line you can also use esbeautifier. It is a wrapper around esformatter that accept a list of globs to format
# install the dependencies globally
npm i -g esbeautifier
# beautify the files under src/ and specs/ both .js and .jsx
esbeautifier src/**/*.js* specs/**/*.js*
Update
So I ended up doing a plugin for esformatter to enable the formatting of JSX files:
https://www.npmjs.com/package/esformatter-jsx
Here is a live demo on requirebin
It should be somehow feasible to call esformatter from Sublime passing the current file as the argument. In any case to use it from the command line you can follow these instructions:
From the command line it can be used like this:
# install the dependencies globally
npm i -g esformatter esformatter-jsx
# call it (this will print to stdout)
esformatter --plugins=esformatter-jsx ./path/to/your/file
# to actually modify the file
esformatter --plugins=esformatter-jsx ./path/to/your/file > ./path/to/your/file
# to specify a config file (where you can also specify the plugins)
# check esformatter for more info about the configuration options
esformatter -c ./path/to/.esformatter ./path/to/your/file > ./path/to/your/file
==== old answer below ===
So if what you're looking is just to make your jsx files to be formatted while allowing the jsx syntax (basically beautify all the javascript syntax and ignore jsx tags, meaning leave them as is), this is what I'm doing using esformatter
// needed for grunt.file.expand
var grunt = require('grunt');
// use it with care, I haven't check if there
// isn't any side effect from using proxyquire to
// inject esprima-fb into the esformatter
// but this type of dependency replacement
// seems to be very fragile... if rocambole deps change
// this will certainly break, same is true for esformatter
// use it with care
var proxyquire = require('proxyquire');
var rocambole = proxyquire('rocambole', {
'esprima': require('esprima-fb')
});
var esformatter = proxyquire('esformatter', {
rocambole: rocambole
});
// path to your esformatter configuration
var cfg = grunt.file.readJSON('./esformatter.json');
// expand the files from the glob
var files = grunt.file.expand('./js/**/*.jsx');
// do the actual formatting
files.forEach(function (fIn) {
console.log('formatting', fIn);
var output = esformatter.format(grunt.file.read(fIn), cfg);
grunt.file.write(fIn, output);
});
I would actually like that esformatter use a version of rocambole that use esprima-fb instead of esprima, to avoid proxyquire.
There is a setting in the HTML-CSS-JS Prettify plugin that allows you to ignore xml syntax in the js/jsx file. That way it doesn't mess up the jsx code.
The setting is: "e4x": true in the "js" section of the settings file
Preferences > Package Settings > HTML\CSS\JS Prettify > Set Prettify Preferences
This does not work well if you have self closing tags eg. tags ending in />
You can install a JsPrettier package for Sublime 2 & 3. It's a fairly new JavaScript formatter (at the time of writing this: Feb-2017). It supports most of the latest developments like: ES2017, JSX, and Flow.
Quickstart
Install prettier globally using terminal: $ npm install -g prettier
In Sublime go to Tools -> Command Palette... -> Package Control: Install Package, type the word JsPrettier, then select it to complete the installation.
Format your file using context menu inside the editor or bind it to a keyboard shortcut: { "keys": ["super+b"], "command": "js_prettier" }
Links:
https://github.com/jonlabelle/SublimeJsPrettier
https://github.com/jlongster/prettier
To add to what #Shoobah said:
There is a setting in the HTML-CSS-JS Prettify plugin that allows you
to ignore xml syntax in the js/jsx file. That way it doesn't mess up
the jsx code. The setting is: "e4x": true in the "js" section of the
settings file
Go to: Preferences > Package Settings > HTML\CSS\JS Prettify > Set
Prettify Preferences
Go to "js" section:
Add "jsx" to the "allowed_file_extension", and then change "e4x" to "true"
the answer in the internet that always told you set 'e4x' to true,
but sometimes, we have to set option of 'format_on_save_extensions' then add 'jsx' in array
modify jsFormat.sublime-settings
{
"e4x": true,
"format_on_save": true,
"format_on_save_extensions": ["js", "json", "jsx"]
}
Using Sublime's Package Installer, install Babel. Then:
Open a .jsx file.
Select View from the menu,
Then Syntax -> Open all with current extension as... -> Babel -> JavaScript (Babel).
Not specifically for Sublime Text, but there is a beautifier in JavaScript for React JSX.
http://prettydiff.com/?m=beautify claims to support JSX at:
http://prettydiff.com/guide/react_jsx.xhtml

Custom templates with phpDocumentor 2

I've been trying to get a custom template to work with PHPDocumentor (2) without much luck. The documentation on their site is incomplete and I'm kind of stumped.
What I've done is downloaded a copy of a complete template and reference it in my command, like so:
php phpdoc.php
--template=/path/to/customtemplate/
-d /path/to/php/source/files
-t /path/to/generated/content/
The command runs fine: it generates the documentation correctly but appears to be ignoring the --template option - at least, any changes I make to the template files in the /customtemplate folder are ignored.
Anyone have any idea?
(Thanks in advance!)
Ben
Instead of declaring the template command on the CLI you might try changing your phpdoc.dist.xml configuration file so that it pulls the template name or path from there directly.

Gradlew behind a proxy

I have a sample from Gaelyk (called Bloogie) and it is using gradlew.
I am behind a proxy.
I've read gradle docs and found this:
gradle.properties
systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
But I have no clue how to put this info into the wrapper gradlew. Any idea?
All you have to do is to create a file called gradle.properties (with the properties you mentioned above) and place it under your gradle user home directory (which defaults to USER_HOME/.gradle) OR in your project directory.
Gradle (the wrapper too!!!) automatically picks up gradle.properties files if found in the user home directory or project directories.
For more info, read the Gradle user guide, especially at section 12.3: Accessing the web via a proxy
If you need https access behind a proxy, please consider defining also the same set of properties for systemProp.https.
systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
See Can't build Android app using crashlytics behind VPN and proxy for more information.
Add the below in your gradle.properties file and in your gradle/wrapper/gradle-wrapper.properties file if you are downloading the wrapper over a proxy
If you want to set these properties globally then add it in USER_HOME/.gradle/gradle.properties file
## Proxy setup
systemProp.proxySet=true
systemProp.http.keepAlive=true
systemProp.http.proxyHost=host
systemProp.http.proxyPort=port
systemProp.http.proxyUser=username
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=local.net|some.host.com
systemProp.https.keepAlive=true
systemProp.https.proxyHost=host
systemProp.https.proxyPort=port
systemProp.https.proxyUser=username
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=local.net|some.host.com
## end of proxy setup
Use this in prompt line:
gradle -Dhttp.proxyHost=*** -Dhttp.proxyPort=*** -Dhttp.proxyUser=**** -Dhttp.proxyPassword=****
Works here!
I could not get the proxy property to work until I set the https proxy:
systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
However I had to use the http property for user name and password:
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
This problem with the Gradle Wrapper has been fixed with Gradle 1.0-milestone-8. Give it a shot.
after of this JDK update, I couldn't use gradlew behind a proxy again.
and finally I found a JDK has disabled Basic authentication for HTTPS tunneling by default.
so I have to add this property for gradle.properties in addition to proxy settings
systemProp.jdk.http.auth.tunneling.disabledSchemes=""
I hope it would be helpful for someone who struggle same problem
To add more nuances, for my case, when I have multiple gradle.properties files in both USER_HOME/.gradle and the project root, I encountered the authenticationrequired 407 error, with the bellow log: CONNECT refused by proxy: HTTP/1.1 407 authenticationrequired
This caused my systemProp.https.proxyPassword and systemProp.http.proxyPasswordblank in the gradle.properties file under USER_HOME/.gradle, while the gradle.properties file under the project root remained password info. Not sure the exact reason, But when I remove one gradle.properties in the project root and keep the file in the USER_HOME/.gradle, my case is resolved.
I had same problem and first thing I did was to create gradle.properties. I had not such as file so I should create it with following content:
systemProp.http.proxyHost=proxy
systemProp.http.proxyPort=port
systemProp.http.nonProxyHosts=domainname|localhost
systemProp.https.proxyHost=proxy
systemProp.https.proxyPort=port
systemProp.https.nonProxyHosts=domainname|localhost
When I added them gradlew command works properly behind corporate proxy. I hope that it can be useful.
I was found that reading of properties from gradle.properties can be incorrect. In case line contains trail white space, gradle cannot find proxy. check your proxy file and cut whitespace at the end of line. Can be help
This was not working for me at first.
In my case, I had created what I thought was a USER_HOME/.gradle/gradle.properties file but ended up with a gradle.properties.txt file.
From the terminal window an ls command will show the full file names in the .gradle folder.
Then mv gradle.properties.txt gradle.properties
I have the same proxy issue while working with Cordova project.
To fix the issue, I have created a new gradle.properties file under the android folder of my Cordova project (hello/platforms/android), and added the code from your question
systemProp.http.proxyHost=proxy.yourproxysite.com
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=yourusername
systemProp.http.proxyPassword=password
Setting SSl proxy worked for me.
systemProp.http.proxyHost=proxy.yourproxysite.com
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=proxy.yourproxysite.com
systemProp.https.proxyPort=8080
An excerpted answer from the linked thread below. It shows how to do
this more programtically. Hope it helps
task setHttpProxyFromEnv {
def map = ['HTTP_PROXY': 'http', 'HTTPS_PROXY': 'https']
for (e in System.getenv()) {
def key = e.key.toUpperCase()
if (key in map) {
def base = map[key]
//Get proxyHost,port, username, and password from http system properties
// in the format http://username:password#proxyhost:proxyport
def (val1,val2) = e.value.tokenize( '#' )
def (val3,val4) = val1.tokenize( '//' )
def(userName, password) = val4.tokenize(':')
def url = e.value.toURL()
//println " - systemProp.${base}.proxy=${url.host}:${url.port}"
System.setProperty("${base}.proxyHost", url.host.toString())
System.setProperty("${base}.proxyPort", url.port.toString())
System.setProperty("${base}.proxyUser", userName.toString())
System.setProperty("${base}.proxyPassword", password.toString())
}
}
}
See this thread for more
After lots of struggling with this and banging my head against a wall, because nothing on my system was using a proxy: it turned out that my ** Android Emulator instance ** itself was secretly/silently setting a proxy for me via Android Emulator > Settings > Proxy and had applied these settings when playing around with it weeks earlier in order to troubleshoot an issue with Expo.
If anyone is having this issue, make sure you check 100% to see if indeed no custom proxy settings are being used via: ./gradlew installDebug --info --debug --stacktrace and searching for proxyHost in the log output to make sure of this. It may be your emulator.
The following applies when your gradle archive is mirrored behind the firewall (like mine..):
For some reason, I needed both of these lines:
gradle.properties:
systemProp.http.nonProxyHosts=*.localserver.co
systemProp.https.nonProxyHosts=*.localserver.co
EVEN though my download line started with https, such as below:
gradle-wrapper.properties:
distributionUrl=https\://s.localserver.co/gradle-7.0.1-bin.zip
It wasn't working in ANY other way... except only it worked if I used export JAVA_OPTS=-Dhttp.nonProxyHosts=localserver.co|etc.
Even though my environment variable no_proxy was already correctly set, it wasn't working without the two values in the above properties.
systemProp.http.proxyUser=userId
systemProp.http.proxyPassword=password
same with https......

Resources