|
40 | 40 | import io.swagger.v3.oas.annotations.media.DependentRequired; |
41 | 41 | import io.swagger.v3.oas.annotations.media.DependentSchema; |
42 | 42 | import io.swagger.v3.oas.annotations.media.DependentSchemas; |
43 | | -import io.swagger.v3.oas.annotations.media.DiscriminatorMapping; |
44 | 43 | import io.swagger.v3.oas.annotations.media.PatternProperties; |
45 | 44 | import io.swagger.v3.oas.annotations.media.PatternProperty; |
46 | 45 | import io.swagger.v3.oas.annotations.media.SchemaProperties; |
@@ -2694,24 +2693,7 @@ protected Map<String, Object> resolveExtensions(Annotated a, Annotation[] annota |
2694 | 2693 | } |
2695 | 2694 |
|
2696 | 2695 | protected void resolveDiscriminatorProperty(JavaType type, ModelConverterContext context, Schema model) { |
2697 | | - // add JsonTypeInfo.property if not member of bean |
2698 | | - JsonTypeInfo typeInfo = type.getRawClass().getDeclaredAnnotation(JsonTypeInfo.class); |
2699 | | - if (typeInfo != null) { |
2700 | | - String typeInfoProp = typeInfo.property(); |
2701 | | - if (StringUtils.isNotBlank(typeInfoProp)) { |
2702 | | - Schema modelToUpdate = model; |
2703 | | - if (StringUtils.isNotBlank(model.get$ref())) { |
2704 | | - modelToUpdate = context.getDefinedModels().get(model.get$ref().substring(SCHEMA_COMPONENT_PREFIX)); |
2705 | | - } |
2706 | | - if (modelToUpdate.getProperties() == null || !modelToUpdate.getProperties().keySet().contains(typeInfoProp)) { |
2707 | | - Schema discriminatorSchema = openapi31 ? new JsonSchema().typesItem("string").name(typeInfoProp) : new StringSchema().name(typeInfoProp); |
2708 | | - modelToUpdate.addProperties(typeInfoProp, discriminatorSchema); |
2709 | | - if (modelToUpdate.getRequired() == null || !modelToUpdate.getRequired().contains(typeInfoProp)) { |
2710 | | - modelToUpdate.addRequiredItem(typeInfoProp); |
2711 | | - } |
2712 | | - } |
2713 | | - } |
2714 | | - } |
| 2696 | + DiscriminatorUtils.resolveDiscriminatorProperty(type, context, model, openapi31); |
2715 | 2697 | } |
2716 | 2698 |
|
2717 | 2699 | /* |
@@ -2748,35 +2730,7 @@ protected Schema resolveWrapping(JavaType type, ModelConverterContext context, S |
2748 | 2730 | } |
2749 | 2731 |
|
2750 | 2732 | protected Discriminator resolveDiscriminator(JavaType type, ModelConverterContext context) { |
2751 | | - |
2752 | | - io.swagger.v3.oas.annotations.media.Schema declaredSchemaAnnotation = AnnotationsUtils.getSchemaDeclaredAnnotation(type.getRawClass()); |
2753 | | - |
2754 | | - String disc = (declaredSchemaAnnotation == null) ? "" : declaredSchemaAnnotation.discriminatorProperty(); |
2755 | | - |
2756 | | - if (disc.isEmpty()) { |
2757 | | - // longer method would involve AnnotationIntrospector.findTypeResolver(...) but: |
2758 | | - JsonTypeInfo typeInfo = type.getRawClass().getDeclaredAnnotation(JsonTypeInfo.class); |
2759 | | - if (typeInfo != null) { |
2760 | | - disc = typeInfo.property(); |
2761 | | - } |
2762 | | - } |
2763 | | - if (!disc.isEmpty()) { |
2764 | | - Discriminator discriminator = new Discriminator() |
2765 | | - .propertyName(disc); |
2766 | | - if (declaredSchemaAnnotation != null) { |
2767 | | - DiscriminatorMapping[] mappings = declaredSchemaAnnotation.discriminatorMapping(); |
2768 | | - if (mappings != null && mappings.length > 0) { |
2769 | | - for (DiscriminatorMapping mapping : mappings) { |
2770 | | - if (!mapping.value().isEmpty() && !mapping.schema().equals(Void.class)) { |
2771 | | - discriminator.mapping(mapping.value(), constructRef(context.resolve(new AnnotatedType().type(mapping.schema())).getName())); |
2772 | | - } |
2773 | | - } |
2774 | | - } |
2775 | | - } |
2776 | | - |
2777 | | - return discriminator; |
2778 | | - } |
2779 | | - return null; |
| 2733 | + return DiscriminatorUtils.resolveDiscriminator(type, context); |
2780 | 2734 | } |
2781 | 2735 |
|
2782 | 2736 | protected XML resolveXml(Annotated a, Annotation[] annotations, io.swagger.v3.oas.annotations.media.Schema schema) { |
|
0 commit comments