[WIP]Generate swagger file
This commit is contained in:
		
							parent
							
								
									85b71c65ca
								
							
						
					
					
						commit
						e62b008c71
					
				
					 4 changed files with 74 additions and 0 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -5,3 +5,4 @@ | |||
| npm-debug.log | ||||
| *.pem | ||||
| run.bat | ||||
| api-docs.json | ||||
|  |  | |||
|  | @ -11,6 +11,7 @@ | |||
|   "scripts": { | ||||
|     "config": "node ./init.js", | ||||
|     "start": "node ./built/index.js", | ||||
|     "swagger": "node ./swagger.js", | ||||
|     "build": "gulp build", | ||||
|     "rebuild": "gulp rebuild", | ||||
|     "clean": "gulp clean", | ||||
|  | @ -120,6 +121,7 @@ | |||
|     "sortablejs": "1.5.0-rc1", | ||||
|     "subdomain": "1.2.0", | ||||
|     "summaly": "1.2.7", | ||||
|     "swagger-jsdoc": "^1.8.4", | ||||
|     "syuilo-password-strength": "0.0.1", | ||||
|     "syuilo-transformify": "0.1.2", | ||||
|     "tcp-port-used": "0.1.2", | ||||
|  |  | |||
|  | @ -7,6 +7,36 @@ import * as uuid from 'uuid'; | |||
| import App from '../../../models/app'; | ||||
| import AuthSess from '../../../models/auth-session'; | ||||
| 
 | ||||
| /** | ||||
|  * @swagger | ||||
|  * /auth/session/generate: | ||||
|  *   post: | ||||
|  *     summary: Generate a session | ||||
|  *     parameters: | ||||
|  *       - | ||||
|  *         name: app_secret | ||||
|  *         in: formData | ||||
|  *         required: true | ||||
|  *         type: string | ||||
|  *          | ||||
|  *     responses: | ||||
|  *       200: | ||||
|  *         description: OK | ||||
|  *         schema: | ||||
|  *           type: object | ||||
|  *           properties: | ||||
|  *             token: | ||||
|  *               type: string | ||||
|  *               description: API Token | ||||
|  *             url: | ||||
|  *               type: string | ||||
|  *               description: Callback URL | ||||
|  *       400: | ||||
|  *         description: Failed | ||||
|  *         schema: | ||||
|  *           $ref: "#/definitions/Error" | ||||
|  */ | ||||
| 
 | ||||
| /** | ||||
|  * Generate a session | ||||
|  * | ||||
|  |  | |||
							
								
								
									
										41
									
								
								swagger.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								swagger.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,41 @@ | |||
| const swaggerJSDoc = require('swagger-jsdoc'); | ||||
| const fs = require('fs'); | ||||
| 
 | ||||
| const apiRoot = './src/api/endpoints'; | ||||
| const files = [ | ||||
|   'auth/session/generate.js' | ||||
| ]; | ||||
| 
 | ||||
| const errorDefinition = { | ||||
|   'type': 'object', | ||||
|   'properties':{ | ||||
|     'error': { | ||||
|       'type': 'string', | ||||
|       'description': 'Error message' | ||||
|     } | ||||
|   } | ||||
| }  | ||||
| 
 | ||||
| var options = { | ||||
|   swaggerDefinition: { | ||||
|     swagger: '2.0', | ||||
|     info: { | ||||
|       title: 'Misskey API', | ||||
|       version: 'aoi', | ||||
|     }, | ||||
|     consumes: [ | ||||
|       'application/x-www-form-urlencoded' | ||||
|     ], | ||||
|     produces: [ | ||||
|       'application/json' | ||||
|     ] | ||||
|   }, | ||||
|   apis: [] | ||||
| }; | ||||
| options.apis = files.map(c => {return `${apiRoot}/${c}`;}); | ||||
| 
 | ||||
| var swaggerSpec = swaggerJSDoc(options); | ||||
| swaggerSpec.definitions.Error = errorDefinition; | ||||
| 
 | ||||
| fs.writeFileSync('api-docs.json', JSON.stringify(swaggerSpec)); | ||||
| 
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue