Browse Source

swagger improvements

pull/14929/head
dashevchenko 7 months ago
parent
commit
ed7ccae66c
  1. 12
      application/src/main/java/org/thingsboard/server/config/SwaggerConfiguration.java
  2. 11
      application/src/main/java/org/thingsboard/server/controller/EntityRelationController.java

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

@ -33,6 +33,7 @@ import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License; import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.media.Content; import io.swagger.v3.oas.models.media.Content;
import io.swagger.v3.oas.models.media.IntegerSchema;
import io.swagger.v3.oas.models.media.MediaType; import io.swagger.v3.oas.models.media.MediaType;
import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.RequestBody; import io.swagger.v3.oas.models.parameters.RequestBody;
@ -73,7 +74,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@ -280,8 +280,14 @@ public class SwaggerConfiguration {
JavaType javaType = Json.mapper().constructType(type.getType()); JavaType javaType = Json.mapper().constructType(type.getType());
if (javaType != null) { if (javaType != null) {
Class<?> cls = javaType.getRawClass(); Class<?> cls = javaType.getRawClass();
if (AtomicInteger.class.isAssignableFrom(cls)) { Schema<?> atomicSchema = switch (cls.getName()) {
return new Schema<>().type("integer").format("int32"); case "java.util.concurrent.atomic.AtomicInteger" -> new IntegerSchema().format("int32");
case "java.util.concurrent.atomic.AtomicLong" -> new IntegerSchema().format("int64");
case "com.google.common.util.concurrent.AtomicDouble" -> new IntegerSchema().format("double");
default -> null;
};
if (atomicSchema != null) {
return atomicSchema;
} }
} }
if (chain.hasNext()) { if (chain.hasNext()) {

11
application/src/main/java/org/thingsboard/server/controller/EntityRelationController.java

@ -73,24 +73,21 @@ public class EntityRelationController extends BaseController {
"If the user has the authority of 'Tenant Administrator', the server checks that the entity is owned by the same tenant. " + "If the user has the authority of 'Tenant Administrator', the server checks that the entity is owned by the same tenant. " +
"If the user has the authority of 'Customer User', the server checks that the entity is assigned to the same customer."; "If the user has the authority of 'Customer User', the server checks that the entity is assigned to the same customer.";
@ApiOperation(value = "Create Relation (saveRelation)", @Hidden
notes = "Creates or updates a relation between two entities in the platform. " +
"Relations unique key is a combination of from/to entity id and relation type group and relation type. " +
SECURITY_CHECKS_ENTITIES_DESCRIPTION)
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@PostMapping(value = "/relation") @PostMapping(value = "/relation")
public void saveRelation(@Parameter(description = "A JSON value representing the relation.", required = true) public void saveRelationV1(@Parameter(description = "A JSON value representing the relation.", required = true)
@RequestBody EntityRelation relation) throws ThingsboardException { @RequestBody EntityRelation relation) throws ThingsboardException {
doSave(relation); doSave(relation);
} }
@ApiOperation(value = "Create Relation (saveRelationAndReturn)", @ApiOperation(value = "Create Relation (saveRelation)",
notes = "Creates or updates a relation between two entities in the platform. " + notes = "Creates or updates a relation between two entities in the platform. " +
"Relations unique key is a combination of from/to entity id and relation type group and relation type. " + "Relations unique key is a combination of from/to entity id and relation type group and relation type. " +
SECURITY_CHECKS_ENTITIES_DESCRIPTION) SECURITY_CHECKS_ENTITIES_DESCRIPTION)
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@PostMapping(value = "/v2/relation") @PostMapping(value = "/v2/relation")
public EntityRelation saveRelationAndReturn(@Parameter(description = "A JSON value representing the relation.", required = true) public EntityRelation saveRelation(@Parameter(description = "A JSON value representing the relation.", required = true)
@RequestBody EntityRelation relation) throws ThingsboardException { @RequestBody EntityRelation relation) throws ThingsboardException {
return doSave(relation); return doSave(relation);
} }

Loading…
Cancel
Save