|
39 | 39 | import io.swagger.v3.oas.annotations.media.DependentRequired; |
40 | 40 | import io.swagger.v3.oas.annotations.media.DependentSchema; |
41 | 41 | import io.swagger.v3.oas.annotations.media.DependentSchemas; |
42 | | -import io.swagger.v3.oas.annotations.media.DiscriminatorMapping; |
43 | 42 | import io.swagger.v3.oas.annotations.media.PatternProperties; |
44 | 43 | import io.swagger.v3.oas.annotations.media.PatternProperty; |
45 | 44 | import io.swagger.v3.oas.annotations.media.SchemaProperties; |
@@ -2669,24 +2668,7 @@ protected Map<String, Object> resolveExtensions(Annotated a, Annotation[] annota |
2669 | 2668 | } |
2670 | 2669 |
|
2671 | 2670 | protected void resolveDiscriminatorProperty(JavaType type, ModelConverterContext context, Schema model) { |
2672 | | - // add JsonTypeInfo.property if not member of bean |
2673 | | - JsonTypeInfo typeInfo = type.getRawClass().getDeclaredAnnotation(JsonTypeInfo.class); |
2674 | | - if (typeInfo != null) { |
2675 | | - String typeInfoProp = typeInfo.property(); |
2676 | | - if (StringUtils.isNotBlank(typeInfoProp)) { |
2677 | | - Schema modelToUpdate = model; |
2678 | | - if (StringUtils.isNotBlank(model.get$ref())) { |
2679 | | - modelToUpdate = context.getDefinedModels().get(model.get$ref().substring(SCHEMA_COMPONENT_PREFIX)); |
2680 | | - } |
2681 | | - if (modelToUpdate.getProperties() == null || !modelToUpdate.getProperties().keySet().contains(typeInfoProp)) { |
2682 | | - Schema discriminatorSchema = openapi31 ? new JsonSchema().typesItem("string").name(typeInfoProp) : new StringSchema().name(typeInfoProp); |
2683 | | - modelToUpdate.addProperties(typeInfoProp, discriminatorSchema); |
2684 | | - if (modelToUpdate.getRequired() == null || !modelToUpdate.getRequired().contains(typeInfoProp)) { |
2685 | | - modelToUpdate.addRequiredItem(typeInfoProp); |
2686 | | - } |
2687 | | - } |
2688 | | - } |
2689 | | - } |
| 2671 | + DiscriminatorUtils.resolveDiscriminatorProperty(type, context, model, openapi31); |
2690 | 2672 | } |
2691 | 2673 |
|
2692 | 2674 | /* |
@@ -2723,35 +2705,7 @@ protected Schema resolveWrapping(JavaType type, ModelConverterContext context, S |
2723 | 2705 | } |
2724 | 2706 |
|
2725 | 2707 | protected Discriminator resolveDiscriminator(JavaType type, ModelConverterContext context) { |
2726 | | - |
2727 | | - io.swagger.v3.oas.annotations.media.Schema declaredSchemaAnnotation = AnnotationsUtils.getSchemaDeclaredAnnotation(type.getRawClass()); |
2728 | | - |
2729 | | - String disc = (declaredSchemaAnnotation == null) ? "" : declaredSchemaAnnotation.discriminatorProperty(); |
2730 | | - |
2731 | | - if (disc.isEmpty()) { |
2732 | | - // longer method would involve AnnotationIntrospector.findTypeResolver(...) but: |
2733 | | - JsonTypeInfo typeInfo = type.getRawClass().getDeclaredAnnotation(JsonTypeInfo.class); |
2734 | | - if (typeInfo != null) { |
2735 | | - disc = typeInfo.property(); |
2736 | | - } |
2737 | | - } |
2738 | | - if (!disc.isEmpty()) { |
2739 | | - Discriminator discriminator = new Discriminator() |
2740 | | - .propertyName(disc); |
2741 | | - if (declaredSchemaAnnotation != null) { |
2742 | | - DiscriminatorMapping[] mappings = declaredSchemaAnnotation.discriminatorMapping(); |
2743 | | - if (mappings != null && mappings.length > 0) { |
2744 | | - for (DiscriminatorMapping mapping : mappings) { |
2745 | | - if (!mapping.value().isEmpty() && !mapping.schema().equals(Void.class)) { |
2746 | | - discriminator.mapping(mapping.value(), constructRef(context.resolve(new AnnotatedType().type(mapping.schema())).getName())); |
2747 | | - } |
2748 | | - } |
2749 | | - } |
2750 | | - } |
2751 | | - |
2752 | | - return discriminator; |
2753 | | - } |
2754 | | - return null; |
| 2708 | + return DiscriminatorUtils.resolveDiscriminator(type, context); |
2755 | 2709 | } |
2756 | 2710 |
|
2757 | 2711 | protected XML resolveXml(Annotated a, Annotation[] annotations, io.swagger.v3.oas.annotations.media.Schema schema) { |
|
0 commit comments