【发布时间】:2021-12-15 18:15:48
【问题描述】:
我正在为返回这种 JSON 的 REST 服务做文档:
{
"CKM_RSA_PKCS_OAEP" : {
"keyType" : "RSA",
"canGenerateKey" : false,
"canEncryptDecrypt" : true,
"canSignVerify" : false,
"canWrapSecretKeys" : true,
"canWrapPrivateKeys" : false,
"canDerive" : false,
"canDigest" : false,
"minKeySize" : 512,
"maxKeySize" : 16384
},
"CKM_SHA384" : {
"canGenerateKey" : false,
"canEncryptDecrypt" : false,
"canSignVerify" : false,
"canWrapSecretKeys" : false,
"canWrapPrivateKeys" : false,
"canDerive" : false,
"canDigest" : true,
"minKeySize" : 0,
"maxKeySize" : 0
}
}
这表示Map<Mechanism, MechanismInfo>,其中Mechanism 是枚举,MechanismInfo 是 POJO。
我想只记录MechanismInfo 类的字段,而不管Mechanism 的约束条件是keyType 属性可以是null,然后不存在于响应中。所有其他属性都是整数或布尔值,并且具有默认值。
这是我的 Junit 5 测试的一部分:
this.webTestClient = WebTestClient.bindToApplicationContext(applicationContext)
.configureClient()
.filter(documentationConfiguration(restDocumentation)
.operationPreprocessors()
.withResponseDefaults(prettyPrint()))
.build();
(...)
webTestClient
.get().uri("/tokens/{id}/mechanisms", TOKEN_TEST)
.exchange()
.expectStatus().isOk()
.expectBody(new ParameterizedTypeReference<Map<Mechanism, MechanismInfo>>() {
})
.consumeWith(document(
"get_mechanisms"
));
有人可以帮我做这件事吗?
【问题讨论】:
标签: enums spring-restdocs