Search in sources :

Example 36 with InlineModelResolver

use of io.swagger.v3.parser.util.InlineModelResolver 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"));
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Content(io.swagger.v3.oas.models.media.Content) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) MediaType(io.swagger.v3.oas.models.media.MediaType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Aggregations

OpenAPI (io.swagger.v3.oas.models.OpenAPI)35 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)35 Test (org.testng.annotations.Test)35 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)34 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)34 Schema (io.swagger.v3.oas.models.media.Schema)34 StringSchema (io.swagger.v3.oas.models.media.StringSchema)34 Operation (io.swagger.v3.oas.models.Operation)25 PathItem (io.swagger.v3.oas.models.PathItem)25 Content (io.swagger.v3.oas.models.media.Content)24 MediaType (io.swagger.v3.oas.models.media.MediaType)24 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)13 Components (io.swagger.v3.oas.models.Components)11 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)11 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)11 ArrayList (java.util.ArrayList)6 LinkedList (java.util.LinkedList)4 List (java.util.List)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Parameter (io.swagger.v3.oas.models.parameters.Parameter)1