<commit_before>package org.reekwest.http.contract.module

import org.reekwest.http.contract.module.PathBinder.Companion.Core
import org.reekwest.http.core.ContentType
import org.reekwest.http.core.Filter
import org.reekwest.http.core.HttpMessage
import org.reekwest.http.core.Method
import org.reekwest.http.core.Request
import org.reekwest.http.core.Response
import org.reekwest.http.core.Status
import org.reekwest.http.lens.BodyLens
import org.reekwest.http.lens.Failure
import org.reekwest.http.lens.HeaderLens
import org.reekwest.http.lens.Lens
import org.reekwest.http.lens.LensFailure
import org.reekwest.http.lens.QueryLens

data class RouteResponse(val status: Status, val description: String?, val example: String?)

class Route private constructor(internal val core: Core) {
    constructor(name: String, description: String? = null) : this(Core(name, description, null))

    fun header(new: HeaderLens<*>) = Route(core.copy(requestParams = core.requestParams.plus(new)))
    fun query(new: QueryLens<*>) = Route(core.copy(requestParams = core.requestParams.plus(new)))
    fun body(new: Lens<HttpMessage, *>) = Route(core.copy(body = new))
    fun returning(new: Status) = Route(core.copy(responses = core.responses.plus(Response(new))))
    fun producing(vararg new: ContentType) = Route(core.copy(produces = core.produces.plus(new)))
    fun consuming(vararg new: ContentType) = Route(core.copy(consumes = core.consumes.plus(new)))

    infix fun at(method: Method): PathBinder0 = PathBinder0(Core(this, method, { it }))

    internal val validationFilter = Filter {
        next ->
        {
            val errors = core.fold(emptyList<Failure>()) { memo, next ->
                try {
                    next(it)
                    memo
                } catch (e: LensFailure) {
                    memo.plus(e.failures)
                }
            }
            if (errors.isEmpty()) next(it) else throw LensFailure(errors)
        }
    }

    companion object {
        internal data class Core(val summary: String,
                                 val description: String?,
                                 val body: BodyLens<*>?,
                                 val produces: Set<ContentType> = emptySet(),
                                 val consumes: Set<ContentType> = emptySet(),
                                 val requestParams: List<Lens<Request, *>> = emptyList(),
                                 val responses: List<Response> = emptyList()) : Iterable<Lens<Request, *>> {

            override fun iterator(): Iterator<Lens<Request, *>> = requestParams.plus(body?.let { listOf(it) } ?: emptyList<Lens<Request, *>>()).iterator()
        }
    }
}<commit_msg>work on Swagger<commit_after>package org.reekwest.http.contract.module

import org.reekwest.http.contract.module.PathBinder.Companion.Core
import org.reekwest.http.core.ContentType
import org.reekwest.http.core.Filter
import org.reekwest.http.core.HttpMessage
import org.reekwest.http.core.Method
import org.reekwest.http.core.Request
import org.reekwest.http.core.Response
import org.reekwest.http.core.Status
import org.reekwest.http.lens.BodyLens
import org.reekwest.http.lens.Failure
import org.reekwest.http.lens.HeaderLens
import org.reekwest.http.lens.Lens
import org.reekwest.http.lens.LensFailure
import org.reekwest.http.lens.QueryLens

class Route private constructor(internal val core: Core) {
    constructor(name: String, description: String? = null) : this(Core(name, description, null))

    fun header(new: HeaderLens<*>) = Route(core.copy(requestParams = core.requestParams.plus(new)))
    fun query(new: QueryLens<*>) = Route(core.copy(requestParams = core.requestParams.plus(new)))
    fun body(new: Lens<HttpMessage, *>) = Route(core.copy(body = new))

    @JvmName("returningResponse")
    fun returning(new: Pair<String, Response>) = Route(core.copy(responses = core.responses.plus(new)))

    @JvmName("returningStatus")
    fun returning(new: Pair<String, Status>) = Route(core.copy(responses = core.responses.plus(new.first to Response(new.second))))

    fun producing(vararg new: ContentType) = Route(core.copy(produces = core.produces.plus(new)))
    fun consuming(vararg new: ContentType) = Route(core.copy(consumes = core.consumes.plus(new)))

    infix fun at(method: Method): PathBinder0 = PathBinder0(Core(this, method, { it }))

    internal val validationFilter = Filter {
        next ->
        {
            val errors = core.fold(emptyList<Failure>()) { memo, next ->
                try {
                    next(it)
                    memo
                } catch (e: LensFailure) {
                    memo.plus(e.failures)
                }
            }
            if (errors.isEmpty()) next(it) else throw LensFailure(errors)
        }
    }

    companion object {
        internal data class Core(val summary: String,
                                 val description: String?,
                                 val body: BodyLens<*>?,
                                 val produces: Set<ContentType> = emptySet(),
                                 val consumes: Set<ContentType> = emptySet(),
                                 val requestParams: List<Lens<Request, *>> = emptyList(),
                                 val responses: List<Pair<String, Response>> = emptyList()) : Iterable<Lens<Request, *>> {

            override fun iterator(): Iterator<Lens<Request, *>> = requestParams.plus(body?.let { listOf(it) } ?: emptyList<Lens<Request, *>>()).iterator()
        }
    }
}
{'fraction_non_alphanumeric': 0.12343891402714932, 'fraction_numerical': 0.0007239819004524887, 'mean_word_length': 2.6475247524752477, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4942735', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1566, 'n_words': 319}