Yaml 使用swagger进行请求验证

Yaml 使用swagger进行请求验证,yaml,swagger-2.0,Yaml,Swagger 2.0,我需要在java中使用swagger(YAML文件)验证传入的REST请求。有人能帮我吗。 提前谢谢 招摇过市者 具有接受字节数组的构造函数。见下文: public SwaggerValidationInterceptor(final EncodedResource swaggerInterface) throws IOException { this(new SwaggerRequestValidationService(swaggerInterface)); } 因

我需要在java中使用swagger(YAML文件)验证传入的REST请求。有人能帮我吗。 提前谢谢

招摇过市者

具有接受字节数组的构造函数。见下文:

public SwaggerValidationInterceptor(final EncodedResource swaggerInterface) throws IOException {
        this(new SwaggerRequestValidationService(swaggerInterface));
    }
因此,您可以将yaml文件转换为字节数组,然后将其传递给Swagger

要将其转换为字节数组,可以采用以下方法:

public SwaggerValidationInterceptor swaggerValidationInterceptor(Resource swaggerDescriptor) throws IOException {
        final byte[] yamlPathAsBytes = swaggerDescriptor.getFile().getAbsolutePath().getBytes(UTF_8);
        return new SwaggerValidationInterceptor(
                new EncodedResource(new ByteArrayResource(yamlPathAsBytes), UTF_8));
    }

可能重复,。实际上,我的swagger文件是一个YAML文件。提供的链接提供了一个JSON招摇过市的解决方案。那么,你能帮助我如何使用YAML文件进行验证吗?这些问题中的“JSON”指的是请求格式,而不是Swagger定义格式。删除Swagger ValidationInterceptor的名称并没有多大帮助。此拦截器属于swagger请求验证程序库(链接?!)。它是SpringMVC应用程序的适配器。这个不具体的问题没有提到任何春天。所以这只是一个猜测。