Schema prop = properties.get(key); if (prop.get$ref() != null) { Pair<String, String> refName = extractSimpleName(prop.get$ref()); if (!StringUtils.isBlank(refName.getRight())) { // skip if didn't resolve simple name prop.set$ref(constructRef(toSnakeCase(refName.getLeft()), refName.getRight()));
protected Discriminator resolveDiscriminator(JavaType type, ModelConverterContext context) { io.swagger.v3.oas.annotations.media.Schema declaredSchemaAnnotation = AnnotationsUtils.getSchemaDeclaredAnnotation(type.getRawClass()); String disc = (declaredSchemaAnnotation == null) ? "" : declaredSchemaAnnotation.discriminatorProperty(); if (disc.isEmpty()) { // longer method would involve AnnotationIntrospector.findTypeResolver(...) but: JsonTypeInfo typeInfo = type.getRawClass().getDeclaredAnnotation(JsonTypeInfo.class); if (typeInfo != null) { disc = typeInfo.property(); } } if (!disc.isEmpty()) { Discriminator discriminator = new Discriminator() .propertyName(disc); if (declaredSchemaAnnotation != null) { DiscriminatorMapping mappings[] = declaredSchemaAnnotation.discriminatorMapping(); if (mappings != null && mappings.length > 0) { for (DiscriminatorMapping mapping : mappings) { if (!mapping.value().isEmpty() && !mapping.schema().equals(Void.class)) { discriminator.mapping(mapping.value(), constructRef(context.resolve(new AnnotatedType().type(mapping.schema())).getName())); } } } } return discriminator; } return null; }
protected void locateReferencedDefinitions(String ref, Set<String> nestedReferencedDefinitions, OpenAPI openAPI) { // if not already processed so as to avoid infinite loops if (!nestedReferencedDefinitions.contains(ref)) { nestedReferencedDefinitions.add(ref); String simpleName = (String) RefUtils.extractSimpleName(ref).getLeft(); Schema model = openAPI.getComponents().getSchemas().get(simpleName); if (model != null) { addSchemaRef(model, nestedReferencedDefinitions); } } } }
schema = new Schema().$ref(constructRef(pName));
protected OpenAPI removeBrokenReferenceDefinitions(OpenAPI openApi) { if (openApi == null || openApi.getComponents() == null || openApi.getComponents().getSchemas() == null) { return openApi; } Set<String> referencedDefinitions = new TreeSet<>(); if (openApi.getPaths() != null) { for (String resourcePath : openApi.getPaths().keySet()) { PathItem pathItem = openApi.getPaths().get(resourcePath); addPathItemSchemaRef(pathItem, referencedDefinitions); } } Set<String> nestedReferencedDefinitions = new TreeSet<>(); for (String ref : referencedDefinitions) { locateReferencedDefinitions(ref, nestedReferencedDefinitions, openApi); } referencedDefinitions.addAll(nestedReferencedDefinitions); openApi.getComponents().getSchemas().keySet().retainAll(referencedDefinitions.stream().map(s -> (String) RefUtils.extractSimpleName(s).getLeft()).collect(Collectors.toSet())); return openApi; }
innerSchema = new Schema().$ref(constructRef(innerSchema.getName())); implSchema = new Schema().$ref(constructRef(implSchema.getName())); addPropertiesSchema = new Schema().$ref(constructRef(pName)); items = new Schema().$ref(constructRef(pName)); property = new Schema().$ref(constructRef(pName)); model = new Schema().$ref(constructRef(model.getName()));
protected void locateReferencedDefinitions(String ref, Set<String> nestedReferencedDefinitions, OpenAPI openAPI) { // if not already processed so as to avoid infinite loops if (!nestedReferencedDefinitions.contains(ref)) { nestedReferencedDefinitions.add(ref); String simpleName = (String) RefUtils.extractSimpleName(ref).getLeft(); Schema model = openAPI.getComponents().getSchemas().get(simpleName); if (model != null) { addSchemaRef(model, nestedReferencedDefinitions); } } } }
protected Discriminator resolveDiscriminator(JavaType type, ModelConverterContext context) { io.swagger.v3.oas.annotations.media.Schema declaredSchemaAnnotation = AnnotationsUtils.getSchemaDeclaredAnnotation(type.getRawClass()); String disc = (declaredSchemaAnnotation == null) ? "" : declaredSchemaAnnotation.discriminatorProperty(); if (disc.isEmpty()) { // longer method would involve AnnotationIntrospector.findTypeResolver(...) but: JsonTypeInfo typeInfo = type.getRawClass().getDeclaredAnnotation(JsonTypeInfo.class); if (typeInfo != null) { disc = typeInfo.property(); } } if (!disc.isEmpty()) { Discriminator discriminator = new Discriminator() .propertyName(disc); if (declaredSchemaAnnotation != null) { DiscriminatorMapping mappings[] = declaredSchemaAnnotation.discriminatorMapping(); if (mappings != null && mappings.length > 0) { for (DiscriminatorMapping mapping : mappings) { if (!mapping.value().isEmpty() && !mapping.schema().equals(Void.class)) { discriminator.mapping(mapping.value(), constructRef(context.resolve(new AnnotatedType().type(mapping.schema())).getName())); } } } } return discriminator; } return null; }
protected OpenAPI removeBrokenReferenceDefinitions(OpenAPI openApi) { if (openApi == null || openApi.getComponents() == null || openApi.getComponents().getSchemas() == null) { return openApi; } Set<String> referencedDefinitions = new TreeSet<>(); if (openApi.getPaths() != null) { for (String resourcePath : openApi.getPaths().keySet()) { PathItem pathItem = openApi.getPaths().get(resourcePath); addPathItemSchemaRef(pathItem, referencedDefinitions); } } Set<String> nestedReferencedDefinitions = new TreeSet<>(); for (String ref : referencedDefinitions) { locateReferencedDefinitions(ref, nestedReferencedDefinitions, openApi); } referencedDefinitions.addAll(nestedReferencedDefinitions); openApi.getComponents().getSchemas().keySet().retainAll(referencedDefinitions.stream().map(s -> (String) RefUtils.extractSimpleName(s).getLeft()).collect(Collectors.toSet())); return openApi; }
innerSchema = new Schema().$ref(constructRef(innerSchema.getName())); implSchema = new Schema().$ref(constructRef(implSchema.getName())); addPropertiesSchema = new Schema().$ref(constructRef(pName)); items = new Schema().$ref(constructRef(pName)); property = new Schema().$ref(constructRef(pName)); model = new Schema().$ref(constructRef(model.getName()));