Search in sources :

Example 66 with Reader

use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.

the class BeanParamTest method shouldSerializeTypeParameter.

// tests issue #2466
@Test(description = "check array type of serialized BeanParam containing QueryParams")
public void shouldSerializeTypeParameter() {
    OpenAPI openApi = new Reader(new OpenAPI()).read(MyBeanParamResource.class);
    List<Parameter> getOperationParams = openApi.getPaths().get("/").getGet().getParameters();
    Assert.assertEquals(getOperationParams.size(), 1);
    Parameter param = getOperationParams.get(0);
    Assert.assertEquals(param.getName(), "listOfStrings");
    Schema<?> schema = param.getSchema();
    // These are the important checks:
    Assert.assertEquals(schema.getClass(), ArraySchema.class);
    Assert.assertEquals(((ArraySchema) schema).getItems().getType(), "string");
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 67 with Reader

use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.

the class ReaderTest method testLinkWithRef.

@Test(description = "Link with Ref")
public void testLinkWithRef() {
    Components components = new Components();
    components.addLinks("Link", new Link().description("Link Description").operationId("id"));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(RefLinksResource.class);
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  description: info\n" + "paths:\n" + "  /links:\n" + "    get:\n" + "      operationId: getUserWithAddress\n" + "      parameters:\n" + "      - name: userId\n" + "        in: query\n" + "        schema:\n" + "          type: string\n" + "      responses:\n" + "        default:\n" + "          description: test description\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/User'\n" + "          links:\n" + "            address:\n" + "              operationId: getAddress\n" + "              parameters:\n" + "                userId: $request.query.userId\n" + "              $ref: '#/components/links/Link'\n" + "components:\n" + "  links:\n" + "    Link:\n" + "      operationId: id\n" + "      description: Link Description\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Link(io.swagger.v3.oas.models.links.Link) Test(org.testng.annotations.Test)

Example 68 with Reader

use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.

the class ReaderTest method test2818.

@Test(description = "test ticket #2818 @Parameter annotation")
public void test2818() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket2818Resource.class);
    Paths paths = openAPI.getPaths();
    assertEquals(paths.size(), 1);
    PathItem pathItem = paths.get("/bookstore/{id}");
    assertNotNull(pathItem);
    Operation operation = pathItem.getGet();
    assertNotNull(operation);
    assertEquals(operation.getParameters().get(0).getSchema().getType(), "integer");
    assertEquals(operation.getParameters().get(0).getSchema().getFormat(), "int32");
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) 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 69 with Reader

use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.

the class ReaderTest method testSchemaProperties.

