fix: secret data cannot be used in YAML (#5917)

#### What type of PR is this?
/kind bug
/area core
/milestone 2.16.x

#### What this PR does / why we need it:
修复 Secret 的 data 字段无法在 YAML 使用的问题

#### Does this PR introduce a user-facing change?
```release-note
None
```
pull/5928/head
guqing 2024-05-15 15:32:34 +08:00 committed by GitHub
parent 2341905323
commit 983e70d50d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import io.swagger.v3.core.util.Json;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.openapi4j.core.exception.ResolutionException;
import org.openapi4j.core.model.v3.OAI3;
@ -54,8 +55,14 @@ public class JSONExtensionConverter implements ExtensionConverter {
var scheme = schemeManager.get(gvk);
try {
var convertedExtension = Optional.of(extension)
.map(item -> scheme.type().isAssignableFrom(item.getClass()) ? item
: objectMapper.convertValue(item, scheme.type())
)
.orElseThrow();
var validation = new ValidationData<>(extension);
var extensionJsonNode = objectMapper.valueToTree(extension);
var extensionJsonNode = objectMapper.valueToTree(convertedExtension);
var validator = getValidator(scheme);
validator.validate(extensionJsonNode, validation);
if (!validation.isValid()) {