Search in sources :

Example 31 with RefFormat

use of io.swagger.v3.parser.models.RefFormat in project swagger-parser by swagger-api.

the class ResolverFully method resolveRequestBody.

public RequestBody resolveRequestBody(RequestBody requestBody) {
    RefFormat refFormat = computeRefFormat(requestBody.get$ref());
    String $ref = requestBody.get$ref();
    if (!isAnExternalRefFormat(refFormat)) {
        if (requestBodies != null && !requestBodies.isEmpty()) {
            String referenceKey = computeDefinitionName($ref);
            return requestBodies.getOrDefault(referenceKey, requestBody);
        }
    }
    return requestBody;
}
Also used : RefUtils.computeRefFormat(io.swagger.v3.parser.util.RefUtils.computeRefFormat) RefUtils.isAnExternalRefFormat(io.swagger.v3.parser.util.RefUtils.isAnExternalRefFormat) RefFormat(io.swagger.v3.parser.models.RefFormat)

Example 32 with RefFormat

use of io.swagger.v3.parser.models.RefFormat in project swagger-parser by swagger-api.

the class SecuritySchemeProcessor method processSecurityScheme.

public SecurityScheme processSecurityScheme(SecurityScheme securityScheme) {
    if (securityScheme.get$ref() != null) {
        RefFormat refFormat = computeRefFormat(securityScheme.get$ref());
        String $ref = securityScheme.get$ref();
        SecurityScheme newSecurityScheme = cache.loadRef($ref, refFormat, SecurityScheme.class);
        if (newSecurityScheme != null) {
            return newSecurityScheme;
        }
    }
    return securityScheme;
}
Also used : RefFormat(io.swagger.v3.parser.models.RefFormat) RefUtils.computeRefFormat(io.swagger.v3.parser.util.RefUtils.computeRefFormat) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme)

Example 33 with RefFormat

use of io.swagger.v3.parser.models.RefFormat in project swagger-parser by swagger-api.

the class PathsProcessor method processReferencePath.

public PathItem processReferencePath(PathItem pathItem) {
    RefFormat refFormat = computeRefFormat(pathItem.get$ref());
    String $ref = pathItem.get$ref();
    if (isAnExternalRefFormat(refFormat)) {
        pathItem = externalRefProcessor.processRefToExternalPathItem($ref, refFormat);
    } else {
        pathItem = cache.loadRef(pathItem.get$ref(), refFormat, PathItem.class);
    }
    return pathItem;
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) RefUtils.isAnExternalRefFormat(io.swagger.v3.parser.util.RefUtils.isAnExternalRefFormat) RefUtils.computeRefFormat(io.swagger.v3.parser.util.RefUtils.computeRefFormat) RefFormat(io.swagger.v3.parser.models.RefFormat)

Example 34 with RefFormat

use of io.swagger.v3.parser.models.RefFormat in project swagger-parser by swagger-api.

the class ParameterProcessor method processParameters.

