Add minimal Kotlin DSL RouterFunction attributes support

Closes gh-28567
This commit is contained in:
christophejan
2022-06-05 18:51:15 +02:00
committed by Arjen Poutsma
parent 5b1bda5c7c
commit bbabf8d855
6 changed files with 222 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -699,6 +699,30 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
builder.onError({it is E}, responseProvider)
}
/**
* Add an attribute with the given name and value to the last route built with this builder.
* @param name the attribute name
* @param value the attribute value
* @since 5.3
*/
fun withAttribute(name: String, value: Any) {
builder.withAttribute(name, value)
}
/**
* Manipulate the attributes of the last route built with the given consumer.
*
* The map provided to the consumer is "live", so that the consumer can be used
* to [overwrite][Map.put] existing attributes,
* [remove][Map.remove] attributes, or use any of the other
* [Map] methods.
* @param attributesConsumer a function that consumes the attributes map
* @since 5.3
*/
fun withAttributes(attributesConsumer: (MutableMap<String, Any>) -> Unit) {
builder.withAttributes(attributesConsumer)
}
/**
* Return a composed routing function created from all the registered routes.
*/