├── .eslintrc.js ├── .gitignore ├── LICENSE ├── README.md ├── package.json ├── readme_images ├── Capture_00.PNG ├── Capture_01.PNG ├── Capture_02.PNG ├── Capture_03.PNG ├── Capture_04.PNG └── Capture_Swagger_UI.PNG └── swagger ├── locales ├── en-US │ └── swagger.json └── ja │ └── swagger.json ├── swagger-ui └── swagger-ui.html ├── swagger.html └── swagger.js /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "env": { 3 | "browser": true, 4 | "commonjs": true, 5 | "es6": true, 6 | "node": true 7 | }, 8 | "extends": "eslint:recommended", 9 | "globals": { 10 | "Atomics": "readonly", 11 | "SharedArrayBuffer": "readonly" 12 | }, 13 | "parserOptions": { 14 | "ecmaVersion": 2018 15 | }, 16 | "rules": { 17 | } 18 | }; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Node-RED Swagger Documentation Generator 2 | 3 | This package provides a set of tools for generating Swagger api documentation 4 | based on the HTTP nodes deployed in a flow. 5 | 6 | ## Usage 7 | 8 | 1. Install the node module 9 | 10 | npm install node-red-node-swagger 11 | 12 | **Note:** until this is published to npm, you will need to install from git: 13 | 14 | npm install node-red/node-red-node-swagger 15 | 16 | 2. Provide a template swagger file in `settings.js`: 17 | 18 | swagger: { 19 | "template": { 20 | "swagger": "2.0", 21 | "info": { 22 | "title": "My Node-RED API", 23 | "version": "0.0.1" 24 | } 25 | } 26 | } 27 | 28 | 3. This template will remain unchanged and serve as the basis for the swagger doc. 29 | 30 | **Note:** You may additionally add parameters to the swagger file in 'settings.js' to have those parameters automatically added to each path in the generated swagger doc. 31 | 32 | "swagger": { 33 | "template": { 34 | "swagger": "2.0", 35 | "info": { 36 | "title": "My Node-RED API", 37 | "version": "0.0.1" 38 | } 39 | }, 40 | "parameters": [ 41 | { 42 | "name": "parameterA", 43 | "type": "string", 44 | "in": "header", 45 | "required": false, 46 | "description": "This is a test parameter to show how parameters are automatically added to each path in the generated swagger doc." 47 | } 48 | ] 49 | } 50 | 51 | 4. After installing the package, you have the option to identify metadata for each HTTP-In node that will be used in the swagger doc generation. 52 | 53 | 5. The generated swagger is then available at . 54 | 55 | ## Path Swagger Generation 56 | 57 | Via the editor, you can define metadata for each particular HTTP-In node to be used in swagger generation. 58 | 59 | To do so, 60 | 61 | 1. Select an HTTP-In node in the editor. 62 | ![](readme_images/Capture_00.PNG?raw=true) 63 | 64 | 2. From the config panel, you can select a user-defined swagger doc from the dropdown. You may create a new metadata definition by selecting "Add new swagger-doc..." and clicking the edit button. 65 | ![](readme_images/Capture_01.PNG?raw=true) 66 | 67 | 3. This will launch the swagger config panel, where you have three distinct tabs that make up the swagger documentation. 68 | 69 | #### Info 70 | 71 | ![](readme_images/Capture_02.PNG?raw=true) 72 | 73 | This tab allows you to provide the basic information about the attached paths. 74 | 75 | * Summary - A short summary of what the operation does. For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters. 76 | * Description - A verbose explanation of the operation behavior. [GFM syntax](https://help.github.com/articles/github-flavored-markdown) can be used for rich text representation. 77 | * Tags - A list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier. These should be provided as a comma-separated list. 78 | * Consumes - A list of MIME types the operation can consume. These should be provided as a comma-separated list 79 | * Produces - A list of MIME types the operation can produce. These should be provided as a comma-separated list. 80 | * Deprecated - Declares this operation to be deprecated. Usage of the declared operation should be refrained. 81 | 82 | #### Parameters 83 | 84 | ![](readme_images/Capture_03.PNG?raw=true) 85 | 86 | This tab allows you to configure the parameters that can be used with the particular operation. 87 | 88 | * Name - The name of the parameter. Parameter names are case sensitive. 89 | * In - The location of the parameter. There are four supported locations of the parameter 90 | * _Query_ - Parameters that are appended to the URL. For example, in `/items?id=###`, the query parameter is `id`. 91 | * _Header_ - Custom headers that are expected as part of the request. 92 | * _Form_ - Used to describe the payload of an HTTP request when either `application/x-www-form-urlencoded` or `multipart/form-data` are used as the content type of the request. This is the only parameter type that can be used to send files, thus supporting the `file` type. Since form parameters are sent in the payload, they cannot be declared together with a body parameter for the same operation. Form parameters have a different format based on the content-type used (for further details, consult ): 93 | * _Body_ - The payload that's appended to the HTTP request. Since there can only be one payload, there can only be *one* body parameter. The name of the body parameter has no effect on the parameter itself and is used for documentation purposes only. Since Form parameters are also in the payload, body and form parameters cannot exist together for the same operation. 94 | * Description - A brief description of the parameter. This could contain examples of use. [GFM syntax](https://help.github.com/articles/github-flavored-markdown) can be used for rich text representation. 95 | * Required - Determines whether this parameter is mandatory. 96 | * Type - The type of the parameter. Since the parameter is not located at the request body, it is limited to simple types (that is, not an object). 97 | * Format - The extending format for the previously mentioned type. 98 | 99 | If a body parameter is selected, the user will provide properties included in the body object, rather than specifying a type. 100 | 101 | 102 | #### Responses 103 | 104 | ![](readme_images/Capture_04.PNG?raw=true) 105 | 106 | This tab allows you to define the applicable responses that a user may receive back from the operation. 107 | 108 | * Code - You can either select to define the default response, or to provide a specific HTTP status code that the response will be applicable for. A default response is used to cover other undeclared responses 109 | * Description - A short description of the parameter. This could contain examples of use. [GFM syntax](https://help.github.com/articles/github-flavored-markdown) can be used for rich text representation. 110 | * Properties - The properties are the components that build up the schema of the response. 111 | * Name - The key name for the particular property. 112 | * Type - The type of the property. 113 | * Format - The extending format for the previously mentioned type. 114 | 115 | If no responses are provided, a default response with the reply "success" will be used. 116 | 117 | ##Swagger-UI 118 | 119 | ![](readme_images/Capture_Swagger_UI.PNG?raw=true) 120 | 121 | Swagger-UI is including in the plugin. Once loaded, the plugin will show a swagger tab in the node-red sidebar. From here, you can see the dynamically generated swagger for the current flow. Additionally, you can use the test function to try out your API directly from the editor, providing any parameters you have defined in the docs for the HTTP-In nodes. The Swagger-UI will automatically refresh any time the flow is redeployed. 122 | 123 | 124 | 125 | ## Notes 126 | 127 | - the `paths` entry of the swagger is generated based on the `HTTP In` nodes 128 | present in the flow. 129 | - if a swagger template is not provided, the example above is used as the default. 130 | - if `basePath` is not set in the template, it is set to the value of `httpNodeRoot` 131 | if that value is something other than `/`. 132 | 133 | 134 | ###### Attribute definitions provided come from the [Swagger 2.0 Spec](https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-red-node-swagger", 3 | "version": "0.1.9", 4 | "description": "A set of tools for generating Swagger API documentation based on the HTTP nodes deployed in a flow", 5 | "license": "Apache", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/node-red/node-red-node-swagger.git" 9 | }, 10 | "keywords": [ 11 | "node-red", 12 | "swagger" 13 | ], 14 | "node-red": { 15 | "version": ">=0.11.0", 16 | "nodes": { 17 | "swagger": "swagger/swagger.js" 18 | } 19 | }, 20 | "contributors": [ 21 | "Nick O'Leary ", 22 | "Cody Walker ", 23 | "Jon Silver " 24 | ], 25 | "dependencies": { 26 | "swagger-ui": "2.1.4", 27 | "i18next-client": "1.11.4" 28 | }, 29 | "devDependencies": { 30 | "eslint": "^6.4.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /readme_images/Capture_00.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/node-red/node-red-node-swagger/a183fdac2e79700e9b53ccb2b6522ff831aa1cbb/readme_images/Capture_00.PNG -------------------------------------------------------------------------------- /readme_images/Capture_01.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/node-red/node-red-node-swagger/a183fdac2e79700e9b53ccb2b6522ff831aa1cbb/readme_images/Capture_01.PNG -------------------------------------------------------------------------------- /readme_images/Capture_02.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/node-red/node-red-node-swagger/a183fdac2e79700e9b53ccb2b6522ff831aa1cbb/readme_images/Capture_02.PNG -------------------------------------------------------------------------------- /readme_images/Capture_03.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/node-red/node-red-node-swagger/a183fdac2e79700e9b53ccb2b6522ff831aa1cbb/readme_images/Capture_03.PNG -------------------------------------------------------------------------------- /readme_images/Capture_04.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/node-red/node-red-node-swagger/a183fdac2e79700e9b53ccb2b6522ff831aa1cbb/readme_images/Capture_04.PNG -------------------------------------------------------------------------------- /readme_images/Capture_Swagger_UI.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/node-red/node-red-node-swagger/a183fdac2e79700e9b53ccb2b6522ff831aa1cbb/readme_images/Capture_Swagger_UI.PNG -------------------------------------------------------------------------------- /swagger/locales/en-US/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": { 3 | "sidebar": { 4 | "label": "swagger", 5 | "name": "Swagger UI" 6 | }, 7 | "label": { 8 | "path": "Path", 9 | "summary": "Summary", 10 | "description": "Description", 11 | "tags": "Tags", 12 | "consumes": "Consumes", 13 | "produces": "Produces", 14 | "deprecated": "Deprecated", 15 | "parameter": "parameter", 16 | "parameters-help": "Parameters Help", 17 | "response": "response", 18 | "responses-help": "Responses Help", 19 | "property": "property" 20 | }, 21 | "placeholder": { 22 | "tags": "Comma-separated list of Tags", 23 | "consumes": "Comma-separated list of Mime Types", 24 | "produces": "Comma-separated list of Mime Types" 25 | }, 26 | "data-content": { 27 | "summary": "A short summary of what the operation does. For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.", 28 | "description": "A verbose explanation of the operation behavior. GitHub Flavored Markup syntax can be used for rich text representation.", 29 | "tags": "A list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier.", 30 | "consumes": "A list of MIME types the operation can consume.", 31 | "produces": "A list of MIME types the operation can produce.", 32 | "deprecated": "Declares this operation to be deprecated. Usage of the declared operation should be refrained." 33 | }, 34 | "content": { 35 | "parameter-info": "

