softwaremill / softwaremill/tapir

[Feature Request] codegen: add support for default values in parameters

Open
#5,490 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
1.5k
Forks
468
Avg merge
5h 37m
Merged PRs (30d)
34

Description

Hello maintainers.

First of all thank you for the great work on codegen, it is nice having such a tool in Scala.

While experimenting with it, I found that default values work perfectly for request bodies, but are ignored in parameters (query, headers, path).

Adding such support would be nice, and make for a more coherent experience across the different openapi items.

I did not find it clear if I should open an issue before opening a PR, but I have worked on adding this support in my fork. The included swagger can be used to reproduce the issue (no default value in the generated code).

This is a proposal and maybe you have a better way of implementing it with your knowledge of the code base, as adding support for basic schemas was pretty trivial, but handling schema refs required more substantial changes, and this may need a better refacto than what I submitted, hence why i separated it in two commits.

Thanks for your time, and please let me know if you want me to open the PR.

Contributor guide

No contributing guide indexed for this repository

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

Start with openapi-codegen/sbt-plugin/src/sbt-test/sbt-openapi-codegen/param-default-support/swagger.yaml and use it to reproduce the missing defaults in generated parameter code. Compare the implementation in the linked fork, including its handling of basic schemas and schema refs; done means query, header, and path parameters preserve their OpenAPI default values.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, scala
Domain
backend-api-design, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.