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

[Bug][Go] consider allOf schemas for rendering string default vaules #14684

Merged
merged 1 commit into from
Feb 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,29 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
}
}

/**
* Determines if at least one of the allOf pieces of a schema are of type string
*
* @param p
* @return
*/
private boolean isAllOfStringSchema(Schema schema) {
if (schema.getAllOf() != null) {
Iterator<Schema> it = schema.getAllOf().iterator();
while (it.hasNext()) {
Schema childSchema = ModelUtils.getReferencedSchema(this.openAPI, it.next());
if (ModelUtils.isStringSchema(childSchema)) {
return true;
}
}
}
return false;
}

@Override
public String toDefaultValue(Schema p) {
p = ModelUtils.getReferencedSchema(this.openAPI, p);
if (ModelUtils.isStringSchema(p)) {
if (ModelUtils.isStringSchema(p) || isAllOfStringSchema(p)) {
Object defaultObj = p.getDefault();
if (defaultObj != null) {
if (defaultObj instanceof java.lang.String) {
Expand Down