Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defaut mapping to RequstBody #44

Open
rafalkrupinski opened this issue Jan 14, 2024 · 2 comments
Open

Add defaut mapping to RequstBody #44

rafalkrupinski opened this issue Jan 14, 2024 · 2 comments

Comments

@rafalkrupinski
Copy link
Contributor

rafalkrupinski commented Jan 14, 2024

The typical usage of RequestBody annotation is:

body: Annotated(RequestBodyType, RequestBody({'application/json': RequestBodyType}))

with a single key-value pair, where

  • RequestBodyType is a concrete, non-Union, possibly Optional, model type
  • the key is typically 'application/json'

These alternative shortcut forms could be allowed, to better support human authors:

body: Annotated(RequestBodyType, RequestBody())  # only accept 'application/json' and map the body to ResultType

body: Annotated(RequestBodyType, RequestBody('application/json'))  # only accept the given media type, and map to ResultType
@rafalkrupinski
Copy link
Contributor Author

rafalkrupinski commented Jan 14, 2024

Same for maps in Responses/code maps:

Responses({
            '200': {
                'application/json': ResultType,
            }
        })
# same as 
Responses({
            '200': ResultType,
            }
        })

Not adding option of omitting the response code, to encourage declaring errors.

@rafalkrupinski
Copy link
Contributor Author

rafalkrupinski commented Jul 28, 2024

Lapidary shouldn't read type hints, only WebArg annotations.

Annotated[ResultType, Responses({'200': ResultType})] # OK - matches content-type: application/json
Annotated(RequestBodyType, Body(RequestBodyType) # OK - sends content-type: application/json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant