Skip to content

Instantly share code, notes, and snippets.

View ponelat's full-sized avatar

Josh Ponelat ponelat

View GitHub Profile
@ponelat
ponelat / spec.json
Last active August 29, 2015 14:19
Simple,complete spec relating to swagger-ui#1133
{
"swagger": "2.0",
"host": "petstore.swagger.wordnik.com",
"info": {
"title": "Test Spec",
"version": "1.0.0"
},
"paths": {
"/road": {
"get": {
@ponelat
ponelat / external_and_rel_refs.json
Last active August 29, 2015 14:20
External $ref in path
{
"swagger": "2.0",
"basePath": "http://localhost:3000/s/",
"host": "petstore.swagger.wordnik.com",
"info": {
"title": "swagger-ui#1234",
"title": "Describe your issue here",
"version": "1.0.0"
},
"paths": {
{
"swagger": "2.0",
"host": "petstore.swagger.wordnik.com",
"info": {
"title": "swagger-ui#1234",
"title": "Describe your issue here",
"version": "1.0.0"
},
"paths": {
"/road": {
var client = require('swagger-client');
var swagger = new client({
url: 'http://petstore.swagger.io/v2/swagger.json',
success: function() {
swagger.apis.pet.getPetById({petId:10},function(pet){
console.log('pet', pet);
});
@ponelat
ponelat / index.html
Created May 3, 2015 10:20
Basic sending of an api_key
<script src='browser/swagger-client.js' type='text/javascript'></script>
<script type="text/javascript">
// initialize swagger, point to a resource listing
window.swagger = new SwaggerClient({
url: "http://petstore.swagger.io/api/api-docs",
success: function() {
// This will add a query parameter called api_key with the value 'special-key'
this.clientAuthorizations.add("api_key", new client.ApiKeyAuthorization("api_key","special-key","query"));
@ponelat
ponelat / index.html
Last active November 8, 2022 05:11
Select Box Url Swagger-UI
<!DOCTYPE html>
<html>
<head>
<title>Swagger UI</title>
<link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" />
<link href='css/typography.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
@ponelat
ponelat / basic_auth.js
Last active July 19, 2017 20:28
Swagger-UI: Custom auth function
// This can only get called from within the success handler, as we need swagger-client to be instantiated.
function addApiKeyAuthorization(){
var key = encodeURIComponent($('#input_apiKey')[0].value);
if(key && key.trim() != "") {
var someAweseomAuth = new SwaggerClient.PasswordAuthorization("yourAuthName", "some user", "some password");
window.swaggerUi.api.clientAuthorizations.add("yourAuthName", someAweseomAuth);
}
}
@ponelat
ponelat / send_a_cookie_swagger-ui_index.js
Last active August 29, 2015 14:22
Send Cookies with CORs (client side only)
@ponelat
ponelat / index.html
Created June 11, 2015 13:27
Ron's double Swagger-UI
<!DOCTYPE html>
<html>
<head>
<title>Swagger UI</title>
<link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" />
<link href='css/typography.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
@ponelat
ponelat / inline_spec_for_index.html.js
Last active August 29, 2015 14:22
Inline your swagger spec into swagger-ui's index.html file
// This goes in the dist/index.html file found in swagger-ui.
// Be careful that the file gets overwritten when you build swagger-ui
window.swaggerUi = new SwaggerUi({
url: url,
spec: {
// ...
// your spec here
// ....
},