metosin / metosin/compojure-api

How do I specify an optional field when accepting multipart-params for a request?

Open
#460 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Clojure
Stars
1.1k
Forks
146
PR merge metrics
No merged PRs in 30d

Description

Library Version(s)

2.0.0-alpha31

Problem

(POST "/test-route" request
     :multipart-params [optional_data :- s/Str]
     :middleware [admin-rbac upload/wrap-multipart-params]
     (res/ok "ok"))

In this example, optional_data is not a mandatory argument. How do I tell the framework to accept requests which do not provide this field. I've tried these and they don't work:

...
:multipart-params [optional_data :- s/Str nil]
...
...
:multipart-params [optional_data :- (s/maybe s/Str)]
...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the route using :multipart-params and the upload/wrap-multipart-params middleware described in the issue, on version 2.0.0-alpha31. Read the multipart parameter handling and schema validation entry points to determine whether an omitted optional_data field is supported; done means identifying the accepted syntax or documenting the missing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.