@Test(description = "Test SchemaProperties and additionalProperties annotations")
public void testSchemaProperties() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(SchemaPropertiesResource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      summary: Simple get operation\n" + "      description: Defines a simple get operation with no inputs and a complex output\n" + "        object\n" + "      operationId: getWithPayloadResponse\n" + "      responses:\n" + "        \"200\":\n" + "          description: voila!\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                type: object\n" + "                properties:\n" + "                  foo:\n" + "                    maximum: 1\n" + "                    type: integer\n" + "        default:\n" + "          description: boo\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                maxProperties: 3\n" + "                type: object\n" + "                properties:\n" + "                  foo:\n" + "                    maximum: 1\n" + "                    type: integer\n" + "                description: various properties\n" + "        \"400\":\n" + "          description: additionalProperties schema\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                maxProperties: 2\n" + "                type: object\n" + "                additionalProperties:\n" + "                  type: string\n" + "        \"401\":\n" + "          description: additionalProperties boolean\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                maxProperties: 2\n" + "                type: object\n" + "                additionalProperties: false\n" + "      deprecated: true\n" + "  /one:\n" + "    get:\n" + "      operationId: requestBodySchemaPropertyNoSchema\n" + "      requestBody:\n" + "        content:\n" + "          application/yaml:\n" + "            schema:\n" + "              type: object\n" + "              properties:\n" + "                foo:\n" + "                  type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/MultipleBaseBean'\n" + "  /two:\n" + "    get:\n" + "      operationId: requestBodySchemaPropertySchema\n" + "      requestBody:\n" + "        content:\n" + "          application/yaml:\n" + "            schema:\n" + "              required:\n" + "              - foo\n" + "              type: object\n" + "              properties:\n" + "                foo:\n" + "                  type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/MultipleBaseBean'\n" + "  /three:\n" + "    get:\n" + "      operationId: requestBodySchemaPropertySchemaArray\n" + "      requestBody:\n" + "        content:\n" + "          application/yaml:\n" + "            schema:\n" + "              type: array\n" + "              items:\n" + "                required:\n" + "                - foo\n" + "                type: object\n" + "                properties:\n" + "                  foo:\n" + "                    type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/MultipleBaseBean'\n" + "components:\n" + "  schemas:\n" + "    MultipleBaseBean:\n" + "      type: object\n" + "      properties:\n" + "        beanType:\n" + "          type: string\n" + "        a:\n" + "          type: integer\n" + "          format: int32\n" + "        b:\n" + "          type: string\n" + "      description: MultipleBaseBean\n" + "    MultipleSub1Bean:\n" + "      type: object\n" + "      description: MultipleSub1Bean\n" + "      allOf:\n" + "      - $ref: '#/components/schemas/MultipleBaseBean'\n" + "      - type: object\n" + "        properties:\n" + "          c:\n" + "            type: integer\n" + "            format: int32\n" + "    MultipleSub2Bean:\n" + "      type: object\n" + "      description: MultipleSub2Bean\n" + "      allOf:\n" + "      - $ref: '#/components/schemas/MultipleBaseBean'\n" + "      - type: object\n" + "        properties:\n" + "          d:\n" + "            type: integer\n" + "            format: int32\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 70 with Reader

use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.

the class ReaderTest method testGetCallbacks.

@Test(description = "Callbacks")
public void testGetCallbacks() {
    Reader reader = new Reader(new OpenAPI());
    Method[] methods = SimpleCallbackResource.class.getMethods();
    Operation callbackOperation = reader.parseMethod(methods[0], null, null);
    assertNotNull(callbackOperation);
    Map<String, Callback> callbacks = callbackOperation.getCallbacks();
    assertNotNull(callbacks);
    Callback callback = callbacks.get(CALLBACK_SUBSCRIPTION_ID);
    assertNotNull(callback);
    PathItem pathItem = callback.get(CALLBACK_URL);
    assertNotNull(pathItem);
    Operation postOperation = pathItem.getPost();
    assertNotNull(postOperation);
    assertEquals(CALLBACK_POST_OPERATION_DESCRIPTION, postOperation.getDescription());
    Operation getOperation = pathItem.getGet();
    assertNotNull(getOperation);
    assertEquals(CALLBACK_GET_OPERATION_DESCRIPTION, getOperation.getDescription());
    Operation putOperation = pathItem.getPut();
    assertNotNull(putOperation);
    assertEquals(CALLBACK_POST_OPERATION_DESCRIPTION, putOperation.getDescription());
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Callback(io.swagger.v3.oas.models.callbacks.Callback) Method(java.lang.reflect.Method) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

OpenAPI (io.swagger.v3.oas.models.OpenAPI)85 Test (org.testng.annotations.Test)81 Operation (io.swagger.v3.oas.models.Operation)24 PathItem (io.swagger.v3.oas.models.PathItem)17 Info (io.swagger.v3.oas.models.info.Info)17 Components (io.swagger.v3.oas.models.Components)15 Paths (io.swagger.v3.oas.models.Paths)15 Reader (io.swagger.v3.jaxrs2.Reader)11 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)9 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)8 Schema (io.swagger.v3.oas.models.media.Schema)8 Parameter (io.swagger.v3.oas.models.parameters.Parameter)7 Method (java.lang.reflect.Method)7 SwaggerConfiguration (io.swagger.v3.oas.integration.SwaggerConfiguration)5 AbstractSpecFilter (io.swagger.v3.core.filter.AbstractSpecFilter)4 OpenAPISpecFilter (io.swagger.v3.core.filter.OpenAPISpecFilter)4 SpecFilter (io.swagger.v3.core.filter.SpecFilter)4 AbstractAnnotationTest (io.swagger.v3.jaxrs2.annotations.AbstractAnnotationTest)4 GenericOpenApiContext (io.swagger.v3.oas.integration.GenericOpenApiContext)4 OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)4