Skip to content

Commit

Permalink
Do not require JsonSubType annotation for sealed classes #2696
Browse files Browse the repository at this point in the history
  • Loading branch information
bnasslahsen committed Feb 16, 2025
1 parent 7c0229f commit f4e632b
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@

package org.springdoc.core.configuration;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.module.SimpleModule;
import io.swagger.v3.core.jackson.SwaggerAnnotationIntrospector;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* The type Spring doc sealed class module.
Expand All @@ -51,7 +52,10 @@ private static class RespectSealedClassAnnotationIntrospector extends SwaggerAnn
public List<NamedType> findSubtypes(Annotated annotated) {
ArrayList<NamedType> subTypes = new ArrayList<>();

if (annotated.getAnnotated() instanceof Class<?> clazz && clazz.isSealed()) {
if (annotated.getAnnotated() instanceof Class<?> clazz
&& clazz.isSealed()
&& !clazz.getPackage().getName().startsWith("java")
) {
Class<?>[] permittedSubClasses = clazz.getPermittedSubclasses();
if (permittedSubClasses.length > 0) {
Arrays.stream(permittedSubClasses).map(NamedType::new).forEach(subTypes::add);
Expand Down

0 comments on commit f4e632b

Please sign in to comment.