Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apis/collection/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Apis.schema = new SimpleSchema({
type: String,
optional: true
},

apiLogoFileId: {
type: String,
optional: true
Expand All @@ -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
Expand Down Expand Up @@ -88,4 +93,7 @@ Apis.schema = new SimpleSchema({
}
});

// Enable translations (i18n)
Apis.schema.i18n('schemas.apis');

Apis.attachSchema(Apis.schema);
2 changes: 1 addition & 1 deletion documentation/client/codegenerator/codegenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 11 additions & 5 deletions documentation/client/manage/autoform.js
Original file line number Diff line number Diff line change
@@ -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);
},
}
});
90 changes: 49 additions & 41 deletions documentation/client/manage/manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,56 @@
<h1 class="modal-title">{{_ "manageApiDocumentationModal_Title" }}</h1>
</div>
<div class="modal-body">
<legend>
{{> showHelp 'uploadApiDocumentation'}}
{{_ "import_ApiDocumentation_Title"}}
</legend>
<div class="documentation-file">
{{#unless documentationFile }}
{{> manageApiDocumentationModalUploadButton }}
{{else}}
<ul class="list-group">
<li class="list-group-item">
<span class="glyphicon glyphicon-file"></span>
{{ documentationFile.filename }}
<span class="pull-right">
<button class="btn btn-xs btn-danger delete-documentation">
<span class="glyphicon glyphicon-trash"></span>
</button>
</span>
</li>
</ul>
{{/unless}}
</div>
{{# if apiDocumentationEditorIsEnabled}}
<legend>
{{>showHelp 'documentation_editor_create_file'}}
{{_ "manageApiDocumentationModal_CreateDocumentation_Title" }}
</legend>
<a id="open-api-editor" class="btn btn-primary" href="/documentation/editor">
{{_ "manageApiDocumentationModal_openDocumentationEditor" }}
</a>
{{/ if }}
<legend>
{{>showHelp 'documentation_link'}}
{{_ "manageApiDocumentationModal_DocumentationLink_Title" }}
</legend>
{{#autoForm collection=apisCollection doc=api id="apiDocumentationForm" type="update" }}
{{> afQuickField name='documentation_link'}}
<button type="submit" class="btn btn-success" id="save-documentation-link">
{{_ "manageApiDocumentationModal_CreateDocumentation_SaveButton" }}
</button>
<button type="button" class="btn btn-default" data-dismiss="modal">
{{_ "manageApiDocumentationModal_CreateDocumentation_CancelButton" }}
</button>

<legend>
{{> showHelp 'uploadApiDocumentation'}}
{{_ "import_ApiDocumentation_Title"}}
</legend>
<div class="documentation-file">
{{#unless documentationFile }}
{{> manageApiDocumentationModalUploadButton }}
{{else}}
<ul class="list-group">
<li class="list-group-item">
<i class="fa fa-file-text-o" aria-hidden="true"></i>
{{ documentationFile.filename }}
<span class="pull-right">
<button type="button" class="btn btn-xs btn-danger delete-documentation">
<i class="fa fa-trash-o fa-lg" aria-hidden="true"></i>
</button>
</span>
</li>
</ul>
{{> afQuickField
name="submit_methods"
options=supportedSubmitMethods
type="select-checkbox-inline"
noselect=false
}}
{{/unless}}
</div>
{{# if apiDocumentationEditorIsEnabled}}
<legend>
{{>showHelp 'documentation_editor_create_file'}}
{{_ "manageApiDocumentationModal_CreateDocumentation_Title" }}
</legend>
<a id="open-api-editor" class="btn btn-primary" href="/documentation/editor">
{{_ "manageApiDocumentationModal_openDocumentationEditor" }}
</a>
{{/ if }}
<legend>
{{>showHelp 'documentation_link'}}
{{_ "manageApiDocumentationModal_DocumentationLink_Title" }}
</legend>
{{> afQuickField name='documentation_link'}}
<button type="submit" class="btn btn-success" id="save-documentation-link">
{{_ "manageApiDocumentationModal_CreateDocumentation_SaveButton" }}
</button>
<button type="button" class="btn btn-default" data-dismiss="modal">
{{_ "manageApiDocumentationModal_CreateDocumentation_CancelButton" }}
</button>

{{/ autoForm }}
</div>
</div>
Expand Down
42 changes: 28 additions & 14 deletions documentation/client/manage/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Settings } from '/settings/collection';

Template.manageApiDocumentationModal.onCreated(function () {
const instance = this;

// Initialize help texts
const helpTexts = {
'documentation_link': {
Expand All @@ -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');
});
Expand All @@ -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'));
}
},
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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 [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment, and/or semantic variable name, describing this return object. E.g. what is it used for?

{label: 'GET', value: 'get'},
{label: 'POST', value: 'post'},
{label: 'DELETE', value: 'delete'},
{label: 'PATCH', value: 'patch'},
{label: 'PUT', value: 'put'}
]
},
});
4 changes: 3 additions & 1 deletion documentation/client/manage/uploadButton/uploadButton.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<template name="manageApiDocumentationModalUploadButton">
<button class="btn btn-primary fileBrowse">{{_ "manageApiDocumentationModalUploadButton" }}</button>
<button type="button" class="btn btn-primary" id="file-browse">
{{_ "manageApiDocumentationModalUploadButton" }}
</button>
</template>
2 changes: 1 addition & 1 deletion documentation/client/manage/uploadButton/uploadButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
52 changes: 26 additions & 26 deletions documentation/client/swaggerUI/swaggerUi.html
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<template name="swaggerUi">
<div class="swagger-section">
<div id="header">
<div class="swagger-ui-wrap">
<a id="logo" href="http://swagger.io" target="_blank" rel="nofollow">
<img src="/img/logo_small.png" class="logo__img" alt="swagger" height="30" width="30">
<span class="logo__title">swagger</span>
</a>
<form id="api_selector">
<div class="input"><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
<div id="auth_container"></div>
<div class="input"><a id="explore" class="header__btn" href="#" data-sw-translate>Explore</a></div>
</form>
</div>
</div>
<div id="message-bar" class="swagger-ui-wrap message-success" data-sw-translate=""></div>
{{#if dataFetched}}
{{#if documentationValid}}
{{>swaggerUiContent apiDocumentation=apiDocumentation}}
{{else}}
<i>
{{_ 'swaggerUi_swaggerDocumentInvalidText'}}
</i>
{{/if}}
{{else}}
{{>spinner}}
{{/if}}
<div class="swagger-section">
<div id="header">
<div class="swagger-ui-wrap">
<a id="logo" href="http://swagger.io" target="_blank" rel="nofollow">
<img src="/img/logo_small.png" class="logo__img" alt="swagger" height="30" width="30">
<span class="logo__title">swagger</span>
</a>
<form id="api_selector">
<div class="input"><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
<div id="auth_container"></div>
<div class="input"><a id="explore" class="header__btn" href="#" data-sw-translate>Explore</a></div>
</form>
</div>
</div>
<div id="message-bar" class="swagger-ui-wrap message-success" data-sw-translate=""></div>
{{#if dataFetched}}
{{#if documentationValid}}
{{>swaggerUiContent apiDoc=apiDoc api=api}}
{{else}}
<i>
{{_ 'swaggerUi_swaggerDocumentInvalidText'}}
</i>
{{/if}}
{{else}}
{{>spinner}}
{{/if}}
</div>
</template>
6 changes: 3 additions & 3 deletions documentation/client/swaggerUI/swaggerUi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 '{}'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<template name="swaggerUiContent">
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
</template>
40 changes: 23 additions & 17 deletions documentation/client/swaggerUI/swaggerUiContent/swaggerUiContent.js
Original file line number Diff line number Diff line change
@@ -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);
});
Loading