kotlin-webextensions-declarations
kotlin-webextensions-declarations copied to clipboard
webRequest.onAuthRequired.addListener takes multiple arguments
It takes filter and extraInfoSpec. Also, the function in the listener should return a webRequest.BlockingResponse or a Promise
The current declarations only allow adding a listener that returns nothing.
The schema for onAuthRequired is rather complicated
{
"name": "onAuthRequired",
"type": "function",
"description": "...",
"parameters": [
{
"type": "object",
"name": "details",
"properties": {
...
}
},
{
"type": "function",
"optional": true,
"name": "callback",
"parameters": [
{"name": "response", "$ref": "BlockingResponse"}
]
}
],
"extraParameters": [
{
"$ref": "RequestFilter",
"name": "filter",
"description": "A set of filters that restricts the events that will be sent to this listener."
},
{
"type": "array",
"optional": true,
"name": "extraInfoSpec",
"description": "Array of extra information that should be passed to the listener function.",
"items": {
"$ref": "OnAuthRequiredOptions"
}
}
],
"returns": {
"$ref": "BlockingResponse",
"description": "If \"blocking\" is specified in the \"extraInfoSpec\" parameter, the event listener should return an object of this type.",
"optional": true
}
}
The extraParameters field is currently not parsed at all.
@deepanshu-zendrive How would you imagine the signature of the Kotlin declaration too look like?
Maybe something like:
onAuthRequired.addListener(callback: (Details) -> BlockingResponse?,
filter: RequestFilter,
extraInfoSpec: Array<String>?)
And another similar overload for Promise. The classes for RequestFilter, Details and BlockingResponse are same as what's generated in the current version
A dirty fix would be something like
FunSpec.builder("addListener")
.addModifiers(KModifier.EXTERNAL)
.addParameter(ParameterSpec.builder("listener", TypeVariableName("T")).build())
.addParameter(
ParameterSpec.builder(
"filter", ClassName.bestGuess("webRequest.RequestFilter")
).defaultValue("%L", "definedExternally").build()
)
.addParameter(
ParameterSpec.builder(
"extraInfoSpec", Array::class.asTypeName().parameterizedBy(String::class.asTypeName())
).defaultValue("%L", "definedExternally").build()
)
.returns(ClassName.bestGuess("webRequest.BlockingResponse").copy(nullable = true))
.build()
in Generator.kt