Skip to content

Commit

Permalink
Binding mapping issue fix, blob output, auto-generating HttpResponse …
Browse files Browse the repository at this point in the history
…binding when it's missing (#4)

* Binding mapping issue fix that affecting blob output.
* Auto-generating HttpResponse binding when it's missing 
* Bug fixes
  • Loading branch information
SalehAlbuga authored Dec 7, 2019
1 parent 8daca70 commit 6dd3fb1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
7 changes: 4 additions & 3 deletions Sources/AzureFunctions/AzureFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ internal extension Function {

for binding in outputBindings {
bindings.append(try (binding as! BindingCapability).jsonDescription(direction: .output))

}

if trigger is HttpRequest && outputBindings.count == 0 {
bindings.append(try HttpResponse().jsonDescription(direction: .output))
if trigger is HttpRequest && (outputBindings.count == 0 || !outputBindings.contains { (binding) -> Bool in
return binding is HttpResponse
}) {
bindings.append(try HttpResponse(bindingName: "$return").jsonDescription(direction: .output))
}

let dic: [String : Any] = ["generatedBy": "azure-functions-swift",
Expand Down
2 changes: 1 addition & 1 deletion Sources/AzureFunctions/Bindings/BindingFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal final class BindingFactory {
case _ as Queue, _ as Table:
return nil
default:
throw FunctionError.internalInconsistancyException("Cannot build binding for type of '\(binding.name)'")
throw FunctionError.internalInconsistancyException("Cannot build binding for type of '\(binding.name)', type unsupported")
}
}

Expand Down
5 changes: 0 additions & 5 deletions Sources/AzureFunctions/CodeGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ internal struct CodeGen {
} else {
localSetRes = try environment.renderTemplate(string: Templates.ProjectFiles.localSettingsJson, context: nil)
}
// if let storage = registry.AzureWebJobsStorage {
// localSetRes = try environment.renderTemplate(string: Templates.ProjectFiles.localSettingsJson, context: ["envVars": "\"AzureWebJobsStorage\": \"\(storage)\""])
// } else {
// localSetRes = try environment.renderTemplate(string: Templates.ProjectFiles.localSettingsJson, context: nil)
// }

let localSetFile = try rootFolder.createFile(named: "local.settings.json")
try localSetFile.write(localSetRes)
Expand Down
7 changes: 7 additions & 0 deletions Sources/AzureFunctions/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public final class Context {

internal init () { }

internal func prepBindings() {
self.bindings = inputBindings
self.bindings.merge(self.outputBindings) { (current, _) -> Any in
current
}
}

public func log(_ message: String) {
Logger.log(message)
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/AzureFunctions/WorkerChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ extension WorkerChannel {
context!.bindings[http] = httpRes
}

context!.prepBindings()

res.outputData = functionInfo.outputBindings
.filter({ (key, val) -> Bool in
return context!.bindings[key] != nil
Expand Down

0 comments on commit 6dd3fb1

Please sign in to comment.