-
Notifications
You must be signed in to change notification settings - Fork 33
Integrate sdk generator #1429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate sdk generator #1429
Changes from 7 commits
ee4b180
6e26cbd
87c5d3e
09bebbd
53519b3
7051793
c415cf9
b2c8c74
0a46ef8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { HTTP } from 'meteor/http'; | ||
|
|
||
| AutoForm.addHooks('downloadSDK', { | ||
| onSubmit: function (formValues, updateDoc, instance) { | ||
| // Prevent form from submitting | ||
| this.event.preventDefault(); | ||
|
|
||
| // Get selected language from dropdown list | ||
| const selectedLanguage = formValues.selectLanguage; | ||
|
|
||
| // Get index of selected language in global list of languages | ||
| const index = _.indexOf(instance.languageList, selectedLanguage); | ||
|
|
||
| // Find mask of the language for url | ||
| const parameter = instance.urlParameters[index]; | ||
|
|
||
| const host = 'https://generator.swagger.io'; | ||
|
|
||
| // Create URL to send request | ||
| const url = host + '/api/gen/clients/' + parameter; | ||
|
|
||
| // Get path to documentation file | ||
| const pathToFile = instance.documentationFileURL; | ||
|
|
||
| // Create POST options | ||
| const options = { | ||
| 'swaggerUrl': pathToFile | ||
| }; | ||
|
|
||
| // Start spinner when send request | ||
| instance.callRequest.set(true); | ||
|
|
||
| // Send POST request | ||
| HTTP.post(url, { data: options }, function (error, result) { | ||
| // Get information from Swagger API response | ||
| let response = JSON.parse(result.content); | ||
|
|
||
| if (result.statusCode === 200) { | ||
| // Hide modal | ||
| Modal.hide('sdkCodeGeneratorModal'); | ||
|
|
||
| // Go to link and download file | ||
| window.location.href = response.link; | ||
| } else { | ||
| $('button').removeAttr('disabled'); | ||
|
|
||
| // Otherwise show an error message | ||
| FlashMessages.sendError(TAPi18n.__('sdkCodeGeneratorModal_errorText')); | ||
| } | ||
| // Finish spinner | ||
| instance.callRequest.set(false); | ||
| }); | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <template name="sdkCodeGeneratorModal"> | ||
| <div class="modal fade"> | ||
| <div class="modal-dialog" role="document"> | ||
| <div class="modal-content"> | ||
| <div class="modal-header"> | ||
| <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
| <span aria-hidden="true">×</span> | ||
| </button> | ||
| <h1 class="modal-title"> | ||
| {{_ "sdkCodeGeneratorModal_Title" }} | ||
| </h1> | ||
| </div> | ||
| <div class="modal-body"> | ||
| {{#if dataFetched}} | ||
|
|
||
| {{> quickForm | ||
| id="downloadSDK" | ||
| schema=generateSDK | ||
| doc=getTemplateInstance | ||
| buttonContent="Download" }} | ||
|
|
||
| {{else}} | ||
| {{> spinner}} | ||
| {{/if}} | ||
|
|
||
| {{#if statusRequest}} | ||
| {{> spinner}} | ||
| {{/if}} | ||
| </div> | ||
| {{> flashMessages}} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </template> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { Template } from 'meteor/templating'; | ||
| import { ReactiveVar } from 'meteor/reactive-var'; | ||
| import { Session } from 'meteor/session'; | ||
|
|
||
| import _ from 'lodash'; | ||
|
|
||
| import { DocumentationFiles, languageHashName } from '/documentation/collection/collection'; | ||
|
|
||
| Template.sdkCodeGeneratorModal.onCreated(function () { | ||
| const instance = this; | ||
|
|
||
| instance.callRequest = new ReactiveVar(false); | ||
| instance.dataReady = new ReactiveVar(false); | ||
|
|
||
| // Get documentation file id | ||
| const documentationFileId = instance.data.apiBackend.documentationFileId; | ||
|
|
||
| // Get documentation file URL | ||
| const documentationFileURL = Meteor.absoluteUrl().slice(0, -1) + DocumentationFiles.baseURL + '/id/' + documentationFileId; | ||
|
|
||
| // Save documentation file URL | ||
| instance.documentationFileURL = documentationFileURL; | ||
|
|
||
| /* Get list of an available languages from Codegen server */ | ||
|
|
||
| // Codegen server url | ||
| const url = 'https://generator.swagger.io/api/gen/clients'; | ||
|
|
||
| // Call GET request | ||
| HTTP.get(url, {}, function (error, result) { | ||
| // Get information from Swagger API response | ||
| const response = JSON.parse(result.content); | ||
|
|
||
| // Save response to use it like url parameter in POST request | ||
| instance.urlParameters = response; | ||
|
|
||
| // Create list of friendly language names | ||
| instance.languageList = []; | ||
|
|
||
| _.forEach(response, function (language) { | ||
| // Check on specific name | ||
| let newLanguageName = languageHashName[language]; | ||
|
|
||
| // Convert name by standard method if it isn't specific name | ||
| if (_.isUndefined(newLanguageName)) { | ||
| // Split the name into words, ex. 'akka-scala' -> 'akka','scala' | ||
| let newLanguageList = language.split('-'); | ||
| // Do the capital letter for each word | ||
| newLanguageList = _.map(newLanguageList, function (word) { return _.capitalize(word); }); | ||
| // Join this list to string using space | ||
| newLanguageName = newLanguageList.join(' '); | ||
| } | ||
| // Add new name to list of languages which show to user | ||
| instance.languageList.push(newLanguageName); | ||
|
|
||
| // Finish spinner | ||
| instance.dataReady.set(true); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| Template.sdkCodeGeneratorModal.helpers({ | ||
| // Schema for SDK Code Generator form | ||
| generateSDK () { | ||
| // Get reference to template instance | ||
| const instance = Template.instance(); | ||
|
|
||
| // Create simple schema for sdk modal | ||
| const sdkSchema = new SimpleSchema({ | ||
| selectLanguage: { | ||
| type: String, | ||
| allowedValues: instance.languageList, | ||
| autoform: { | ||
| afFieldInput: { | ||
| firstOption: '(Language)' | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| return sdkSchema; | ||
| }, | ||
| // Check on ready of data from call GET request | ||
| dataFetched () { | ||
| // Get reference to template instance | ||
| const instance = Template.instance(); | ||
|
|
||
| return instance.dataReady.get(); | ||
| }, | ||
| // Give variable callRequest to template | ||
| statusRequest () { | ||
| // Get reference to template instance | ||
| const instance = Template.instance(); | ||
|
|
||
| return instance.callRequest.get(); | ||
| }, | ||
| // From template AutoForm we don't have access to instance of this template | ||
| // getTemplateInstance return object that containts the necessary varaibles | ||
| getTemplateInstance () { | ||
| // Get reference to template instance | ||
| const instance = Template.instance(); | ||
|
|
||
| // Create object with instance varaibles | ||
| const dataToAutoform = { | ||
| 'apiBackend': instance.data.apiBackend, | ||
| 'callRequest': instance.callRequest, | ||
| 'documentationFileURL': instance.documentationFileURL, | ||
| 'languageList': instance.languageList, | ||
| 'urlParameters': instance.urlParameters | ||
| }; | ||
|
|
||
| return dataToAutoform; | ||
| } | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ const DocumentationFiles = new FileCollection('DocumentationFiles', { | |
| { | ||
| method: 'get', | ||
| path: '/id/:_id', | ||
| lookup: function(params, query) { | ||
| lookup: function (params, query) { | ||
| return { | ||
| _id: params._id | ||
| }; | ||
|
|
@@ -14,4 +14,21 @@ const DocumentationFiles = new FileCollection('DocumentationFiles', { | |
| ] | ||
| }); | ||
|
|
||
| export { DocumentationFiles }; | ||
| // The most part of list items can convert to user friendly name by standard method | ||
| // The method is to replace dash on space and to do the capital letter of each word | ||
| // Some language names can't be convert by standard method. | ||
| // Variable 'languageHashName' keeps specific names | ||
| const languageHashName = { | ||
|
||
| 'dynamic-html': 'Dynamic HTML', | ||
| 'csharp': 'C#', | ||
| 'CsharpDotNet2': 'C# .NET 2.0', | ||
| 'html': 'HTML', | ||
| 'objc': 'Objective-C', | ||
| 'php': 'PHP', | ||
| 'qt5cpp': 'Qt 5 C++', | ||
| 'swagger': 'Swagger JSON', | ||
| 'swagger-yaml': 'Swagger YAML' | ||
| }; | ||
|
|
||
| export { DocumentationFiles, languageHashName }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,3 +12,7 @@ iframe { | |
| .s-alert-box { | ||
| z-index: 10000 | ||
| } | ||
|
|
||
| button#sdk-code-generator { | ||
| margin-right: 1em | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brylie File codegenerator.js
If I do import the variables 'LanguagesList' and 'LanguageParams' from collection.js, this variables wil be undefined.