зеркало из https://github.com/Azure/sway.git
Fixed registration of customValidators during creation of SwaggerApi.
This commit is contained in:
Родитель
1a3102625c
Коммит
379d6da77c
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
1750
browser/sway.js
1750
browser/sway.js
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
60
docs/API.md
60
docs/API.md
|
@ -1,4 +1,5 @@
|
|||
## Classes
|
||||
|
||||
<dl>
|
||||
<dt><a href="#Operation">Operation</a></dt>
|
||||
<dd></dd>
|
||||
|
@ -13,18 +14,23 @@
|
|||
<dt><a href="#SwaggerApi">SwaggerApi</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
## Functions
|
||||
|
||||
<dl>
|
||||
<dt><a href="#create">create(options)</a> ⇒ <code>Promise</code></dt>
|
||||
<dd><p>Creates a SwaggerApi object from its Swagger definition(s).</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
## Typedefs
|
||||
|
||||
<dl>
|
||||
<dt><a href="#validatorCallback">validatorCallback</a> ⇒ <code>object</code></dt>
|
||||
<dd><p>Callback used for validation.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<a name="Operation"></a>
|
||||
## Operation
|
||||
**Kind**: global class
|
||||
|
@ -42,12 +48,12 @@
|
|||
|
||||
|
||||
* [Operation](#Operation)
|
||||
* [new Operation(api, pathObject, method, ptr, definition, consumes, produces)](#new_Operation_new)
|
||||
* [.getParameters()](#Operation+getParameters) ⇒ <code>[Array.<Parameter>](#Parameter)</code>
|
||||
* [.getResponse([statusCode])](#Operation+getResponse) ⇒ <code>[Response](#Response)</code>
|
||||
* [.getResponses()](#Operation+getResponses) ⇒ <code>[Array.<Response>](#Response)</code>
|
||||
* [.validateRequest(req)](#Operation+validateRequest) ⇒ <code>object</code>
|
||||
* [.validateResponse(statusCode, headers, body, [encoding])](#Operation+validateResponse) ⇒ <code>object</code>
|
||||
* [new Operation(api, pathObject, method, ptr, definition, consumes, produces)](#new_Operation_new)
|
||||
* [.getParameters()](#Operation+getParameters) ⇒ <code>[Array.<Parameter>](#Parameter)</code>
|
||||
* [.getResponse([statusCode])](#Operation+getResponse) ⇒ <code>[Response](#Response)</code>
|
||||
* [.getResponses()](#Operation+getResponses) ⇒ <code>[Array.<Response>](#Response)</code>
|
||||
* [.validateRequest(req)](#Operation+validateRequest) ⇒ <code>object</code>
|
||||
* [.validateResponse(statusCode, headers, body, [encoding])](#Operation+validateResponse) ⇒ <code>object</code>
|
||||
|
||||
<a name="new_Operation_new"></a>
|
||||
### new Operation(api, pathObject, method, ptr, definition, consumes, produces)
|
||||
|
@ -175,10 +181,10 @@ Validates the response.
|
|||
|
||||
|
||||
* [Parameter](#Parameter)
|
||||
* [new Parameter(opOrPath, ptr, definition, schema)](#new_Parameter_new)
|
||||
* [.getSample()](#Parameter+getSample) ⇒ <code>\*</code>
|
||||
* [.getSchema()](#Parameter+getSchema) ⇒ <code>object</code>
|
||||
* [.getValue(req)](#Parameter+getValue) ⇒ <code>[ParameterValue](#ParameterValue)</code>
|
||||
* [new Parameter(opOrPath, ptr, definition, schema)](#new_Parameter_new)
|
||||
* [.getSample()](#Parameter+getSample) ⇒ <code>\*</code>
|
||||
* [.getSchema()](#Parameter+getSchema) ⇒ <code>object</code>
|
||||
* [.getValue(req)](#Parameter+getValue) ⇒ <code>[ParameterValue](#ParameterValue)</code>
|
||||
|
||||
<a name="new_Parameter_new"></a>
|
||||
### new Parameter(opOrPath, ptr, definition, schema)
|
||||
|
@ -280,11 +286,11 @@ Object representing a parameter value.
|
|||
|
||||
|
||||
* [Path](#Path)
|
||||
* [new Path(api, path, ptr, definition, regexp)](#new_Path_new)
|
||||
* [.getOperation(method)](#Path+getOperation) ⇒ <code>[Array.<Operation>](#Operation)</code>
|
||||
* [.getOperations()](#Path+getOperations) ⇒ <code>[Array.<Operation>](#Operation)</code>
|
||||
* [.getOperationsByTag(tag)](#Path+getOperationsByTag) ⇒ <code>[Array.<Operation>](#Operation)</code>
|
||||
* [.getParameters()](#Path+getParameters) ⇒ <code>[Array.<Parameter>](#Parameter)</code>
|
||||
* [new Path(api, path, ptr, definition, regexp)](#new_Path_new)
|
||||
* [.getOperation(method)](#Path+getOperation) ⇒ <code>[Array.<Operation>](#Operation)</code>
|
||||
* [.getOperations()](#Path+getOperations) ⇒ <code>[Array.<Operation>](#Operation)</code>
|
||||
* [.getOperationsByTag(tag)](#Path+getOperationsByTag) ⇒ <code>[Array.<Operation>](#Operation)</code>
|
||||
* [.getParameters()](#Path+getParameters) ⇒ <code>[Array.<Parameter>](#Parameter)</code>
|
||||
|
||||
<a name="new_Path_new"></a>
|
||||
### new Path(api, path, ptr, definition, regexp)
|
||||
|
@ -353,10 +359,10 @@ Return the parameters for this path.
|
|||
|
||||
|
||||
* [Response](#Response)
|
||||
* [new Response(operation, ptr, definition, statusCode)](#new_Response_new)
|
||||
* [.getExample([mimeType])](#Response+getExample) ⇒ <code>string</code>
|
||||
* [.getSample()](#Response+getSample) ⇒ <code>\*</code>
|
||||
* [.validateResponse(headers, body, [encoding])](#Response+validateResponse) ⇒ <code>object</code>
|
||||
* [new Response(operation, ptr, definition, statusCode)](#new_Response_new)
|
||||
* [.getExample([mimeType])](#Response+getExample) ⇒ <code>string</code>
|
||||
* [.getSample()](#Response+getSample) ⇒ <code>\*</code>
|
||||
* [.validateResponse(headers, body, [encoding])](#Response+validateResponse) ⇒ <code>object</code>
|
||||
|
||||
<a name="new_Response_new"></a>
|
||||
### new Response(operation, ptr, definition, statusCode)
|
||||
|
@ -442,14 +448,14 @@ Validates the response.
|
|||
|
||||
|
||||
* [SwaggerApi](#SwaggerApi)
|
||||
* [new SwaggerApi(plugin, definition, resolved, references, options)](#new_SwaggerApi_new)
|
||||
* [.getOperation(pathOrReq, [method])](#SwaggerApi+getOperation) ⇒ <code>[Operation](#Operation)</code>
|
||||
* [.getOperations([path])](#SwaggerApi+getOperations) ⇒ <code>[Array.<Operation>](#Operation)</code>
|
||||
* [.getOperationsByTag([tag])](#SwaggerApi+getOperationsByTag) ⇒ <code>[Array.<Operation>](#Operation)</code>
|
||||
* [.getPath(pathOrReq)](#SwaggerApi+getPath) ⇒ <code>[Path](#Path)</code>
|
||||
* [.getPaths()](#SwaggerApi+getPaths) ⇒ <code>[Array.<Path>](#Path)</code>
|
||||
* [.registerValidator(validator)](#SwaggerApi+registerValidator)
|
||||
* [.validate()](#SwaggerApi+validate) ⇒ <code>object</code>
|
||||
* [new SwaggerApi(plugin, definition, resolved, references, options)](#new_SwaggerApi_new)
|
||||
* [.getOperation(pathOrReq, [method])](#SwaggerApi+getOperation) ⇒ <code>[Operation](#Operation)</code>
|
||||
* [.getOperations([path])](#SwaggerApi+getOperations) ⇒ <code>[Array.<Operation>](#Operation)</code>
|
||||
* [.getOperationsByTag([tag])](#SwaggerApi+getOperationsByTag) ⇒ <code>[Array.<Operation>](#Operation)</code>
|
||||
* [.getPath(pathOrReq)](#SwaggerApi+getPath) ⇒ <code>[Path](#Path)</code>
|
||||
* [.getPaths()](#SwaggerApi+getPaths) ⇒ <code>[Array.<Path>](#Path)</code>
|
||||
* [.registerValidator(validator)](#SwaggerApi+registerValidator)
|
||||
* [.validate()](#SwaggerApi+validate) ⇒ <code>object</code>
|
||||
|
||||
<a name="new_SwaggerApi_new"></a>
|
||||
### new SwaggerApi(plugin, definition, resolved, references, options)
|
||||
|
|
|
@ -92,7 +92,7 @@ function SwaggerApi (plugin, definition, resolved, references, options) {
|
|||
this.pathObjects = plugin.getPaths(this);
|
||||
|
||||
// Register custom validators
|
||||
_.forEach(options.validators, this.registerValidator);
|
||||
_.forEach(options.customValidators, SwaggerApi.prototype.registerValidator, this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,6 +55,9 @@ describe('sway (Swagger 2.0)', function () {
|
|||
// Validate the operations (Simple tests for now, deeper testing is below)
|
||||
assert.ok(_.isArray(theApi.pathObjects));
|
||||
assert.ok(theApi.pathObjects.length > 0);
|
||||
|
||||
// Validate the registration of customValidator on SwaggerApi
|
||||
assert.deepEqual(theApi.customValidators, options.customValidators || [])
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -77,7 +80,25 @@ describe('sway (Swagger 2.0)', function () {
|
|||
.then(validateCreateSwaggerApi(options))
|
||||
.then(done, done);
|
||||
});
|
||||
|
||||
|
||||
it('should register customValidators', function (done) {
|
||||
var options = {
|
||||
definition: helpers.swaggerDoc,
|
||||
customValidators: [
|
||||
function validator1 () {
|
||||
return {
|
||||
errors: [],
|
||||
warnings: []
|
||||
};
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
helpers.swaggerApi.create(options)
|
||||
.then(validateCreateSwaggerApi(options))
|
||||
.then(done, done);
|
||||
});
|
||||
|
||||
// TODO: Add test for definition file URL (remote)
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче