use of io.swagger.v3.oas.annotations.parameters.RequestBody 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.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class PathsProcessor method updateRefs.
protected void updateRefs(RequestBody body, String pathRef) {
if (body.get$ref() != null) {
body.set$ref(computeRef(body.get$ref(), pathRef));
}
if (body.getContent() != null) {
Map<String, MediaType> content = body.getContent();
for (String key : content.keySet()) {
MediaType mediaType = content.get(key);
if (mediaType.getSchema() != null) {
updateRefs(mediaType.getSchema(), pathRef);
}
Map<String, Example> examples = content.get(key).getExamples();
if (examples != null) {
for (Example example : examples.values()) {
updateRefs(example, pathRef);
}
}
}
} else if (body.get$ref() != null) {
}
}
use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class ParameterProcessorTest method testProcessParameters_BodyParameter.
@Test
public void testProcessParameters_BodyParameter(@Injectable final Schema bodyParamSchema) throws Exception {
expectedModelProcessorCreation();
RequestBody bodyParameter = new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(bodyParamSchema)));
expectModelProcessorInvoked(bodyParamSchema);
new RequestBodyProcessor(cache, openAPI).processRequestBody(bodyParameter);
new FullVerifications() {
{
}
};
}
use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testSkipInlineMatchesFalse.
@Test
public void testSkipInlineMatchesFalse() {
final OpenAPI openAPI = new OpenAPI();
final InlineModelResolver inlineModelResolver = new InlineModelResolver();
final Schema operationAlphaInAsset = new ObjectSchema();
operationAlphaInAsset.setTitle("operationAlphaInAsset");
operationAlphaInAsset.addProperties("id1", new IntegerSchema());
operationAlphaInAsset.addProperties("id2", new IntegerSchema());
final Schema operationAlphaIn = new ObjectSchema();
operationAlphaIn.setTitle("operationAlphaIn");
operationAlphaIn.addProperties("asset", operationAlphaInAsset);
final Schema operationAlphaRequest = new ObjectSchema();
operationAlphaRequest.setTitle("operationAlphaRequest");
operationAlphaRequest.addProperties("in", operationAlphaIn);
final Schema operationBetaInAsset = new ObjectSchema();
operationBetaInAsset.setTitle("operationBetaInAsset");
operationBetaInAsset.addProperties("id1", new IntegerSchema());
operationBetaInAsset.addProperties("id2", new IntegerSchema());
final Schema operationBetaIn = new ObjectSchema();
operationBetaIn.setTitle("operationBetaIn");
operationBetaIn.addProperties("asset", operationBetaInAsset);
final Schema operationBetaRequest = new ObjectSchema();
operationBetaRequest.setTitle("operationBetaRequest");
operationBetaRequest.addProperties("in", operationBetaIn);
openAPI.path("/operationAlpha", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(operationAlphaRequest))))));
openAPI.path("/operationBeta", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(operationBetaRequest))))));
inlineModelResolver.flatten(openAPI);
assertNotNull(openAPI);
assertNotNull(openAPI.getComponents());
assertNotNull(openAPI.getComponents().getSchemas());
assertEquals(openAPI.getComponents().getSchemas().size(), 6);
}
use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testIssue386.
@Test
public void testIssue386() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " description: bleh\n" + " version: 2.0.0\n" + " title: Test\n" + "paths:\n" + " /foo:\n" + " post:\n" + " responses:\n" + " '200':\n" + " description: OK\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: object\n" + " enum:\n" + " - id: fun\n" + " properties:\n" + " id:\n" + " type: string\n" + "components:\n" + " schemas:\n" + " Fun:\n" + " type: object\n" + " properties:\n" + " complex:\n" + " enum:\n" + " - id: 110\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: string\n" + " MyEnum:\n" + " type: integer\n" + " enum:\n" + " - value: 3\n" + " description: Value 1\n" + " - value: 10\n" + " description: Value 2";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);
}
Aggregations