diff --git a/apis/collection/schema.js b/apis/collection/schema.js index 0cc25c0d97..9e51e55ada 100644 --- a/apis/collection/schema.js +++ b/apis/collection/schema.js @@ -25,6 +25,7 @@ Apis.schema = new SimpleSchema({ type: String, optional: true }, + apiLogoFileId: { type: String, optional: true @@ -34,6 +35,10 @@ Apis.schema = new SimpleSchema({ optional: true, regEx: SimpleSchema.RegEx.Url }, + submit_methods: { + type: [String], + optional: true + }, created_at: { type: Date, optional: true @@ -88,4 +93,7 @@ Apis.schema = new SimpleSchema({ } }); +// Enable translations (i18n) +Apis.schema.i18n('schemas.apis'); + Apis.attachSchema(Apis.schema); diff --git a/documentation/client/codegenerator/codegenerator.js b/documentation/client/codegenerator/codegenerator.js index 1d6c9099fd..1f6dab1aa4 100644 --- a/documentation/client/codegenerator/codegenerator.js +++ b/documentation/client/codegenerator/codegenerator.js @@ -14,7 +14,7 @@ Template.sdkCodeGeneratorModal.onCreated(function () { instance.dataReady = new ReactiveVar(false); // Get documentation file id - const documentationFileId = instance.data.apiBackend.documentationFileId; + const documentationFileId = instance.data.api.documentationFileId; // Save documentation file URL instance.documentationFileURL = Meteor.absoluteUrl().slice(0, -1) + DocumentationFiles.baseURL + '/id/' + documentationFileId; diff --git a/documentation/client/manage/autoform.js b/documentation/client/manage/autoform.js index d0b3b69df5..f54d9531d4 100644 --- a/documentation/client/manage/autoform.js +++ b/documentation/client/manage/autoform.js @@ -1,5 +1,11 @@ -AutoForm.addHooks(['apiDocumentationForm'], { - onSuccess () { - sAlert.success(TAPi18n.__('manageApiDocumentationModal_LinkField_Updated_Message')); - }, -}); +AutoForm.hooks({ + apiDocumentationForm: { + onSuccess () { + // Get success message translation + const message = TAPi18n.__('manageApiDocumentationModal_LinkField_Updated_Message'); + + // Alert user of success + sAlert.success(message); + }, + } +}); \ No newline at end of file diff --git a/documentation/client/manage/manage.html b/documentation/client/manage/manage.html index 2a7c2a0eaf..6bc88cb32c 100644 --- a/documentation/client/manage/manage.html +++ b/documentation/client/manage/manage.html @@ -9,48 +9,56 @@

{{_ "manageApiDocumentationModal_Title" }}

diff --git a/documentation/client/manage/manage.js b/documentation/client/manage/manage.js index 5f61286970..6270093bd3 100644 --- a/documentation/client/manage/manage.js +++ b/documentation/client/manage/manage.js @@ -4,7 +4,7 @@ import { Settings } from '/settings/collection'; Template.manageApiDocumentationModal.onCreated(function () { const instance = this; - + // Initialize help texts const helpTexts = { 'documentation_link': { @@ -27,13 +27,13 @@ Template.manageApiDocumentationModal.onCreated(function () { }, }; InlineHelp.initHelp(helpTexts); - + instance.autorun(function () { const api = Apis.findOne(instance.data.api._id); // Save apibackend id Session.set('api', api); }); - + // Subscribe to documentation editor settings instance.subscribe('singleSetting', 'apiDocumentationEditor'); }); @@ -47,21 +47,21 @@ Template.manageApiDocumentationModal.events({ 'click .delete-documentation': function (event, instance) { // Show confirmation dialog to user const confirmation = confirm(TAPi18n.__('manageApiDocumentationModal_DeletedFile_ConfirmationMessage')); - + // Check if user clicked "OK" if (confirmation === true) { // Get currentApiBackend documentationFileId const documentationFileId = this.api.documentationFileId; - + // Convert to Mongo ObjectID const objectId = new Mongo.Collection.ObjectID(documentationFileId); - + // Remove documentation object DocumentationFiles.remove(objectId); - + // Remove documenation file id field Apis.update(instance.data.api._id, { $unset: { documentationFileId: '' } }); - + sAlert.success(TAPi18n.__('manageApiDocumentationModal_DeletedFile_Message')); } }, @@ -79,15 +79,15 @@ Template.manageApiDocumentationModal.events({ Template.manageApiDocumentationModal.helpers({ documentationFile () { const api = Session.get('api'); - + const documentationFileId = api.documentationFileId; - + // Convert to Mongo ObjectID const objectId = new Mongo.Collection.ObjectID(documentationFileId); - + // Get documentation file Object const documentationFile = DocumentationFiles.findOne(objectId); - + // Check if documentation file is available if (documentationFile) { return documentationFile; @@ -96,9 +96,13 @@ Template.manageApiDocumentationModal.helpers({ apiDocumentationEditorIsEnabled () { // Get settings const settings = Settings.findOne(); - + // Check settings exists, editor is enabled and host setting exists - if (settings && settings.apiDocumentationEditor.enabled && settings.apiDocumentationEditor.host) { + if ( + settings && + settings.apiDocumentationEditor && + settings.apiDocumentationEditor.enabled && + settings.apiDocumentationEditor.host) { // Editor is enabled and has host setting, return true return true; } else { @@ -110,4 +114,14 @@ Template.manageApiDocumentationModal.helpers({ // Return a reference to Apis collection, for AutoForm return Apis; }, + // Return list of all try-out methods, which is used in Swagger Options + supportedSubmitMethods () { + return [ + {label: 'GET', value: 'get'}, + {label: 'POST', value: 'post'}, + {label: 'DELETE', value: 'delete'}, + {label: 'PATCH', value: 'patch'}, + {label: 'PUT', value: 'put'} + ] + }, }); diff --git a/documentation/client/manage/uploadButton/uploadButton.html b/documentation/client/manage/uploadButton/uploadButton.html index 3f6a5d63f5..4a7fefe572 100644 --- a/documentation/client/manage/uploadButton/uploadButton.html +++ b/documentation/client/manage/uploadButton/uploadButton.html @@ -1,3 +1,5 @@ diff --git a/documentation/client/manage/uploadButton/uploadButton.js b/documentation/client/manage/uploadButton/uploadButton.js index e4a9e03ac2..d192d2a8c2 100644 --- a/documentation/client/manage/uploadButton/uploadButton.js +++ b/documentation/client/manage/uploadButton/uploadButton.js @@ -2,5 +2,5 @@ import { DocumentationFiles } from '/documentation/collection/collection'; Template.manageApiDocumentationModalUploadButton.onRendered(function() { // Assign resumable browse to element - DocumentationFiles.resumable.assignBrowse($('.fileBrowse')); + DocumentationFiles.resumable.assignBrowse($('#file-browse')); }); diff --git a/documentation/client/swaggerUI/swaggerUi.html b/documentation/client/swaggerUI/swaggerUi.html index a28e459613..ad563004df 100644 --- a/documentation/client/swaggerUI/swaggerUi.html +++ b/documentation/client/swaggerUI/swaggerUi.html @@ -1,29 +1,29 @@ \ No newline at end of file diff --git a/documentation/client/swaggerUI/swaggerUi.js b/documentation/client/swaggerUI/swaggerUi.js index 2d2f6c639f..fae6ed8022 100644 --- a/documentation/client/swaggerUI/swaggerUi.js +++ b/documentation/client/swaggerUI/swaggerUi.js @@ -5,10 +5,10 @@ Template.swaggerUi.onCreated(function () { const instance = Template.instance(); // Set flag on Data is not Ready instance.dataFetched = new ReactiveVar(false); - + // Get url of api documentation - const documentationURL = instance.data.apiDocumentation; - + const documentationURL = instance.data.apiDoc; + // Check validation of Swagger file Meteor.call('isValidSwagger', documentationURL, function (error, result) { // result can be 'true' or '{}' diff --git a/documentation/client/swaggerUI/swaggerUiContent/swaggerUiContent.html b/documentation/client/swaggerUI/swaggerUiContent/swaggerUiContent.html index b0a885cf57..16075e9933 100644 --- a/documentation/client/swaggerUI/swaggerUiContent/swaggerUiContent.html +++ b/documentation/client/swaggerUI/swaggerUiContent/swaggerUiContent.html @@ -1,3 +1,3 @@ \ No newline at end of file diff --git a/documentation/client/swaggerUI/swaggerUiContent/swaggerUiContent.js b/documentation/client/swaggerUI/swaggerUiContent/swaggerUiContent.js index 1b70d82493..b6f86f0f87 100644 --- a/documentation/client/swaggerUI/swaggerUiContent/swaggerUiContent.js +++ b/documentation/client/swaggerUI/swaggerUiContent/swaggerUiContent.js @@ -1,29 +1,35 @@ import SwaggerUi from 'swagger-ui-browserify'; +import { Apis } from '/apis/collection'; Template.swaggerUiContent.onCreated(function () { + const instance = this; + // Get URL of api documentation - const documentationURL = this.data.apiDocumentation; - - // Create Swagger UI - const swagger = window.swaggerUi = new SwaggerUi({ + const documentationURL = this.data.apiDoc; + + // Create Swagger UI object + const swagger = new SwaggerUi({ url: documentationURL, dom_id: 'swagger-ui-container', useJQuery: true, supportHeaderParams: true, - supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'], apisSorter: 'alpha', operationsSorter: 'alpha', - docExpansion: 'none' + docExpansion: 'none', + }); + + // Subscribe to api collection + instance.autorun(() => { + // Get relevant api collection + instance.subscribe('apiBackend', instance.data.api._id); + + // Get api + const api = Apis.findOne(instance.data.api._id); + + // Set selected methods in Swagger + swagger.setOption('supportedSubmitMethods', api.submit_methods); + + // Load Swagger UI + swagger.load(); }); - - // Load Swagger UI - swagger.load(); -}); - -Template.swaggerUiContent.onRendered(function () { - // Get URL of api documentation - const documentationURL = this.data.apiDocumentation; - - // Display URL on Swagger UI input - $('#input_baseUrl').val(documentationURL); }); diff --git a/documentation/client/view/documentation.html b/documentation/client/view/documentation.html index 2344becf5f..b8bccbc15d 100644 --- a/documentation/client/view/documentation.html +++ b/documentation/client/view/documentation.html @@ -41,7 +41,7 @@

{{_ "documentation_Link_Title" }}

{{else}} {{_ "documentation_No_Link_Message" }} - {{#if apiBackend.currentUserCanEdit }} + {{#if api.currentUserCanEdit }} {{_ "documentation_No_Link_Manager_Message" }} {{/if}} @@ -66,11 +66,11 @@

{{_ "documentation_Viewer_Title" }}

{{#if Template.subscriptionsReady }} {{#if documentationExists }} - {{> swaggerUi apiDocumentation=uploadedDocumentationLink}} + {{> swaggerUi apiDoc=uploadedDocumentationLink api=api}} {{ else }} {{_ "documentation_No_Swagger_Message" }} - {{#if apiBackend.currentUserCanEdit }} + {{#if api.currentUserCanEdit }} {{_ "documentation_No_Swagger_Manager_Message" }} {{/if}} diff --git a/lib/i18n/en.i18n.json b/lib/i18n/en.i18n.json index f0c6b238bf..c72759b15d 100644 --- a/lib/i18n/en.i18n.json +++ b/lib/i18n/en.i18n.json @@ -295,6 +295,11 @@ "responseTimeDistributionChart_title": "API Response Time", "responseTimeDistributionChart_help_text": "Click on any bar to filter API Request Timeline and HTTP Status Code chart by requests that have the selected response time range.", "schemas": { + "apis": { + "submit_methods": { + "label": "Allow try-out for following methods:" + } + }, "apiMetadata": { "organization": { "label": "Organization", diff --git a/package.json b/package.json index b80793cfac..35f8e7c444 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "swagger-client": "^2.1.0", "swagger-parser": "^3.4.1", "swagger-ui": "^2.2.3", - "swagger-ui-browserify": "^2.2.3", + "swagger-ui-browserify": "^2.2.3-a", "urijs": "^1.18.1" }, "devDependencies": {