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

This commit is contained in:
Justin Sherrill 2023-02-17 22:07:09 -05:00 committed by GitHub
parent 7968349991
commit e9f55c0dd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -387,10 +387,29 @@ public class GoClientCodegen extends AbstractGoCodegen {
}
}
/**
* 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) {