Java Spring数据Rest-自定义Json模式/Alps?

Java Spring数据Rest-自定义Json模式/Alps?,java,rest,spring-data,spring-data-rest,jsonschema,Java,Rest,Spring Data,Spring Data Rest,Jsonschema,我需要向将使用API的客户端应用程序提供有关数据约束或默认值的信息。由Spring数据Rest生成的模式或ALPS似乎是放置这些信息的好地方 但是官方参考文档中关于API文档化的部分有点快,我在社区中找不到完整的文档化示例。我试着阅读PersistentEntityToJsonSchemaConverter的代码,以了解提供的可能性,但首先是头痛 我知道有一个@Description注释可以放在实体和属性上,它将更改模式的title字段。 我知道可以在rest消息中修改相同的字段。属性 是否有其

我需要向将使用API的客户端应用程序提供有关数据约束或默认值的信息。由
Spring数据Rest
生成的模式或ALPS似乎是放置这些信息的好地方

但是官方参考文档中关于API文档化的部分有点快,我在社区中找不到完整的文档化示例。我试着阅读
PersistentEntityToJsonSchemaConverter
的代码,以了解提供的可能性,但首先是头痛

我知道有一个
@Description
注释可以放在实体和属性上,它将更改模式的
title
字段。 我知道可以在rest消息中修改相同的字段。属性

是否有其他字段可以通过注释或配置文件进行修改?
将默认或约束信息放在这个描述字段中真的感觉像没有直接使用它。

这个问题几乎已经过时了,我不知道您是否已经找到了解决方案

在任何地方,如果您构建两个替换Spring使用的转换器的自定义转换器,您都可以构建一个完全自定义的ALPS分析信息

第一个需要扩展转换器
org.springframework.data.rest.webmvc.alps.AlpsJsonHttpMessageConverter

以下是一个可能的实现:

public class CustomAlpsJsonHttpMessageConverter extends AlpsJsonHttpMessageConverter {

    public CustomAlpsJsonHttpMessageConverter(RootResourceInformationToAlpsDescriptorConverter converter) {
        super(converter);
    }

    @Override
    public boolean canWrite(Class<?> clazz, MediaType mediaType) {
        return super.canWrite(clazz, mediaType);
    }

    @Override
    public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
        return super.canRead(type, contextClass, mediaType);
    }

    @Override
    public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType,
            Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request,
            ServerHttpResponse response) {
        return super.beforeBodyWrite(body, returnType, selectedContentType, selectedConverterType, request, response);
    }

    @Override
    public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
        return converterType.equals(AlpsJsonHttpMessageConverter.class) 
                || converterType.equals(CustomAlpsJsonHttpMessageConverter.class);
    }

}
所以如果你需要的话,你可以有一个完全定制的阿尔卑斯山


我已经尝试过使用此解决方案来构建自定义分析链接,效果非常好。

谢谢!我不再从事该项目,我们为此结束了一个外部文档,切断了自我解释API的“美丽”,无论如何,我会将您的答案链接到我以前的团队成员,让他们了解如何回到更干净的文档。如果这对任何人都有用。。。为了实现这一点,我必须重新定义RepositoryRestMvcAutoConfiguration-else配置文件只返回了404。扩展RepositoryRestMvcConfiguration时,自动配置将启动
@Bean
@Override
public AlpsJsonHttpMessageConverter alpsJsonHttpMessageConverter() {
    return new CustomAlpsJsonHttpMessageConverter(alpsConverter());
}

@Bean
@Override
public RootResourceInformationToAlpsDescriptorConverter alpsConverter() {
    Repositories repositories = repositories();
    PersistentEntities persistentEntities = persistentEntities();
    RepositoryEntityLinks entityLinks = entityLinks();
    MessageSourceAccessor messageSourceAccessor = resourceDescriptionMessageSourceAccessor();
    RepositoryRestConfiguration config = config();
    ResourceMappings resourceMappings = resourceMappings();

    return new CustomRootResourceInformationToAlpsDescriptorConverter(associationLinks(), repositories, persistentEntities,
            entityLinks, messageSourceAccessor, config, objectMapper(), enumTranslator());
}