Skip to content

Commit c7ba56c

Browse files
committed
Reapply "add warn logs when x-kotlin-implements-fields is used without x-kotlin-implements to improve usability"
This reverts commit 50bb7e5.
1 parent 50bb7e5 commit c7ba56c

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,15 @@ protected boolean needToImport(String type) {
836836
public CodegenModel fromModel(String name, Schema schema) {
837837
CodegenModel m = super.fromModel(name, schema);
838838
List<String> implementedInterfacesClasses = (List<String>) m.getVendorExtensions().getOrDefault(VendorExtension.X_KOTLIN_IMPLEMENTS.getName(), List.of());
839-
List<String> implementedInterfacesFields = implementedInterfacesClasses.isEmpty()
840-
? List.of()
841-
: (List<String>) m.getVendorExtensions().getOrDefault(VendorExtension.X_KOTLIN_IMPLEMENTS_FIELDS.getName(), List.of());
839+
List<String> implementedInterfacesFields = Optional.ofNullable((List<String>) m.getVendorExtensions().get(VendorExtension.X_KOTLIN_IMPLEMENTS_FIELDS.getName()))
840+
.map(xKotlinImplementsFields -> {
841+
if (implementedInterfacesClasses.isEmpty() && !xKotlinImplementsFields.isEmpty()) {
842+
LOGGER.warn("Annotating {} with {} without {} is not supported. {} will be ignored.",
843+
name, VendorExtension.X_KOTLIN_IMPLEMENTS_FIELDS.getName(), VendorExtension.X_KOTLIN_IMPLEMENTS.getName(),
844+
VendorExtension.X_KOTLIN_IMPLEMENTS_FIELDS.getName());
845+
}
846+
return xKotlinImplementsFields;
847+
}).orElse(List.of());
842848
m.optionalVars = m.optionalVars.stream().distinct().collect(Collectors.toList());
843849
// Update allVars/requiredVars/optionalVars with isInherited
844850
// Each of these lists contains elements that are similar, but they are all cloned

0 commit comments

Comments
 (0)