我在 InfluxDB 前面有一个 NestJS API。在 API 中,我想通过来自 nestjs/swagger 的 ApiProptery 装饰器添加属性描述。
我的问题是我不知道如何为地图创建正确的描述。
这是我的模型:
import { Precision } from '../shared/enums';
import { IsEnum, IsInt, IsOptional } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsPrimitive } from '../shared/decorator/decorators';
export class CreateMeasurementDto {
@IsOptional()
@IsInt()
@ApiPropertyOptional()
timestamp: number;
@IsOptional()
@IsEnum(Precision)
@ApiPropertyOptional({ enum: Precision })
precision: Precision;
@ApiProperty({
description:
'Key/value pairs; values can be of type string, boolean or number.',
type: Map,
})
@IsPrimitive()
datapoints: Map<string, string | boolean | …
Run Code Online (Sandbox Code Playgroud) 我有一个使用 Quarkus 的 REST API,我想在其中编写一个拦截器,它为 API 中的每个端点获取不同的参数。基本上我想提供字符串并查看它们是否位于请求附带的 JWT 中。我很难根据需要获取参数(作为字符串)。
这是注释:
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import javax.enterprise.util.Nonbinding;
import javax.interceptor.InterceptorBinding;
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface ScopesAllowed {
@Nonbinding
String[] value();
}
Run Code Online (Sandbox Code Playgroud)
这是使用它的一个端点:
import javax.ws.rs.GET;
import java.util.List;
public class TenantResource {
@GET
@ScopesAllowed({"MyScope", "AnotherScope"})
public List<Tenant> getTenants() {
}
}
Run Code Online (Sandbox Code Playgroud)
这是我对拦截器的尝试:
@Interceptor
@Priority(3000)
@ScopesAllowed({})
public class ScopesAllowedInterceptor {
@Inject
JsonWebToken jwt;
@AroundInvoke
public Object validate(InvocationContext ctx) throws Exception {
// get annotation parameters and check JWT
return ctx.proceed(); …
Run Code Online (Sandbox Code Playgroud) 我有一个 Kubernetes 集群,其中包含一个 REST API 的有效 Ingress 配置。现在我想将端口转发到我的 mqtt 适配器添加到此配置中,但我在寻找将 TCP 规则添加到配置中的方法时遇到问题。Kubernetes 文档仅显示一个 HTTP 示例。https://kubernetes.io/docs/concepts/services-networking/ingress/
我对 Kubernetes 还很陌生,在适应其他配置时遇到了问题,因为我发现的任何内容看起来都与我在 Kubernetes 文档中找到的完全不同。
我使用了常规的 nginx Web 服务器和 LetsEncrypt 来保护 TCP 连接。我希望这也适用于入口控制器。
我的目标是通过 MQTT 使用 TLS 将消息发送到我的集群。有人有这方面的正确文档或知道如何添加配置吗?
我的配置如下:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ratings-web-ingress
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt
spec:
tls:
- hosts:
- example.com
secretName: ratings-web-cert
rules:
- host: example.com
http:
paths:
- backend:
serviceName: test-api
servicePort: 8080
path: /
Run Code Online (Sandbox Code Playgroud) 我的 REST API 中有一个查询参数,其值应受枚举类型的限制。当客户端给出不同的东西时,我正在寻找一种抛出“错误请求”错误的方法。
我的枚举看起来像这样:
export enum Precision {
S = 's',
MS = 'ms',
U = 'u',
NS = 'ns',
}
Run Code Online (Sandbox Code Playgroud)
我的控制器功能如下所示:
@Get(':deviceId/:datapoint/last')
@ApiOkResponse()
@ApiQuery({name: 'precision', enum: Precision})
getLastMeasurement(
@Param('deviceId') deviceId: string,
@Param('datapoint') datapoint: string,
@Query('precision') precision: Precision = Precision.S,
@Res() response: Response,
) {
console.log(precision);
....
response.status(HttpStatus.OK).send(body);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是该函数也接受其他值(例如,我可以发送 f 作为查询参数的值)。该函数不会向客户端返回错误,但我不想在每个控制器函数的开头编写 if else 块。
我想对此有一个相当简单的解决方案,但是当我尝试在互联网上查找它时,我总是在 DTO 中获得类验证的结果,而不是直接在查询参数/REST 控制器中进行简单的枚举验证。
谢谢你的时间,
J
nestjs ×2
rest ×2
typescript ×2
annotations ×1
interceptor ×1
java ×1
json ×1
kubernetes ×1
mqtt ×1
quarkus ×1
swagger ×1