Skip to content

Commit

Permalink
Disable generating codes from swagger codegen.
Browse files Browse the repository at this point in the history
  • Loading branch information
lqtian committed Nov 2, 2016
1 parent 28a809f commit f797650
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
1 change: 1 addition & 0 deletions scripts/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ require('scripts/controllers/importurl.js');
require('scripts/controllers/main.js');
require('scripts/controllers/modal.js');
require('scripts/controllers/openexamples.js');
require('scripts/controllers/CrossOriginPromptCtrl.js');
require('scripts/controllers/paste-json.js');
require('scripts/controllers/preferences.js');
require('scripts/controllers/preview.js');
Expand Down
31 changes: 31 additions & 0 deletions scripts/controllers/CrossOriginPromptCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';


SwaggerEditor.controller('CrossOriginPromptCtrl', function CrossOriginPromptCtrl($scope,
$uibModalInstance, $rootScope, simpleYaml,YAML) {
YAML.dump(simpleYaml.swagger, function(error, result){
var yamlBlob = new Blob([result], {type: 'text/plain'});
$scope.yamlDownloadHref = window.URL.createObjectURL(yamlBlob);
$scope.yamlDownloadUrl = [
'text/plain',
'swagger.yaml',
$scope.yamlDownloadHref
].join(':');

if(error) {$scope.swaggerSpec = "Error"; return;}
{$scope.swaggerSpec = result; return;}
});

$scope.copy=function(){
var copyTextarea = document.querySelector('#prompt-swaggerspec');
copyTextarea.select();

try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
};
});
13 changes: 4 additions & 9 deletions scripts/controllers/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

SwaggerEditor.controller('HeaderCtrl', function HeaderCtrl($scope, $uibModal,
$stateParams, $state, $rootScope, Storage, Builder, FileLoader, Editor,
Codegen, Preferences, YAML, defaults, strings, $localStorage) {
Codegen, Preferences, YAML, defaults, strings, $localStorage, simpleYaml) {
if ($stateParams.path) {
$scope.breadcrumbs = [{active: true, name: $stateParams.path}];
} else {
Expand Down Expand Up @@ -53,6 +53,8 @@ SwaggerEditor.controller('HeaderCtrl', function HeaderCtrl($scope, $uibModal,
});
}

$scope.swaggerSpec='';

$scope.getSDK = function(type, language) {
if(!!Preferences.get('simpleYAML') && language === 'csharp')
{
Expand All @@ -62,14 +64,7 @@ SwaggerEditor.controller('HeaderCtrl', function HeaderCtrl($scope, $uibModal,
$uibModal.open({
template: require('templates/cross-origin-prompt.html'),
size: 'large',
controller: function CrossOriginPromptCtrl($scope,
$uibModalInstance, $rootScope) {
$scope.ok = function() {
$uibModalInstance.close();
Codegen.getSDK(type, language).then(noop, showCodegenError);
};
$scope.cancel = $uibModalInstance.close;
}
controller: 'CrossOriginPromptCtrl'
});
};

Expand Down
11 changes: 6 additions & 5 deletions templates/cross-origin-prompt.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ <h3 class="modal-title">Prompt</h3>
</div>
<div class="modal-body">
<div class="form-group">
<label>We will send a document, which includes the data you input, to http://generator.swagger.io to generate codes. <br><br>
The generation service belongs to SmartBear, you can checkout its Privacy Stagement <a href = "https://smartbear.com/privacy/">here</a>.
<br><br>Do you want to proceed?</label>
<label>Currently only C# is supported, however, you can generate other languages in <a target="_blank" href = "http://editor.swagger.io/">Swagger Service</a> by yourself with the following spec:<br><br>
<textarea id="prompt-swaggerspec" class="form-control" cols="30" rows="10" readonly>{{swaggerSpec}}</textarea>
<br><br>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
<button class="btn btn-primary" ng-click="ok()">OK</button>
<button class="btn btn-warning" ng-click="copy()">Copy Spec</button>
<a class="btn btn-primary" download="swagger.yaml" data-downloadurl="{{yamlDownloadUrl}}"
href="{{yamlDownloadHref}}" tabindex="-1"><span>Download Spec</span></a>
</div>

0 comments on commit f797650

Please sign in to comment.