Skip to content

Add support for parameters.allowEmptyValue #141

Description

@ahenket

Reading up in the openapi specs I also came across allowEmptyValue which by default is false. This is not enforced by roaster at all yet and doing so would be a major breaking change for people who do not specify allowEmptyValue yet.

But it is useful to specify not to use a parameter OR to have a value for it.

How this could work in a non-breaking way in parameters:retrieve#1. Doesn't take this into account yet.

If style is used, and if behavior is n/a (cannot be serialized), the value of allowEmptyValue SHALL be ignored.

declare %private function parameters:retrieve ($parameter as map(*)) as map(*)? {
    if (parameters:is-path-parameter($parameter))
    then ()
    else
        let $name := $parameter?name
        let $default := parameters:get-parameter-default-value($parameter?schema)
        let $needsValue := exists($parameter?allowEmptyValue[. = false()])
        let $values := 
            switch ($parameter?in)
            (: TODO case "body" :)
            case "header" return
                head((request:get-header($name), $default))
            case "cookie" return
                head((request:get-cookie-value($name), $default))
            default return
                request:get-parameter($name, $default)

        return
            if ($parameter?required and empty($values)) then
                error($errors:REQUIRED_PARAM, "Parameter " || $name || " is required")
            else
            if ($needsValue and exists($values[string-length() = 0])) then
                error($errors:REQUIRED_PARAM, "Parameter " || $name || " needs a value when present")
            else
                map { $name : parameters:cast($values, $parameter) }
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions