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;
}
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;
}
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;
}
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;
}
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);
}
}
}
Aggregations