mirror of https://github.com/halo-dev/halo
Fix the problem of inconsistent OpenAPI generation (#3954)
#### What type of PR is this? /kind bug /area core /milestone 2.6.x #### What this PR does / why we need it: Sort properties before building. #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/3944 #### Special notes for your reviewer: Try to generate api client several times. #### Does this PR introduce a user-facing change? ```release-note None ```pull/3941/head
parent
136bd4e91f
commit
88597ac137
|
@ -40,29 +40,33 @@ public final class QueryParamBuildUtil {
|
||||||
var properties = (Map<String, Schema>) resolvedSchema.schema.getProperties();
|
var properties = (Map<String, Schema>) resolvedSchema.schema.getProperties();
|
||||||
var requiredNames = defaultIfNull(resolvedSchema.schema.getRequired(),
|
var requiredNames = defaultIfNull(resolvedSchema.schema.getRequired(),
|
||||||
Collections.emptyList());
|
Collections.emptyList());
|
||||||
properties.forEach((propName, propSchema) -> {
|
properties.keySet()
|
||||||
final var paramBuilder = parameterBuilder().in(ParameterIn.QUERY);
|
.stream()
|
||||||
paramBuilder.name(propSchema.getName())
|
.sorted()
|
||||||
.description(propSchema.getDescription())
|
.forEach(propName -> {
|
||||||
.style(ParameterStyle.FORM)
|
var propSchema = properties.get(propName);
|
||||||
.explode(Explode.TRUE);
|
final var paramBuilder = parameterBuilder().in(ParameterIn.QUERY);
|
||||||
if (requiredNames.contains(propSchema.getName())) {
|
paramBuilder.name(propSchema.getName())
|
||||||
paramBuilder.required(true);
|
.description(propSchema.getDescription())
|
||||||
}
|
.style(ParameterStyle.FORM)
|
||||||
|
.explode(Explode.TRUE);
|
||||||
|
if (requiredNames.contains(propSchema.getName())) {
|
||||||
|
paramBuilder.required(true);
|
||||||
|
}
|
||||||
|
|
||||||
if (propSchema instanceof ArraySchema arraySchema) {
|
if (propSchema instanceof ArraySchema arraySchema) {
|
||||||
paramBuilder.array(arraySchemaBuilder()
|
paramBuilder.array(arraySchemaBuilder()
|
||||||
.uniqueItems(defaultIfNull(arraySchema.getUniqueItems(), false))
|
.uniqueItems(defaultIfNull(arraySchema.getUniqueItems(), false))
|
||||||
.minItems(defaultIfNull(arraySchema.getMinItems(), 0))
|
.minItems(defaultIfNull(arraySchema.getMinItems(), 0))
|
||||||
.maxItems(defaultIfNull(arraySchema.getMaxItems(), Integer.MAX_VALUE))
|
.maxItems(defaultIfNull(arraySchema.getMaxItems(), Integer.MAX_VALUE))
|
||||||
.arraySchema(convertSchemaBuilder(arraySchema))
|
.arraySchema(convertSchemaBuilder(arraySchema))
|
||||||
.schema(convertSchemaBuilder(arraySchema.getItems()))
|
.schema(convertSchemaBuilder(arraySchema.getItems()))
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
paramBuilder.schema(convertSchemaBuilder(propSchema));
|
paramBuilder.schema(convertSchemaBuilder(propSchema));
|
||||||
}
|
}
|
||||||
operationBuilder.parameter(paramBuilder);
|
operationBuilder.parameter(paramBuilder);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static org.springdoc.core.fn.builders.schema.Builder convertSchemaBuilder(
|
private static org.springdoc.core.fn.builders.schema.Builder convertSchemaBuilder(
|
||||||
|
|
Loading…
Reference in New Issue