Skip to content

Conversation

juntae6942
Copy link

@juntae6942 juntae6942 commented Sep 18, 2025

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 defaultValue set to an empty string ("") on a @Schema annotation is ignored and not included in the generated OpenAPI specification.

  • What problem does it solve? This resolves an inconsistency where defaultValue = "" is treated the same as having no defaultValue at all. This can cause problems for code generation tools (like for Dart or other languages) that rely on the presence of the defaultValue property to differentiate optional fields from required ones.
  • Is it a bug fix, new feature, or refactor? This is best described as a feature enhancement (feat). It improves an existing behavior to better align with developer expectations and broader tool compatibility.
  • Link to any related issues. This PR is related to several community discussions and issues regarding the handling of empty strings as default values.

Closes: #4838 (This is the issue you provided in the previous prompt)

Type of Change

  • 🐛 Bug fix
  • New feature
  • ♻️ Refactor (non-breaking change)
  • 🧪 Tests
  • 📝 Documentation
  • 🧹 Chore (build or tooling)

Checklist

  • I have added/updated tests as needed
  • I have added/updated documentation where applicable
  • The PR title is descriptive
  • The code builds and passes tests locally
  • I have linked related issues (if any)

Screenshots / Additional Context

  • This change modifies AnnotationsUtils.java to process defaultValue properties even when they contain a blank or empty string. The condition if (StringUtils.isNotBlank(schema.defaultValue())) is updated to a less restrictive check, such as if (schema.defaultValue() != null).
  • I have included a new test case (emptyDefaultValue) that verifies the correct behavior.
  • The change is non-breaking and improves compatibility with downstream tools.

@daniel-kmiecik
Copy link
Collaborator

@juntae6942 thank you for your contribution. There are errors in your PR. Are you able to fix them?

@juntae6942
Copy link
Author

daniel-kmiecik I’m working on the fix, but I’m running into some difficulties. Could you please provide me with some help?

@juntae6942
Copy link
Author

juntae6942 commented Sep 18, 2025

daniel-kmiecik

@Schema(implementation = Integer.class)
@Schema(type = “string”)

when no defaultValue is specified, I believe the defaultValue is treated as "". However, the current test code does not include default: "", which leads to errors. I’d like to ask whether it would be acceptable to update the test code accordingly.
스크린샷 2025-09-18 오후 6 21 07
This causes issues in several tests.

@juntae6942
Copy link
Author

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

@MichakrawSB
Copy link

Hi @juntae6942,
Thanks a lot for working on this enhancement! 🙌
We'd like to hold off on reviewing/merging this for now, as we need to check how it may impact other repositories in the Swagger ecosystem.
We'll get back to you once we've completed that assessment. Your contribution is appreciated, and we hope you'll continue to share improvements with the project!

@juntae6942
Copy link
Author

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.

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

Successfully merging this pull request may close these issues.

Empty default values are ignored
3 participants