use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testArbitraryObjectBodyParamArrayInline.
@Test
public void testArbitraryObjectBodyParamArrayInline() {
OpenAPI openAPI = new OpenAPI();
ObjectSchema items = new ObjectSchema();
items.addProperties("arbitrary", new ObjectSchema());
openAPI.path("/hello", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(new ArraySchema().items(items)))))));
new InlineModelResolver().flatten(openAPI);
RequestBody requestBody = openAPI.getPaths().get("/hello").getGet().getRequestBody();
Schema schema = requestBody.getContent().get("*/*").getSchema();
assertTrue(schema instanceof ArraySchema);
ArraySchema arraySchema = (ArraySchema) schema;
Schema inner = arraySchema.getItems();
assertTrue(inner.get$ref() != null);
assertEquals(inner.get$ref(), "#/components/schemas/hello_body");
Schema inline = openAPI.getComponents().getSchemas().get("hello_body");
assertNotNull(inline);
Schema p = (Schema) inline.getProperties().get("arbitrary");
assertNotNull(p);
assertTrue(p instanceof ObjectSchema);
}
use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testArbitraryObjectRequestBodyInline.
@Test
public void testArbitraryObjectRequestBodyInline() {
OpenAPI swagger = new OpenAPI();
Schema schema = new Schema();
schema.addProperties("arbitrary", new ObjectSchema());
swagger.path("/hello", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(schema))))));
new InlineModelResolver().flatten(swagger);
Operation operation = swagger.getPaths().get("/hello").getGet();
RequestBody requestBody = operation.getRequestBody();
assertTrue(requestBody.getContent().get("*/*").getSchema().get$ref() != null);
Schema body = swagger.getComponents().getSchemas().get("hello_body");
assertTrue(body instanceof Schema);
Schema property = (Schema) body.getProperties().get("arbitrary");
assertNotNull(property);
assertTrue(property instanceof ObjectSchema);
}
use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testSkipInlineMatchesTrue.
@Test
public void testSkipInlineMatchesTrue() {
final OpenAPI openAPI = new OpenAPI();
final InlineModelResolver inlineModelResolver = new InlineModelResolver(false, false, true);
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(6, openAPI.getComponents().getSchemas().size());
}
use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class InlineModelResolverTest method resolveInlineRequestBodyWithTitle.
@Test
public void resolveInlineRequestBodyWithTitle() throws Exception {
OpenAPI openAPI = new OpenAPI();
ObjectSchema objectSchema = new ObjectSchema();
objectSchema.addProperties("street", new StringSchema());
objectSchema.addProperties("name", new StringSchema());
Schema addressModelItem = new Schema();
String addressModelName = "DetailedAddress";
addressModelItem.setTitle(addressModelName);
addressModelItem.addProperties("address", objectSchema);
openAPI.path("/hello", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(addressModelItem))))));
new InlineModelResolver().flatten(openAPI);
Operation operation = openAPI.getPaths().get("/hello").getGet();
RequestBody requestBody = operation.getRequestBody();
assertTrue(requestBody.getContent().get("*/*").getSchema().get$ref() != null);
Schema body = openAPI.getComponents().getSchemas().get(addressModelName);
assertTrue(body instanceof Schema);
assertNotNull(body.getProperties().get("address"));
}
use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-parser by swagger-api.
the class OpenAPIParserTest method testIssue799.
@Test
public void testIssue799() {
OpenAPIParser openApiParser = new OpenAPIParser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setFlatten(true);
OpenAPI openAPI = openApiParser.readLocation("issue799.json", null, options).getOpenAPI();
Assert.assertEquals(((Schema) openAPI.getComponents().getSchemas().get("v1beta3.Binding").getProperties().get("metadata")).get$ref(), "#/components/schemas/v1beta3.ObjectMeta");
RequestBody bodyParameter = openAPI.getPaths().get("/api/v1beta3/namespaces/{namespaces}/bindings").getPost().getRequestBody();
Assert.assertEquals(bodyParameter.getContent().get("*/*").getSchema().get$ref(), "#/components/schemas/v1beta3.Binding");
Assert.assertEquals(openAPI.getPaths().get("/api/v1beta3/namespaces/{namespaces}/componentstatuses/{name}").getGet().getResponses().get("200").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/v1beta3.ComponentStatus");
Assert.assertEquals(openAPI.getPaths().get("/api/v1beta3/namespaces/{namespaces}/componentstatuses").getGet().getResponses().get("200").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/v1beta3.ComponentStatusList");
Schema conditionsProperty = (Schema) openAPI.getComponents().getSchemas().get("v1beta3.ComponentStatus").getProperties().get("conditions");
assertTrue(conditionsProperty instanceof ArraySchema);
Schema items = ((ArraySchema) conditionsProperty).getItems();
assertTrue(items.get$ref() != null);
Assert.assertEquals(items.get$ref(), "#/components/schemas/v1beta3.ObjectReference");
}
Aggregations