Currently using swagger 2.1.4 i want to upgrade 3.0.10
When reporting an issue, please provide the following details:
- swagger-ui version --2.1.4 upgrade version -3.0.10
Can any one explain steps how to upgrade swagger 2.1.4 to 3.0..
Currently using like below
import { Injectable, Component, ViewChild, Inject } from '@angular/core'; import { Http, HttpModule, Headers, ConnectionBackend } from '@angular/http';
declare var $: any; declare var angular: any; declare var window: any; //@Inject(Window) private window: Window declare var generateDoc: any; declare var _errorContainer: any; declare var _scope: any; declare var UserInfo: any; declare var CSRFToken: any; declare var SITEROOT: any; declare var SwaggerClient: any; declare var SwaggerUi: any;
@Injectable() export class SwaggerDoc { static ionAPI: any; static hhtp: any; public _completionCB: any; static _selfchild: any;
constructor(public _http: Http) {
//IMP.http = this._http;
SwaggerDoc.hhtp = this._http;
SwaggerDoc._selfchild = this;
}
_self = {
/*
Parameters:
- domIdToAttachTo: id of a dom element serving as outer container for swagger ui
- docInfo: { DocumentUrl: xxx', Token: authenticationToken},
- completionCB: function to call when completed or error
*/
//generateDoc: SwaggerDoc,
generateDoc: this._generateDoc,
ensureSwaggerUICreated: this.ensureSwaggerUICreated,
setAuthenticationToken: this.setAuthenticationToken,
handleFailure: this.handleFailure,
_completionCB: this._completionCB,
}
ensureSwaggerUICreated(containerDomId) {
if (window.swaggerUi) {
window.swaggerUi.dom_id = containerDomId;
return window.swaggerUi;
}
//ok, create UI once, along with static options
var options = {
dom_id: containerDomId,
validatorUrl: null,
supportHeaderParams: true,
supportedSubmitMethods: ['get', 'post', 'put'],
docExpansion: "list",
//good
onComplete: function (resourceDoc, viewObj) {
SwaggerDoc._selfchild.handleComplete(resourceDoc, viewObj);
},
//bad
onFailure: function (data) {
SwaggerDoc._selfchild.handleFailure(data);
}
};
//initialize once
window.swaggerUi = new SwaggerUi(options);
window.swaggerUi.api = new SwaggerClient();
return window.swaggerUi;
}
_generateDoc(containerDomId, docInfo, completionCB) {
//sanity check
var CB = angular.isFunction(completionCB) ? completionCB : angular.noop;
if (!containerDomId || !docInfo || !docInfo.Token || !docInfo.DocumentationUrl)
return CB(false);
//ok, proceed
SwaggerDoc._selfchild._completionCB = CB;
var ui = this.ensureSwaggerUICreated(containerDomId);
this.setAuthenticationToken(ui, docInfo.Token);
var data = { url: docInfo.DocumentationUrl };
ui.updateSwaggerUi(data); //set new doc url to trigger doc loading
//ui.specActions.updateSpec(string);
}
handleComplete(resourceDoc, viewObj) {
SwaggerDoc._selfchild._completionCB(true, resourceDoc, viewObj);
}
setAuthenticationToken(swagUI, token) {
var auth1 = new SwaggerClient.ApiKeyAuthorization("x-ionapi-docrequest", "SWAGGER", "header");
swagUI.api.clientAuthorizations.add("x-ionapi-docrequest", auth1);
var auth2 = new SwaggerClient.ApiKeyAuthorization("Authorization", "Bearer " + token, "header");
swagUI.api.clientAuthorizations.add("Authorization", auth2);
}
//build swagger error object then expose it to the uiContainer object
handleFailure(data) {
try {
//capture error object from embedded string
var first = data.indexOf("{");
var last = data.lastIndexOf("}");
var errorString = data.substring(first, last + 1);
var errorObj = JSON.parse(errorString);
//source url causing the error
errorObj.url = data.substr(last + 1);
errorObj.httpErrorCode = parseInt(data);
//We should now have these components to show on the dialog
/*
errorObj.httpError;
errorObj.error.message;
errorObj.error.code;
errorObj.source;
errorObj.url = url;
*/
SwaggerDoc._selfchild._completionCB(false, errorObj);
} catch (ex) {
SwaggerDoc._selfchild._completionCB(false);
throw data; //hmm, best we can do, caller must catch it
}
} }
// html
H @siddamreddy, can you segment the code you're providing? The inconsistent code blocks and scattered HTML is pretty confusing.
We don't currently have any migration docs, but you can see how we're using the new version here.
Does it would not require swagger-ui-container here.
@siddamreddy, from the code you provided, it's not clear how you're getting Swagger-UI in the first place.
You're interacting with it via window.swaggerUi, which means you probably loaded it via a <script> tag, but there's not one that I can see in your snippet.
A good place to start would be to:
- get a copy of the latest swagger-ui (via github, npm, or packagist)
- include
swagger-ui-bundle.json your page - change references of
window.swaggerUitowindow.SwaggerUIBundle
Let me know where that gets you. Thanks for using Swagger!
Closing due to inactivity - feel free to comment if there are any further thoughts or concerns, and we'll be happy to reopen this issue.