feat: allow empty string as defaultValue in @Schema#4974
feat: allow empty string as defaultValue in @Schema#4974juntae6942 wants to merge 2 commits intoswagger-api:masterfrom
Conversation
Signed-off-by: potato <65760583+juntae6942@users.noreply.github.com>
|
@juntae6942 thank you for your contribution. There are errors in your PR. Are you able to fix them? |
|
daniel-kmiecik I’m working on the fix, but I’m running into some difficulties. Could you please provide me with some help? |
|
Also, I'm facing an issue with the hasSchemaAnnotation method. For a schema where only the defaultValue is specified, simply removing the StringUtils.isBlank(schema.defaultValue()) check isn't enough. The method still incorrectly flags it as an empty annotation because all the other conditions are met. I'm trying to figure out the best way to solve this |
|
Hi @juntae6942, |
|
I’ve also looked into that part, and since many changes would likely affect the test code, I agree with MichakrawSB’s opinion. I’ll proceed with additional work once you get in touch. |

Pull Request
Thank you for contributing to swagger-core!
Please fill out the following information to help us review your PR efficiently.
Description
This PR addresses the behavior where a
defaultValueset to an empty string ("") on a@Schemaannotation is ignored and not included in the generated OpenAPI specification.defaultValue = ""is treated the same as having nodefaultValueat all. This can cause problems for code generation tools (like for Dart or other languages) that rely on the presence of thedefaultValueproperty to differentiate optional fields from required ones.feat). It improves an existing behavior to better align with developer expectations and broader tool compatibility.Closes: #4838 (This is the issue you provided in the previous prompt)
Type of Change
Checklist
Screenshots / Additional Context
AnnotationsUtils.javato processdefaultValueproperties even when they contain a blank or empty string. The conditionif (StringUtils.isNotBlank(schema.defaultValue()))is updated to a less restrictive check, such asif (schema.defaultValue() != null).emptyDefaultValue) that verifies the correct behavior.