use of io.swagger.v3.parser.models.RefFormat in project swagger-parser by swagger-api.
the class ExternalRefProcessor method processRefExample.
private void processRefExample(Example example, String externalFile) {
RefFormat format = computeRefFormat(example.get$ref());
if (!isAnExternalRefFormat(format)) {
example.set$ref(RefType.SCHEMAS.getInternalPrefix() + processRefToExternalSchema(externalFile + example.get$ref(), RefFormat.RELATIVE));
return;
}
String $ref = example.get$ref();
String subRefExternalPath = getExternalPath(example.get$ref()).orElse(null);
if (format.equals(RefFormat.RELATIVE) && !Objects.equals(subRefExternalPath, externalFile)) {
$ref = join(externalFile, example.get$ref());
example.set$ref($ref);
} else {
processRefToExternalExample($ref, format);
}
}
use of io.swagger.v3.parser.models.RefFormat in project swagger-parser by swagger-api.
the class LinkProcessor method processLink.
public void processLink(Link link) {
if (link.get$ref() != null) {
RefFormat refFormat = computeRefFormat(link.get$ref());
String $ref = link.get$ref();
if (isAnExternalRefFormat(refFormat)) {
final String newRef = externalRefProcessor.processRefToExternalLink($ref, refFormat);
if (newRef != null) {
link.set$ref(newRef);
}
}
} else if (link.getHeaders() != null) {
Map<String, Header> headers = link.getHeaders();
for (String headerName : headers.keySet()) {
Header header = headers.get(headerName);
headerProcessor.processHeader(header);
}
}
}
use of io.swagger.v3.parser.models.RefFormat in project swagger-parser by swagger-api.
the class OperationProcessor method processOperation.
public void processOperation(Operation operation) {
final List<Parameter> processedOperationParameters = parameterProcessor.processParameters(operation.getParameters());
if (processedOperationParameters != null) {
operation.setParameters(processedOperationParameters);
}
final RequestBody requestBody = operation.getRequestBody();
if (requestBody != null) {
requestBodyProcessor.processRequestBody(requestBody);
}
final Map<String, ApiResponse> responses = operation.getResponses();
if (responses != null) {
for (String responseCode : responses.keySet()) {
ApiResponse response = responses.get(responseCode);
if (response != null) {
// This part allows parser to put response schema inline without the resolveFully option set to true
if (response.get$ref() != null) {
responseProcessor.processResponse(response);
RefFormat refFormat = computeRefFormat(response.get$ref());
ApiResponse resolvedResponse = cache.loadRef(response.get$ref(), refFormat, ApiResponse.class);
if (resolvedResponse != null) {
response = resolvedResponse;
responses.put(responseCode, resolvedResponse);
}
}
responseProcessor.processResponse(response);
}
}
}
final Map<String, Callback> callbacks = operation.getCallbacks();
if (callbacks != null) {
for (String name : callbacks.keySet()) {
Callback callback = callbacks.get(name);
if (callback != null) {
if (callback.get$ref() != null) {
String $ref = callback.get$ref();
RefFormat refFormat = computeRefFormat($ref);
if (isAnExternalRefFormat(refFormat)) {
final String newRef = externalRefProcessor.processRefToExternalCallback($ref, refFormat);
if (newRef != null) {
callback.set$ref(newRef);
}
}
}
for (String callbackName : callback.keySet()) {
PathItem pathItem = callback.get(callbackName);
final Map<PathItem.HttpMethod, Operation> operationMap = pathItem.readOperationsMap();
for (PathItem.HttpMethod httpMethod : operationMap.keySet()) {
Operation op = operationMap.get(httpMethod);
processOperation(op);
}
List<Parameter> parameters = pathItem.getParameters();
if (parameters != null) {
for (Parameter parameter : parameters) {
parameterProcessor.processParameter(parameter);
}
}
}
}
}
}
}
use of io.swagger.v3.parser.models.RefFormat in project swagger-parser by swagger-api.
the class ParameterProcessor method processParameter.
public void processParameter(Parameter parameter) {
String $ref = parameter.get$ref();
if ($ref != null) {
RefFormat refFormat = computeRefFormat(parameter.get$ref());
if (isAnExternalRefFormat(refFormat)) {
final String newRef = externalRefProcessor.processRefToExternalParameter($ref, refFormat);
if (newRef != null) {
parameter.set$ref(newRef);
}
}
}
if (parameter.getSchema() != null) {
schemaProcessor.processSchema(parameter.getSchema());
}
if (parameter.getExamples() != null) {
Map<String, Example> examples = parameter.getExamples();
for (String exampleName : examples.keySet()) {
final Example example = examples.get(exampleName);
exampleProcessor.processExample(example);
}
}
Schema schema = null;
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);
}
}
}
}
}
use of io.swagger.v3.parser.models.RefFormat in project swagger-parser by swagger-api.
the class SchemaProcessor method processReferenceSchema.
private void processReferenceSchema(Schema schema) {
/* if this is a URL or relative ref:
1) we need to load it into memory.
2) shove it into the #/components/schemas
3) update the RefModel to point to its location in #/components/schemas
*/
RefFormat refFormat = computeRefFormat(schema.get$ref());
String $ref = schema.get$ref();
if (isAnExternalRefFormat(refFormat)) {
final String newRef = externalRefProcessor.processRefToExternalSchema($ref, refFormat);
if (newRef != null) {
schema.set$ref(RefType.SCHEMAS.getInternalPrefix() + newRef);
}
}
}
Aggregations