-
Notifications
You must be signed in to change notification settings - Fork 422
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
codegen: Support default values in schema objects #3614
codegen: Support default values in schema objects #3614
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! What would happen for nested fields with default values? Would they just be ignored, or should we expect some errors?
openapi-codegen/core/src/main/scala/sttp/tapir/codegen/ClassDefinitionGenerator.scala
Outdated
Show resolved
Hide resolved
In general nested fields would only work if the actual type was the guessed type from parsing the default value. I think the |
Thank for clarifying. I'm ok with going forward with this solution. In case we have users with really sophisticated schemas not covered by this, the implementation could be revisited for enhancements, but IMO the current scope is good enough :) |
f96bfcb
to
8ff8e9f
Compare
Edit: I took a look at making it more principled, and actually it wasn't too nightmarish in the end. It should now handle complex default values, and the choice of repr for 'stringy' values is now considerably less arbitrary. I think it looks a lot nicer now. |
openapi-codegen/core/src/main/scala/sttp/tapir/codegen/openapi/models/RenderableModels.scala
Outdated
Show resolved
Hide resolved
Excellent, thank you for this contribution @hughsimpson! |
Adds support for default values in schema objects. Actually just adds the default value to the constructed case class and expects the json lib to handle the rest of the functionality. Optional fields with no explicit default in the schema are treated as having a default of
None
. Constructing the representation of default values traverses the schema tree, and so should generate valid syntax for all currently supported spec objects.