diff --git a/application/src/main/java/org/thingsboard/server/config/SwaggerConfiguration.java b/application/src/main/java/org/thingsboard/server/config/SwaggerConfiguration.java index e33c699311..db2fba022f 100644 --- a/application/src/main/java/org/thingsboard/server/config/SwaggerConfiguration.java +++ b/application/src/main/java/org/thingsboard/server/config/SwaggerConfiguration.java @@ -301,6 +301,25 @@ public class SwaggerConfiguration { schema.setProperties(null); } } + } else if (schema != null && schema.getProperties() != null && !schema.getProperties().isEmpty()) { + try { + var beanDesc = Json.mapper().getSerializationConfig().introspect(javaType); + var orderedNames = beanDesc.findProperties().stream() + .map(p -> p.getName()) + .toList(); + if (!orderedNames.isEmpty()) { + Map current = schema.getProperties(); + var reordered = new LinkedHashMap(); + for (String name : orderedNames) { + Object prop = current.get(name); + if (prop != null) reordered.put(name, prop); + } + current.forEach((k, v) -> reordered.putIfAbsent(k, v)); + schema.setProperties(reordered); + } + } catch (Exception ignored) { + // keep original order if introspection fails + } } } return schema; @@ -627,7 +646,7 @@ public class SwaggerConfiguration { ThingsboardErrorResponse.of("Authentication failed", ThingsboardErrorCode.AUTHENTICATION, HttpStatus.UNAUTHORIZED))); unauthorizedExamples.put("credentials-expired", errorExample("Expired credentials", - ThingsboardCredentialsExpiredResponse.of("User password expired!", StringUtils.randomAlphanumeric(30)))); + ThingsboardCredentialsExpiredResponse.of("User password expired!", "udgDQOpS1Q4ZFEL8qHF9s8cSKQ7d1h"))); Schema unauthorizedSchema = new Schema<>(); unauthorizedSchema.oneOf(List.of(