Search in sources :

Example 41 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-core by swagger-api.

the class ReaderTest method testRequestBodyExtensions.

@Test(description = "RequestBody Tests")
public void testRequestBodyExtensions() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(RequestBodyExtensionsResource.class);
    assertNotNull(openAPI);
    Map<String, Object> extensions = openAPI.getPaths().get("/user").getGet().getRequestBody().getExtensions();
    assertNotNull(extensions);
    assertEquals(extensions.size(), 2);
    assertNotNull(extensions.get("x-extension"));
    assertNotNull(extensions.get("x-extension2"));
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 42 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-core by swagger-api.

the class FormParamBeanTest method shouldSerializeTypeParameter.

@Test(description = "check schema of serialized BeanParam containing FormParams")
public void shouldSerializeTypeParameter() {
    OpenAPI openApi = new Reader(new OpenAPI()).read(MyFormBeanParamResource.class);
    RequestBody requestBody = openApi.getPaths().get("/").getGet().getRequestBody();
    Assert.assertNotNull(requestBody);
    MediaType mediaType = requestBody.getContent().get("application/x-www-form-urlencoded");
    Assert.assertNotNull(mediaType);
    Schema schema = mediaType.getSchema();
    Assert.assertEquals(schema.getProperties().size(), 2);
    Assert.assertEquals(schema.getProperties().get("param1"), new StringSchema());
    Assert.assertEquals(schema.getProperties().get("param2"), new StringSchema());
}
Also used : StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) MediaType(io.swagger.v3.oas.models.media.MediaType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) OpenAPI(io.swagger.v3.oas.models.OpenAPI) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Example 43 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-core by swagger-api.

the class ReaderTest method testExampleWithFilter.

@Test(description = "Example with Ref Filter")
public void testExampleWithFilter() {
    Components components = new Components();
    components.addExamples("Id", new Example().description("Id Example").summary("Id Example").value("1"));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(SimpleExamplesResource.class);
    OpenAPISpecFilter filterImpl = new RefExampleFilter();
    SpecFilter f = new SpecFilter();
    openAPI = f.filter(openAPI, filterImpl, null, null, null);
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  description: info\n" + "paths:\n" + "  /example:\n" + "    post:\n" + "      description: subscribes a client to updates relevant to the requestor's account\n" + "      operationId: subscribe\n" + "      parameters:\n" + "      - example:\n" + "          $ref: '#/components/examples/Id'\n" + "      requestBody:\n" + "        content:\n" + "          '*/*':\n" + "            schema:\n" + "              type: integer\n" + "              format: int32\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/SubscriptionResponse'\n" + "components:\n" + "  schemas:\n" + "    SubscriptionResponse:\n" + "      type: object\n" + "      properties:\n" + "        subscriptionId:\n" + "          type: string\n" + "  examples:\n" + "    Id:\n" + "      summary: Id Example\n" + "      description: Id Example\n" + "      value: \"1\"\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) Example(io.swagger.v3.oas.models.examples.Example) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) AbstractSpecFilter(io.swagger.v3.core.filter.AbstractSpecFilter) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) SpecFilter(io.swagger.v3.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 44 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-core by swagger-api.

the class ReaderTest method testRequestBodyWithFilter.

@Test(description = "RequestBody with filter")
public void testRequestBodyWithFilter() {
    Components components = new Components();
    components.addRequestBodies("User", new RequestBody());
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(SimpleRequestBodyResource.class);
    OpenAPISpecFilter filterImpl = new RefRequestBodyFilter();
    SpecFilter f = new SpecFilter();
    openAPI = f.filter(openAPI, filterImpl, null, null, null);
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  description: info\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      summary: Simple get operation\n" + "      description: Defines a simple get operation with a payload complex input object\n" + "      operationId: sendPayload\n" + "      requestBody:\n" + "        $ref: '#/components/requestBodies/User'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "      deprecated: true\n" + "components:\n" + "  schemas:\n" + "    User:\n" + "      type: object\n" + "      properties:\n" + "        id:\n" + "          type: integer\n" + "          format: int64\n" + "        username:\n" + "          type: string\n" + "        firstName:\n" + "          type: string\n" + "        lastName:\n" + "          type: string\n" + "        email:\n" + "          type: string\n" + "        password:\n" + "          type: string\n" + "        phone:\n" + "          type: string\n" + "        userStatus:\n" + "          type: integer\n" + "          description: User Status\n" + "          format: int32\n" + "      xml:\n" + "        name: User\n" + "  requestBodies:\n" + "    User: {}\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) AbstractSpecFilter(io.swagger.v3.core.filter.AbstractSpecFilter) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) SpecFilter(io.swagger.v3.core.filter.SpecFilter) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Example 45 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project swagger-core by swagger-api.

the class ReaderTest method testTicket3092.

@Test
public void testTicket3092() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(UploadResource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /upload:\n" + "    post:\n" + "      operationId: uploadWithBean\n" + "      requestBody:\n" + "        content:\n" + "          multipart/form-data:\n" + "            schema:\n" + "              type: object\n" + "              properties:\n" + "                name:\n" + "                  type: string\n" + "                picture:\n" + "                  $ref: '#/components/schemas/picture'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json: {}\n" + "  /upload/requestbody:\n" + "    post:\n" + "      operationId: uploadWithBeanAndRequestBody\n" + "      requestBody:\n" + "        content:\n" + "          multipart/form-data:\n" + "            schema:\n" + "              $ref: '#/components/schemas/UploadRequest'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json: {}\n" + "components:\n" + "  schemas:\n" + "    picture:\n" + "      type: object\n" + "      format: binary\n" + "    UploadRequest:\n" + "      title: Schema for Upload\n" + "      type: object\n" + "      properties:\n" + "        name:\n" + "          type: string\n" + "        picture:\n" + "          type: string\n" + "          format: binary";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)67 OpenAPI (io.swagger.v3.oas.models.OpenAPI)62 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)59 Schema (io.swagger.v3.oas.models.media.Schema)46 Operation (io.swagger.v3.oas.annotations.Operation)41 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)40 MediaType (io.swagger.v3.oas.models.media.MediaType)36 StringSchema (io.swagger.v3.oas.models.media.StringSchema)35 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)32 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)32 Content (io.swagger.v3.oas.models.media.Content)31 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)28 Operation (io.swagger.v3.oas.models.Operation)27 PathItem (io.swagger.v3.oas.models.PathItem)23 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)21 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)19 Parameter (io.swagger.v3.oas.models.parameters.Parameter)15 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)14 Components (io.swagger.v3.oas.models.Components)13 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)12