-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workaround for optional Cookie.expired field
See ChromeDevTools/devtools-protocol#317 Resolves: #494
- Loading branch information
1 parent
dbeb9fc
commit ffdbaac
Showing
8 changed files
with
90 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...hrome/devtools/protocol/json/EnumFixer.kt → ...tools/protocol/preprocessing/EnumFixer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...tor/src/main/kotlin/org/hildan/chrome/devtools/protocol/preprocessing/JsonPreProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.hildan.chrome.devtools.protocol.preprocessing | ||
|
||
import org.hildan.chrome.devtools.protocol.json.JsonDomain | ||
import org.hildan.chrome.devtools.protocol.json.JsonDomainParameter | ||
import org.hildan.chrome.devtools.protocol.json.JsonDomainType | ||
|
||
/** | ||
* Pre-processes the list of domains from the JSON definitions to work around some issues in the definitions themselves. | ||
*/ | ||
internal fun List<JsonDomain>.preprocessed(): List<JsonDomain> = this | ||
// Workaround for https://github.com/ChromeDevTools/devtools-protocol/issues/317 | ||
.transformDomainTypeProperty("Network", "Cookie", "expires") { it.copy(optional = true) } | ||
// Workaround for https://github.com/ChromeDevTools/devtools-protocol/issues/244 | ||
.map { it.pullNestedEnumsToTopLevel() } | ||
|
||
private fun List<JsonDomain>.transformDomainTypeProperty( | ||
domain: String, | ||
type: String, | ||
property: String, | ||
transform: (JsonDomainParameter) -> JsonDomainParameter, | ||
): List<JsonDomain> = transformDomain(domain) { d -> | ||
d.transformType(type) { t -> | ||
t.transformProperty(property, transform) | ||
} | ||
} | ||
|
||
private fun List<JsonDomain>.transformDomain( | ||
name: String, | ||
transform: (JsonDomain) -> JsonDomain, | ||
): List<JsonDomain> = transformIf({ it.domain == name }) { transform(it) } | ||
|
||
private fun JsonDomain.transformType( | ||
name: String, | ||
transform: (JsonDomainType) -> JsonDomainType, | ||
): JsonDomain = copy(types = types.transformIf({ it.id == name }) { transform(it) }) | ||
|
||
private fun JsonDomainType.transformProperty( | ||
name: String, | ||
transform: (JsonDomainParameter) -> JsonDomainParameter, | ||
): JsonDomainType = copy(properties = properties.transformIf({ it.name == name }) { transform(it) }) | ||
|
||
private fun <T> List<T>.transformIf(predicate: (T) -> Boolean, transform: (T) -> T): List<T> = | ||
map { if (predicate(it)) transform(it) else it } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters