public static Schema extractSchema(Components components, Type returnType, JsonView jsonView, Annotation[] annotations, SpecVersion specVersion) {
		if (returnType == null) return null;
		Schema schemaN = null;
		ResolvedSchema resolvedSchema;
		boolean openapi31 = SpecVersion.V31 == specVersion;
		try {
			resolvedSchema = ModelConverters.getInstance(openapi31)
					.resolveAsResolvedSchema(
							new AnnotatedType(returnType)
									.resolveAsRef(true).jsonViewAnnotation(jsonView).ctxAnnotations(annotations));
		}
		catch (Exception e) {
			LOGGER.warn(Constants.GRACEFUL_EXCEPTION_OCCURRED, e);
			return null;
		}
		if (resolvedSchema != null) {
			Map<String, Schema> schemaMap = resolvedSchema.referencedSchemas;
			if (!CollectionUtils.isEmpty(schemaMap) && components != null) {
				Map<String, Schema> componentSchemas = components.getSchemas();
				if (componentSchemas == null) {
					componentSchemas = new LinkedHashMap<>();
					componentSchemas.putAll(schemaMap);
				}
				else
					for (Entry<String, Schema> entry : schemaMap.entrySet()) {
						// If we've seen this schema before but find later it should be polymorphic,
						// replace the existing schema with this richer version.
						Schema existingSchema = componentSchemas.get(entry.getKey());
						if (!componentSchemas.containsKey(entry.getKey()) ||
								(!entry.getValue().getClass().equals(existingSchema.getClass()) && entry.getValue().getAllOf() != null)) {
							componentSchemas.put(entry.getKey(), entry.getValue());
						}
						else if (componentSchemas.containsKey(entry.getKey()) && schemaMap.containsKey(entry.getKey())) {
							// Check to merge polymorphic types
							Set<Schema> existingAllOf = new LinkedHashSet<>();
							if (existingSchema.getAllOf() != null)
								existingAllOf.addAll(existingSchema.getAllOf());
							if (schemaMap.get(entry.getKey()).getAllOf() != null) {
								existingAllOf.addAll(schemaMap.get(entry.getKey()).getAllOf());
								existingSchema.setAllOf(new ArrayList<>(existingAllOf));
							}
						}
					}
				components.setSchemas(componentSchemas);
			}
			if (resolvedSchema.schema != null) {
				schemaN = new Schema(specVersion);
				if (StringUtils.isNotBlank(resolvedSchema.schema.getName()))
					schemaN.set$ref(COMPONENTS_REF + resolvedSchema.schema.getName());
				else
					schemaN = resolvedSchema.schema;
			}
		}
		if (openapi31)
			handleSchemaTypes(schemaN);

		return schemaN;
	}
Extract schema schema.

@param components  the components
@param returnType  the return type
@param jsonView    the json view
@param annotations the annotations
@param specVersion the spec version
@return the schema
springdoc-openapi-starter-common/src/main/java/org/springdoc/core/utils/SpringDocAnnotationsUtils.java