-
Notifications
You must be signed in to change notification settings - Fork 33
Try-out button for Swagger file #1563
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
Changes from 10 commits
0224569
7964a03
95ef85d
832948e
9fe75f5
7298b3c
a557700
999207c
209b7a0
b02083d
0422cde
8799a81
8a82642
395b72e
cc99194
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 |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| AutoForm.addHooks(['apiDocumentationForm'], { | ||
| onSuccess () { | ||
| sAlert.success(TAPi18n.__('manageApiDocumentationModal_LinkField_Updated_Message')); | ||
| }, | ||
| }); | ||
| AutoForm.hooks({ | ||
| apiDocumentationForm: { | ||
| onSuccess () { | ||
| sAlert.success(TAPi18n.__('manageApiDocumentationModal_LinkField_Updated_Message')); | ||
| }, | ||
| } | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"> | ||
| <span class="glyphicon glyphicon-file"></span> | ||
|
||
| {{ documentationFile.filename }} | ||
| <span class="pull-right"> | ||
| <button type="button" class="btn btn-xs btn-danger delete-documentation"> | ||
| <span class="glyphicon glyphicon-trash"></span> | ||
|
||
| </button> | ||
| </span> | ||
| </li> | ||
| </ul> | ||
| {{> afQuickField | ||
| name="submit_methods" | ||
| options=submitMethods | ||
| 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> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,7 +98,11 @@ Template.manageApiDocumentationModal.helpers({ | |
| 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,13 @@ Template.manageApiDocumentationModal.helpers({ | |
| // Return a reference to Apis collection, for AutoForm | ||
| return Apis; | ||
| }, | ||
| submitMethods () { | ||
| return [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'} | ||
| ] | ||
| }, | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| <template name="manageApiDocumentationModalUploadButton"> | ||
| <button class="btn btn-primary fileBrowse">{{_ "manageApiDocumentationModalUploadButton" }}</button> | ||
| <button type="button" class="btn btn-primary fileBrowse">{{_ "manageApiDocumentationModalUploadButton" }}</button> | ||
|
||
| </template> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ | |
| <div id="message-bar" class="swagger-ui-wrap message-success" data-sw-translate=""></div> | ||
| {{#if dataFetched}} | ||
| {{#if documentationValid}} | ||
| {{>swaggerUiContent apiDocumentation=apiDocumentation}} | ||
| {{>swaggerUiContent apiDoc=apiDoc api=api}} | ||
|
||
| {{else}} | ||
| <i> | ||
| {{_ 'swaggerUi_swaggerDocumentInvalidText'}} | ||
|
|
||
| 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; | ||
| const documentationURL = this.data.apiDoc; | ||
|
|
||
| // Create Swagger UI | ||
| const swagger = window.swaggerUi = new SwaggerUi({ | ||
| // 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', | ||
| }); | ||
|
|
||
| // Load Swagger UI | ||
| swagger.load(); | ||
| }); | ||
| // Subscribe to api collection | ||
| instance.autorun(() => { | ||
| // Get relevant api collection | ||
| instance.subscribe('apiBackend', instance.data.api._id); | ||
|
|
||
| Template.swaggerUiContent.onRendered(function () { | ||
| // Get URL of api documentation | ||
| const documentationURL = this.data.apiDocumentation; | ||
| // Get api | ||
| const api = Apis.findOne(instance.data.api._id); | ||
|
|
||
| // Display URL on Swagger UI input | ||
| $('#input_baseUrl').val(documentationURL); | ||
| // Set selected methods in Swagger | ||
| swagger.setOption('supportedSubmitMethods', api.submit_methods); | ||
|
|
||
| // Load Swagger UI | ||
| swagger.load(); | ||
| }); | ||
| }); |
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.
Please separate this line into two parts:
It is a bit 'cleaner' this way, and shortens the line length.
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.
Okay