1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 10:19:30 +02:00

Add basic api unit. This unit will be responsible for providing all stf restful apis.

This commit is contained in:
Vishal Banthia 2015-12-02 18:18:31 +09:00
parent 7ea7871ec0
commit 41f306a7f0
7 changed files with 172 additions and 0 deletions

View file

@ -0,0 +1,38 @@
# swagger configuration file
# values in the swagger hash are system configuration for swagger-node
swagger:
fittingsDirs: [ fittings ]
defaultPipe: null
swaggerControllerPipe: swagger_controllers # defines the standard processing pipe for controllers
swagger: 'swagger/api_v1.yaml'
# values defined in the bagpipes key are the bagpipes pipes and fittings definitions
# (see https://github.com/apigee-127/bagpipes)
bagpipes:
_router:
name: swagger_router
mockMode: false
mockControllersDirs: [ mocks ]
controllersDirs: [ controllers ]
_swagger_validate:
name: swagger_validator
validateResponse: true
# pipe for all swagger-node controllers
swagger_controllers:
- onError: json_error_handler
- cors
- swagger_security
- _swagger_validate
- express_compatibility
- _router
# pipe to serve swagger (endpoint is in swagger.yaml)
swagger_raw:
name: swagger_raw
# any other values in this file are just loaded into the config for application access...

View file

@ -0,0 +1,10 @@
module.exports = {
getCurrentUser: getCurrentUser
};
function getCurrentUser(req, res) {
res.json({
success: true
, user: {"name": "dummy"}
})
}

27
lib/units/api/index.js Normal file
View file

@ -0,0 +1,27 @@
var http = require('http')
var path = require('path')
var express = require('express')
var SwaggerExpress = require('swagger-express-mw')
var logger = require('../../util/logger')
module.exports = function(options) {
var log = logger.createLogger('api')
, app = express()
, server = http.createServer(app)
var config = {
appRoot: __dirname
, swaggerFile: path.resolve(__dirname, 'swagger', 'api_v1.yaml')
};
SwaggerExpress.create(config, function(err, swaggerExpress) {
if (err) { throw err; }
swaggerExpress.register(app);
})
server.listen(options.port)
log.info('Listening on port %d', options.port)
}

View file

@ -0,0 +1,48 @@
swagger: "2.0"
info:
version: "1.0.10"
title: Smartphone Test Farm
description: Control and manager real Smartphone devices from browser and apis
license:
name: Apache-2.0
url: http://www.apache.org/licenses/LICENSE-2.0
contact:
url: http://openstf.io/
email: contact@openstf.io
basePath: /api/v1/
schemes:
- http
- https
consumes:
- application/json
produces:
- application/json
paths:
/me:
x-swagger-router-controller: user
get:
summary: User Profile
description: The User Profile endpoint returns information about current authorized user.
operationId: getCurrentUser
responses:
"200":
description: Current User Profile information
schema:
$ref: "#/definitions/UserResponse"
default:
description: Unexpected Error
schema:
$ref: "#/definitions/ErrorResponse"
definitions:
UserResponse:
required:
- user
properties:
user:
type: object
ErrorResponse:
required:
- message
properties:
message:
type: string