Search in sources :

Example 1 with RefFormat

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

the class RefUtils method computeRefFormat.

public static RefFormat computeRefFormat(String ref) {
    RefFormat result = RefFormat.INTERNAL;
    ref = mungedRef(ref);
    if (ref.startsWith("http") || ref.startsWith("https")) {
        result = RefFormat.URL;
    } else if (ref.startsWith(REFERENCE_SEPARATOR)) {
        result = RefFormat.INTERNAL;
    } else if (ref.startsWith(".") || ref.startsWith("/") || ref.indexOf(REFERENCE_SEPARATOR) > 0) {
        result = RefFormat.RELATIVE;
    }
    return result;
}
Also used : RefFormat(io.swagger.v3.parser.models.RefFormat)

Example 2 with RefFormat

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

the class ResolverFully method resolveHeader.

public Header resolveHeader(Header header) {
    RefFormat refFormat = computeRefFormat(header.get$ref());
    String $ref = header.get$ref();
    if (!isAnExternalRefFormat(refFormat)) {
        if (headers != null && !headers.isEmpty()) {
            String referenceKey = computeDefinitionName($ref);
            return headers.getOrDefault(referenceKey, header);
        }
    }
    return header;
}
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 3 with RefFormat

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

the class ResolverFully method resolveCallback.

public Callback resolveCallback(Callback callback) {
    RefFormat refFormat = computeRefFormat(callback.get$ref());
    String $ref = callback.get$ref();
    if (!isAnExternalRefFormat(refFormat)) {
        if (callbacks != null && !callbacks.isEmpty()) {
            String referenceKey = computeDefinitionName($ref);
            return callbacks.getOrDefault(referenceKey, callback);
        }
    }
    return callback;
}
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 4 with RefFormat

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

the class ResolverFully method resolveLink.

public Link resolveLink(Link link) {
    RefFormat refFormat = computeRefFormat(link.get$ref());
    String $ref = link.get$ref();
    if (!isAnExternalRefFormat(refFormat)) {
        if (links != null && !links.isEmpty()) {
            String referenceKey = computeDefinitionName($ref);
            Link link1 = links.getOrDefault(referenceKey, link);
            if (link1 == null) {
                return null;
            }
            resolveHeaders(link1.getHeaders());
            return link1;
        }
    }
    return link;
}
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) Link(io.swagger.v3.oas.models.links.Link)

Example 5 with RefFormat

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

the class ExampleProcessor method processReferenceExample.

private void processReferenceExample(Example example) {
    RefFormat refFormat = computeRefFormat(example.get$ref());
    String $ref = example.get$ref();
    if (isAnExternalRefFormat(refFormat)) {
        final String newRef = externalRefProcessor.processRefToExternalExample($ref, refFormat);
        if (newRef != null) {
            example.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