Search in sources :

Example 76 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.

the class ReaderTest method test2497.

@Test(description = "test resource with array in response content")
public void test2497() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(ResponseContentWithArrayResource.class);
    Paths paths = openAPI.getPaths();
    assertEquals(paths.size(), 1);
    PathItem pathItem = paths.get("/user");
    assertNotNull(pathItem);
    Operation operation = pathItem.getGet();
    assertNotNull(operation);
    ArraySchema schema = (ArraySchema) operation.getResponses().get("200").getContent().values().iterator().next().getSchema();
    assertNotNull(schema);
    assertEquals(schema.getItems().get$ref(), "#/components/schemas/User");
    assertEquals(openAPI.getComponents().getSchemas().get("User").getRequired().get(0), "issue3438");
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Paths(io.swagger.v3.oas.models.Paths) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 77 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.

the class ReaderTest method testParameterWithFilter.

@Test(description = "Responses with filter")
public void testParameterWithFilter() {
    Components components = new Components();
    components.addParameters("id", new Parameter().description("Id Description").schema(new IntegerSchema()).in(ParameterIn.QUERY.toString()).example(1).required(true));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(SimpleParameterResource.class);
    OpenAPISpecFilter filterImpl = new RefParameterFilter();
    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" + "      parameters:\n" + "      - $ref: '#/components/parameters/id'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "      deprecated: true\n" + "components:\n" + "  parameters: \n" + "    id:\n" + "      in: query\n" + "      description: Id Description\n" + "      required: true\n" + "      schema:\n" + "        type: integer\n" + "        format: int32\n" + "      example: 1\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) 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 78 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.

the class ReaderTest method testTicket3624.

@Test(description = "Optional handling")
public void testTicket3624() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Service.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /example/model:\n" + "    get:\n" + "      tags:\n" + "      - ExampleService\n" + "      summary: ' Retrieve models for display to the user'\n" + "      operationId: getModels\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/Response'\n" + "  /example/model/by/ids:\n" + "    get:\n" + "      tags:\n" + "      - ExampleService\n" + "      summary: ' Retrieve models by their ids'\n" + "      operationId: getModelsById\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/ByIdResponse'\n" + "  /example/containerized/model:\n" + "    get:\n" + "      tags:\n" + "      - ExampleService\n" + "      summary: ' Retrieve review insights for a specific product'\n" + "      operationId: getContainerizedModels\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/ContainerizedResponse'\n" + "components:\n" + "  schemas:\n" + "    Model:\n" + "      type: object\n" + "      properties:\n" + "        text:\n" + "          type: string\n" + "        title:\n" + "          type: string\n" + "        active:\n" + "          type: boolean\n" + "        schemaParent:\n" + "          $ref: '#/components/schemas/Model'\n" + "        optionalString:\n" + "          type: string\n" + "        parent:\n" + "          $ref: '#/components/schemas/Model'\n" + "        id:\n" + "          type: integer\n" + "          format: int32\n" + "    Response:\n" + "      type: object\n" + "      properties:\n" + "        count:\n" + "          type: integer\n" + "          format: int32\n" + "        models:\n" + "          type: array\n" + "          items:\n" + "            $ref: '#/components/schemas/Model'\n" + "    ByIdResponse:\n" + "      type: object\n" + "      properties:\n" + "        modelsById:\n" + "          type: object\n" + "          additionalProperties:\n" + "            $ref: '#/components/schemas/Model'\n" + "    ContainerizedResponse:\n" + "      type: object\n" + "      properties:\n" + "        totalCount:\n" + "          type: integer\n" + "          format: int32\n" + "        containerizedModels:\n" + "          type: array\n" + "          items:\n" + "            $ref: '#/components/schemas/ModelContainer'\n" + "    ModelContainer:\n" + "      type: object\n" + "      properties:\n" + "        text:\n" + "          type: string\n" + "        model:\n" + "          $ref: '#/components/schemas/Model'\n" + "        id:\n" + "          type: integer\n" + "          format: int32";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 79 with Content

use of io.swagger.v3.oas.annotations.media.Content 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 80 with Content

use of io.swagger.v3.oas.annotations.media.Content 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

OpenAPI (io.swagger.v3.oas.models.OpenAPI)121 Test (org.testng.annotations.Test)120 MediaType (io.swagger.v3.oas.models.media.MediaType)70 Schema (io.swagger.v3.oas.models.media.Schema)70 Operation (io.swagger.v3.oas.annotations.Operation)65 Content (io.swagger.v3.oas.models.media.Content)64 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)62 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)59 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)57 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)53 Operation (io.swagger.v3.oas.models.Operation)52 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)51 StringSchema (io.swagger.v3.oas.models.media.StringSchema)50 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)42 PathItem (io.swagger.v3.oas.models.PathItem)41 ArrayList (java.util.ArrayList)41 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)40 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)37 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)37 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)33