public List<Parameter> processParameters(List<Parameter> parameters) {
    if (parameters == null) {
        return null;
    }
    final List<Parameter> processedPathLevelParameters = new ArrayList<>();
    final List<Parameter> refParameters = new ArrayList<>();
    for (Parameter parameter : parameters) {
        if (parameter.get$ref() != null) {
            RefFormat refFormat = computeRefFormat(parameter.get$ref());
            final Parameter resolvedParameter = cache.loadRef(parameter.get$ref(), refFormat, Parameter.class);
            if (parameter.get$ref().startsWith("#") && parameter.get$ref().indexOf("#/components/parameters") <= -1) {
                // result.warning(location, "The parameter should use Reference Object to link to parameters that are defined at the OpenAPI Object's components/parameters.");
                continue;
            }
            if (resolvedParameter == null) {
                // can't resolve it!
                processedPathLevelParameters.add(parameter);
                continue;
            }
            // if the parameter exists, replace it
            boolean matched = false;
            for (Parameter param : processedPathLevelParameters) {
                if (param != null && param.getName() != null && param.getName().equals(resolvedParameter.getName())) {
                    // ref param wins
                    matched = true;
                    break;
                }
            }
            for (Parameter param : parameters) {
                if (param.getName() != null) {
                    if (param.getName().equals(resolvedParameter.getName())) {
                        // ref param wins
                        matched = true;
                        break;
                    }
                }
            }
            if (matched) {
                refParameters.add(resolvedParameter);
            } else {
                processedPathLevelParameters.add(resolvedParameter);
            }
        } else {
            processedPathLevelParameters.add(parameter);
        }
    }
    for (Parameter resolvedParameter : refParameters) {
        int pos = 0;
        for (Parameter param : processedPathLevelParameters) {
            if (param.getName().equals(resolvedParameter.getName())) {
                // ref param wins
                processedPathLevelParameters.set(pos, resolvedParameter);
                break;
            }
            pos++;
        }
    }
    for (Parameter parameter : processedPathLevelParameters) {
        Schema schema = parameter.getSchema();
        if (schema != null) {
            schemaProcessor.processSchema(schema);
        } else if (parameter.getContent() != null) {
            Map<String, MediaType> content = parameter.getContent();
            for (String mediaName : content.keySet()) {
                MediaType mediaType = content.get(mediaName);
                if (mediaType.getSchema() != null) {
                    schema = mediaType.getSchema();
                    if (schema != null) {
                        schemaProcessor.processSchema(schema);
                    }
                }
                if (mediaType.getExamples() != null) {
                    for (Example ex : mediaType.getExamples().values()) {
                        exampleProcessor.processExample(ex);
                    }
                }
            }
        }
    }
    return processedPathLevelParameters;
}
Also used : Schema(io.swagger.v3.oas.models.media.Schema) Example(io.swagger.v3.oas.models.examples.Example) ArrayList(java.util.ArrayList) RefUtils.isAnExternalRefFormat(io.swagger.v3.parser.util.RefUtils.isAnExternalRefFormat) RefUtils.computeRefFormat(io.swagger.v3.parser.util.RefUtils.computeRefFormat) RefFormat(io.swagger.v3.parser.models.RefFormat) Parameter(io.swagger.v3.oas.models.parameters.Parameter) MediaType(io.swagger.v3.oas.models.media.MediaType) Map(java.util.Map)

Example 35 with RefFormat

use of io.swagger.v3.parser.models.RefFormat in project swagger-parser by swagger-api.

the class RequestBodyProcessor method processReferenceRequestBody.

public void processReferenceRequestBody(RequestBody requestBody) {
    RefFormat refFormat = computeRefFormat(requestBody.get$ref());
    String $ref = requestBody.get$ref();
    if (isAnExternalRefFormat(refFormat)) {
        final String newRef = externalRefProcessor.processRefToExternalRequestBody($ref, refFormat);
        if (newRef != null) {
            requestBody.set$ref(newRef);
        }
    }
}
Also used : RefFormat(io.swagger.v3.parser.models.RefFormat) RefUtils.isAnExternalRefFormat(io.swagger.v3.parser.util.RefUtils.isAnExternalRefFormat) RefUtils.computeRefFormat(io.swagger.v3.parser.util.RefUtils.computeRefFormat)

Aggregations

RefFormat (io.swagger.v3.parser.models.RefFormat)38 RefUtils.computeRefFormat (io.swagger.v3.parser.util.RefUtils.computeRefFormat)30 RefUtils.isAnExternalRefFormat (io.swagger.v3.parser.util.RefUtils.isAnExternalRefFormat)29 Components (io.swagger.v3.oas.models.Components)12 Schema (io.swagger.v3.oas.models.media.Schema)8 Test (org.testng.annotations.Test)7 ResolverCache (io.swagger.v3.parser.ResolverCache)6 Expectations (mockit.Expectations)6 Example (io.swagger.v3.oas.models.examples.Example)5 PathItem (io.swagger.v3.oas.models.PathItem)4 MediaType (io.swagger.v3.oas.models.media.MediaType)4 Parameter (io.swagger.v3.oas.models.parameters.Parameter)4 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)4 OpenAPI (io.swagger.v3.oas.models.OpenAPI)3 Callback (io.swagger.v3.oas.models.callbacks.Callback)3 Header (io.swagger.v3.oas.models.headers.Header)3 Link (io.swagger.v3.oas.models.links.Link)3 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)3 SecurityScheme (io.swagger.v3.oas.models.security.SecurityScheme)3 Map (java.util.Map)3