Search in sources :

Example 1 with RefUtils.extractSimpleName

use of io.swagger.v3.core.util.RefUtils.extractSimpleName in project swagger-core by swagger-api.

the class SpecFilter method removeBrokenReferenceDefinitions.

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);
        }
    }
    referencedDefinitions.addAll(resolveAllNestedRefs(referencedDefinitions, referencedDefinitions, openApi));
    openApi.getComponents().getSchemas().keySet().retainAll(referencedDefinitions.stream().map(s -> (String) RefUtils.extractSimpleName(s).getLeft()).collect(Collectors.toSet()));
    return openApi;
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) TreeSet(java.util.TreeSet)

Example 2 with RefUtils.extractSimpleName

use of io.swagger.v3.core.util.RefUtils.extractSimpleName in project swagger-core by swagger-api.

the class SpecFilter method locateReferencedDefinitions.

protected void locateReferencedDefinitions(String ref, Set<String> nestedReferencedDefinitions, OpenAPI openAPI) {
    nestedReferencedDefinitions.add(ref);
    String simpleName = (String) RefUtils.extractSimpleName(ref).getLeft();
    Schema model = openAPI.getComponents().getSchemas().get(simpleName);
    if (model != null) {
        addSchemaRef(model, nestedReferencedDefinitions);
    }
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Schema(io.swagger.v3.oas.models.media.Schema)

Aggregations

PathItem (io.swagger.v3.oas.models.PathItem)1 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)1 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)1 Schema (io.swagger.v3.oas.models.media.Schema)1 TreeSet (java.util.TreeSet)1