Skip to content

fix C# examples #732

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

Merged
merged 1 commit into from
Jul 10, 2024
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 @@ -1472,19 +1472,7 @@ public void setParameterExampleValue(CodegenParameter p) {
//parameter is enum defined as a schema component
example = "(" + type + ") \"" + example + "\"";
} else if (p.getComposedSchemas() != null) {
if (p.getComposedSchemas().getAnyOf() != null) {
p.getComposedSchemas().getAnyOf().sort((a, b) -> {
if (a.dataType.equals("DateTime")) {
return -1;
}
if (b.dataType.equals("DateTime")) {
return 1;
}
return 0;
});

example = "new " + type + "(" + p.getComposedSchemas().getAnyOf().get(0).example + ")";
}
example = toExampleComposed(p.dataType, p.getComposedSchemas());
} else if (!languageSpecificPrimitives.contains(type)) {
// type is a model class, e.g. User
example = "new " + type + "()";
Expand Down Expand Up @@ -1531,7 +1519,33 @@ protected String toExampleComposed(String dataType, CodegenComposedSchemas compo
return 0;
});

return "new " + dataType + "(" + composedSchema.getAnyOf().get(0).example + ")";
String example = "null";
for (CodegenProperty p : composedSchema.getAnyOf()) {
if (p.example != null && !p.example.equals("null")) {
example = p.example;
break;
}
}
// if none have examples then use a default value if possible
if (example.equals("null")) {
for (CodegenProperty p : composedSchema.getAnyOf()) {
if (p.isNumber) {
example = "100";
break;
}
if (p.isString) {
example = "\"example\"";
break;
}
if (p.isBoolean) {
example = "true";
break;
}
// add more as necessary
}
}

return "new " + dataType + "(" + example + ")";
}
if (composedSchema.getOneOf() != null) {
composedSchema.getOneOf().sort((a, b) -> {
Expand Down
Loading