A list of parameters that are applicable for this operation.

To add a parameter, click the parameter button.

There are four possible parameter types.

  • Query - Parameters that are appended to the URL. For example, in /items?id=###, the query parameter is id.
  • Header - Custom headers that are expected as part of the request.
  • Body - The payload that's appended to the HTTP request. Since there can only be one payload, there can only be one body parameter. The name of the body parameter has no effect on the parameter itself and is used for documentation purposes only.
  • Form - Used to describe the payload of an HTTP request when either application/x-www-form-urlencoded or multipart/form-data are used as the content type of the request (in Swagger's definition, the consumes property of an operation). This is the only parameter type that can be used to send files, thus supporting the file type.
", 36 | "response-info": "

The list of possible responses as they are returned from executing this operation.

You may supply responses for individual status codes, and/or a default response.

To add a parameter, click the response button.

If no responses are entered, a default response returning 'success' will be added for you.

", 37 | "type": "The type of the attribute, limited to primitive types.", 38 | "format": "The extending format for the previously mentioned type.", 39 | "parameter-description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markup syntax can be used for rich text representation.", 40 | "required": "Determines whether this parameter is mandatory.", 41 | "response-description": "A brief description of the response. This could contain examples of use. GitHub Flavored Markup syntax can be used for rich text representation." 42 | }, 43 | "tabs-label": { 44 | "info": "Info", 45 | "parameters": "Parameters", 46 | "responses": "Responses" 47 | }, 48 | "text": { 49 | "type": "Type", 50 | "format": "Format", 51 | "name": "Name", 52 | "in": "in", 53 | "path": "path", 54 | "description": "Description", 55 | "required": "Required?", 56 | "properties": "Properties", 57 | "file": "file", 58 | "code": "Code", 59 | "default": "Default" 60 | }, 61 | "helpBox": { 62 | "title": "I see you're lacking Swagger doc...", 63 | "swaggerIntro": "Swagger is a simple yet powerful way to document your REST API.", 64 | "swaggerInfo": "The Swagger plug-in dynamically generates Swagger documentation based on input provided when setting up your HTTP endpoint nodes.", 65 | "swaggerInstructions0": "After building your REST APIs in the editor, click the HTTP endpoint node. You can then attach additional Swagger documentation to that node by clicking the add button next to Docs.", 66 | "swaggerInstructions1": "You are able to add additional details on the types of inputs and outputs expected from your endpoint by quickly navigating through the screens and providing some information.", 67 | "swaggerInstructions2": "Once your flow is deployed, this tab will be automatically populated by a visual representation of your API.", 68 | "swaggerOutro": "You can then use this Swagger-UI tab to effortlessly test your APIs." 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /swagger/locales/ja/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": { 3 | "sidebar": { 4 | "label": "swagger", 5 | "name": "Swagger UI" 6 | }, 7 | "label": { 8 | "path": "パス", 9 | "summary": "要約", 10 | "description": "説明", 11 | "tags": "タグ", 12 | "consumes": "コンシューム", 13 | "produces": "プロデュース", 14 | "deprecated": "非推奨", 15 | "parameter": "パラメータ", 16 | "parameters-help": "パラメータのヘルプ", 17 | "response": "応答", 18 | "responses-help": "応答のヘルプ", 19 | "property": "プロパティ" 20 | }, 21 | "placeholder": { 22 | "tags": "コンマ区切りのタグのリスト", 23 | "consumes": "コンマ区切りのMime型のリスト", 24 | "produces": "コンマ区切りのMime型のリスト" 25 | }, 26 | "data-content": { 27 | "summary": "操作内容ついての短い要約。Swagger-UI上で読みやすくするために、このフィールドは120文字未満にする必要があります。", 28 | "description": "操作の動作についての詳細な説明。GitHub風のマークアップ構文を用いることで、豊かな文章表現が可能です。", 29 | "tags": "APIドキュメントの制御用のタグリスト。リソースやその他の修飾子による操作の論理グループ化のために、本タグを使用できます。", 30 | "consumes": "操作で利用するコンシュームのMIMEタイプのリスト。", 31 | "produces": "操作で利用するプロディュースのMIMEタイプのリスト。", 32 | "deprecated": "本操作が非推奨になることを宣言します。宣言された操作の利用は控えるべきです。" 33 | }, 34 | "content": { 35 | "parameter-info": "

この操作に適用できるパラメータのリスト。

パラメータを追加するには、 パラメータボタンをクリックします。

利用できるパラメータは、4種類あります。

  • Query - URLに追加されるパラメータ。例えば、/items?id=### におけるクエリパラメータはidです。
  • Header - リクエストの一部として期待されるカスタムヘッダ。
  • Body - HTTPリクエストに追加されるペイロード。ペイロードは1つだけのため、ボディパラメータは1つしか存在できません。ボディパラメータの名前は、パラメータ自体には影響せず、文書化の目的のみで使用されます。
  • Form - リクエストのcontent type (Swagger定義では、操作のコンシュームプロパティ)として、application/x-www-form-urlencodedまたはmultipart/form-dataのいずれかが使われている際に、HTTPリクエストのペイロードを説明するために使用されます。これはファイル送信に使用できる唯一のパラメータであるため、ファイルタイプをサポートします。
", 36 | "response-info": "

この操作を実行すると返される可能性のあるレスポンスのリスト。

デフォルトのレスポンスと、個別の状態コードのためのレスポンスを提供できます。

パラメータを追加するには、レスポンスボタンをクリックします。

レスポンスが入力されない場合は「成功」を返すデフォルトのレスポンスが追加されます。

", 37 | "type": "プリミティブ型に限定された属性のタイプ。", 38 | "format": "前述のタイプのための拡張フォーマット。", 39 | "parameter-description": "パラメータの簡単な説明。ここには使用例を含めることができます。GitHub風のマークアップ構文を用いて、豊かなテキスト表現を利用できます。", 40 | "required": "必須パラメータか否かを判別します。", 41 | "response-description": "レスポンスの簡単な説明。ここには使用例を含めることができます。GitHub風のマークアップ構文を用いて、豊かなテキスト表現を利用できます。" 42 | }, 43 | "tabs-label": { 44 | "info": "情報", 45 | "parameters": "パラメータ", 46 | "responses": "応答" 47 | }, 48 | "text": { 49 | "type": "型", 50 | "format": "形式", 51 | "name": "名前", 52 | "in": "in", 53 | "path": "パス", 54 | "description": "説明", 55 | "required": "必須?", 56 | "properties": "プロパティ", 57 | "file": "ファイル", 58 | "code": "コード", 59 | "default": "規定" 60 | }, 61 | "helpBox": { 62 | "title": "Swaggerドキュメントがない様です...", 63 | "swaggerIntro": "Swaggerとは、REST APIをドキュメント化する簡単で強力な方法です。", 64 | "swaggerInfo": "本Swaggerプラグインは、HTTPエンドポイントのノードを設定した時の入力値に基づいて、動的にSwaggerドキュメントを生成します。", 65 | "swaggerInstructions0": "エディタ上でREST APIを作成した後、HTTPエンドポイントのノードをクリックします。「ドキュメント」の隣にある「追加」ボタンをクリックすることで、Swaggerのドキュメントをそのノードに追加できます。", 66 | "swaggerInstructions1": "画面上で素早く操作して情報を提供することで、エンドポイントの入力や期待される出力のタイプに関する詳細情報の追加できます。", 67 | "swaggerInstructions2": "フローがデプロイされると、このタブには自動的にAPIを視覚的に表示されます。", 68 | "swaggerOutro": "このSwagger-UIを用いて、簡単にAPIをテストできます。" 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /swagger/swagger-ui/swagger-ui.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Swagger UI 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 49 | 70 | 71 | 128 | 129 | 130 | 131 |
132 |

133 | 134 | 135 |

136 |

swagger.helpBox.title

137 |

swagger.helpBox.swaggerIntro

138 |

swagger.helpBox.swaggerInfo

139 |

swagger.helpBox.swaggerInstructions0

140 |

swagger.helpBox.swaggerInstructions1

141 |

swagger.helpBox.swaggerInstructions2

142 |

swagger.helpBox.swaggerOutro

143 |

144 |
145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /swagger/swagger.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 76 | 77 | 80 | 81 | 989 | -------------------------------------------------------------------------------- /swagger/swagger.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2015, 2016 IBM Corp. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **/ 16 | 17 | const DEFAULT_TEMPLATE = { 18 | swagger: "2.0", 19 | info: { 20 | title: "My Node-RED API", 21 | version: "0.0.1" 22 | } 23 | }; 24 | 25 | module.exports = function(RED) { 26 | "use strict"; 27 | 28 | const path = require("path"); 29 | 30 | const convToSwaggerPath = x => `/{${x.substring(2)}}`; 31 | const trimAll = ary => ary.map(x => x.trim()); 32 | const csvStrToArray = csvStr => csvStr ? trimAll(csvStr.split(",")) : []; 33 | const ensureLeadingSlash = url => (url.startsWith("/") ? url : "/" + url); 34 | const stripTerminalSlash = url => 35 | url.length > 1 && url.endsWith("/") ? url.slice(0, -1) : url; 36 | const regexColons = /\/:\w*/g; 37 | 38 | RED.httpNode.get("/http-api/swagger.json", (req, res) => { 39 | const { 40 | httpNodeRoot, 41 | swagger: { parameters: additionalParams = [], template: resp = { ...DEFAULT_TEMPLATE } } = {} 42 | } = RED.settings; 43 | const { basePath = httpNodeRoot } = resp; 44 | resp.basePath = stripTerminalSlash(basePath); 45 | resp.paths = {}; 46 | 47 | RED.nodes.eachNode(node => { 48 | const { name, type, method, swaggerDoc, url } = node; 49 | 50 | if (type === "http in") { 51 | const swagger = RED.nodes.getNode(swaggerDoc); 52 | const endPoint = ensureLeadingSlash(url.replace(regexColons, convToSwaggerPath)); 53 | if (!resp.paths[endPoint]) resp.paths[endPoint] = {}; 54 | 55 | const { 56 | summary = name || method + " " + endPoint, 57 | description = "", 58 | tags = "", 59 | consumes, 60 | produces, 61 | deprecated, 62 | parameters = [], 63 | responses = { 64 | default: { 65 | description: "" 66 | } 67 | } 68 | } = swagger || {}; 69 | 70 | const aryTags = csvStrToArray(tags), 71 | aryConsumes = csvStrToArray(consumes), 72 | aryProduces = csvStrToArray(produces); 73 | 74 | resp.paths[endPoint][method] = { 75 | summary, 76 | description, 77 | tags: aryTags, 78 | consumes: aryConsumes, 79 | produces: aryProduces, 80 | deprecated, 81 | parameters: [...parameters, ...additionalParams], 82 | responses 83 | }; 84 | } 85 | }); 86 | res.json(resp); 87 | }); 88 | 89 | function SwaggerDoc(n) { 90 | RED.nodes.createNode(this, n); 91 | this.summary = n.summary; 92 | this.description = n.description; 93 | this.tags = n.tags; 94 | this.consumes = n.consumes; 95 | this.produces = n.produces; 96 | this.parameters = n.parameters; 97 | this.responses = n.responses; 98 | this.deprecated = n.deprecated; 99 | } 100 | RED.nodes.registerType("swagger-doc", SwaggerDoc); 101 | 102 | function sendFile(res, filename) { 103 | // Use the right function depending on Express 3.x/4.x 104 | if (res.sendFile) { 105 | res.sendFile(filename); 106 | } else { 107 | res.sendfile(filename); 108 | } 109 | } 110 | 111 | RED.httpAdmin.get("/swagger-ui/reqs/i18next.min.js", (req, res) => { 112 | const basePath = require.resolve("i18next-client").replace(/[\\/]i18next.js$/, ""); 113 | const filename = path.join(basePath, "i18next.min.js"); 114 | sendFile(res, filename); 115 | }); 116 | RED.httpAdmin.get("/swagger-ui/reqs/*", (req, res) => { 117 | const basePath = require.resolve("swagger-ui").replace(/[\\/]swagger-ui.js$/, ""); 118 | const filename = path.join(basePath, req.params[0]); 119 | sendFile(res, filename); 120 | }); 121 | RED.httpAdmin.get("/swagger-ui/nls/*", (req, res) => { 122 | const filename = path.join(__dirname, "locales", req.params[0]); 123 | sendFile(res, filename); 124 | }); 125 | RED.httpAdmin.get("/swagger-ui/*", (req, res) => { 126 | const filename = path.join(__dirname, "swagger-ui", req.params[0]); 127 | sendFile(res, filename); 128 | }); 129 | }; 130 | --------------------------------------------------------------------------------