Browse Source

Fix OpenAPI schemas that generated REST clients could not use

The document is OpenAPI 3.1, which writes Schema.types, but registerSchema
resolved classes with the OpenAPI 3.0 ModelConverters instance, so
LoginRequest, LoginResponse, ThingsboardErrorResponse and
ThingsboardCredentialsExpiredResponse lost "type": "object". The
/api/auth/token request body had no types either, so refreshToken was
untyped. ColumnSettings declares allOf DataKeySettings explicitly, so it
stays a DataKeySettings subtype however springdoc reaches it first.
pull/16510/head
Vladyslav_Prykhodko 4 weeks ago
parent
commit
908655b3da
  1. 5
      application/src/main/java/org/thingsboard/server/config/SwaggerConfiguration.java
  2. 5
      common/data/src/main/java/org/thingsboard/server/common/data/report/configuration/ColumnSettings.java

5
application/src/main/java/org/thingsboard/server/config/SwaggerConfiguration.java

@ -269,7 +269,8 @@ public class SwaggerConfiguration {
var requestBody = new RequestBody().description("Refresh token request")
.content(new Content().addMediaType(APPLICATION_JSON_VALUE,
new MediaType().schema(new Schema<JsonNode>().addProperty("refreshToken", new Schema<>().type("string")))));
new MediaType().schema(new Schema<JsonNode>().types(Set.of("object"))
.addProperty("refreshToken", new Schema<>().types(Set.of("string"))))));
operation.requestBody(requestBody);
@ -378,7 +379,7 @@ public class SwaggerConfiguration {
}
private static void registerSchema(Components components, String name, Class<?> cls) {
ResolvedSchema resolved = ModelConverters.getInstance()
ResolvedSchema resolved = ModelConverters.getInstance(true)
.readAllAsResolvedSchema(new AnnotatedType().type(cls));
components.addSchemas(name, resolved.schema);
if (resolved.referencedSchemas != null) {

5
common/data/src/main/java/org/thingsboard/server/common/data/report/configuration/ColumnSettings.java

@ -2,9 +2,14 @@
// SPDX-License-Identifier: BUSL-1.1
package org.thingsboard.server.common.data.report.configuration;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.thingsboard.server.common.data.report.configuration.style.DataKeySettingsType;
// allOf is explicit because ColumnSettings is also a field type
// (TimeseriesTableComponent.timestampColumnSettings): resolved there first, it
// lost the DataKeySettings parent and generated clients did not treat it as one.
@Schema(allOf = DataKeySettings.class)
@Data
public class ColumnSettings implements DataKeySettings {

Loading…
Cancel
Save