Fix function.json parsing for C# functions

They don't require the direction information
This commit is contained in:
Eric Jizba 2018-01-17 16:07:06 -08:00
Родитель 767808b70b
Коммит 198a3486be
2 изменённых файлов: 30 добавлений и 17 удалений

Просмотреть файл

@ -55,29 +55,31 @@ export class FunctionConfig {
this.disabled = data.disabled === true;
// tslint:disable-next-line:no-unsafe-any
if (!data.bindings || !(data.bindings instanceof Array)) {
if (!data.bindings || !(data.bindings instanceof Array) || data.bindings.length === 0) {
errMessage = localize('expectedBindings', 'Expected "bindings" element of type "Array".');
} else {
this.functionJson = <IFunctionJson>data;
const inBinding: IFunctionBinding | undefined = this.functionJson.bindings.find((b: IFunctionBinding) => b.direction === BindingDirection.in);
if (inBinding === undefined) {
errMessage = localize('noInBindingError', 'Expected a binding with direction "in".');
// The generated 'function.json' file for C# class libraries doesn't have direction information (by design), so just use the first
this.inBinding = this.functionJson.bindings[0];
} else {
this.inBinding = inBinding;
if (!inBinding.type) {
errMessage = localize('inBindingTypeError', 'The binding with direction "in" must have a type.');
} else {
this.inBindingType = inBinding.type;
if (inBinding.type.toLowerCase() === 'httptrigger') {
this.isHttpTrigger = true;
if (inBinding.authLevel) {
const authLevel: HttpAuthLevel | undefined = <HttpAuthLevel>HttpAuthLevel[inBinding.authLevel.toLowerCase()];
if (authLevel === undefined) {
errMessage = localize('unrecognizedAuthLevel', 'Unrecognized auth level "{0}".', inBinding.authLevel);
} else {
this.authLevel = authLevel;
}
}
if (!this.inBinding.type) {
errMessage = localize('inBindingTypeError', 'The binding with direction "in" must have a type.');
} else {
this.inBindingType = this.inBinding.type;
if (this.inBinding.type.toLowerCase() === 'httptrigger') {
this.isHttpTrigger = true;
if (this.inBinding.authLevel) {
const authLevel: HttpAuthLevel | undefined = <HttpAuthLevel>HttpAuthLevel[this.inBinding.authLevel.toLowerCase()];
if (authLevel === undefined) {
errMessage = localize('unrecognizedAuthLevel', 'Unrecognized auth level "{0}".', this.inBinding.authLevel);
} else {
this.authLevel = authLevel;
}
}
}

Просмотреть файл

@ -21,10 +21,10 @@ suite('Function Config Tests', () => {
(error: Error) => error.message.includes('bindings')
);
// there's no binding with directon 'in'
// there's no binding
assert.throws(
() => new FunctionConfig({ bindings: [] }),
(error: Error) => error.message.includes('direction') && error.message.includes('in')
(error: Error) => error.message.includes('bindings')
);
// in binding does not have type
@ -125,5 +125,16 @@ suite('Function Config Tests', () => {
assert.equal(config.disabled, false);
assert.equal(config.isHttpTrigger, true);
assert.equal(config.authLevel, HttpAuthLevel.function);
// validate generated function.json that doesn't have 'in' binding
config = new FunctionConfig({
bindings: [{
type: 'httpTrigger',
authLevel: 'function'
}]
});
assert.equal(config.disabled, false);
assert.equal(config.isHttpTrigger, true);
assert.equal(config.authLevel, HttpAuthLevel.function);
});
});