Search in sources :

Example 51 with Yaml

use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.

the class ReaderTest method testTicket3426.

@Test(description = "overridden generic resource methods operationId")
public void testTicket3426() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket3426Resource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /inheritExample/{input}:\n" + "    get:\n" + "      operationId: get\n" + "      parameters:\n" + "      - name: input\n" + "        in: path\n" + "        required: true\n" + "        schema:\n" + "          type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                type: string";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 52 with Yaml

use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.

the class ReaderTest method testSingleExample.

@Test(description = "Single Example")
public void testSingleExample() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(SingleExampleResource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /test1:\n" + "    post:\n" + "      operationId: test1\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              $ref: '#/components/schemas/User'\n" + "            example:\n" + "              foo: foo\n" + "              bar: bar\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "  /test2:\n" + "    post:\n" + "      operationId: test2\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              $ref: '#/components/schemas/User'\n" + "            example:\n" + "              foo: foo\n" + "              bar: bar\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\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";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 53 with Yaml

use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.

the class ReaderTest method testRequestBodyEncoding.

@Test
public void testRequestBodyEncoding() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(UrlEncodedResourceWithEncodings.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /things/search:\n" + "    post:\n" + "      operationId: searchForThings\n" + "      requestBody:\n" + "        content:\n" + "          application/x-www-form-urlencoded:\n" + "            schema:\n" + "              type: object\n" + "              properties:\n" + "                id:\n" + "                  type: array\n" + "                  description: id param\n" + "                  items:\n" + "                    type: string\n" + "                name:\n" + "                  type: array\n" + "                  items:\n" + "                    type: string\n" + "            encoding:\n" + "              id:\n" + "                style: form\n" + "                explode: true\n" + "              name:\n" + "                style: form\n" + "                explode: false\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json: {}\n" + "  /things/sriracha:\n" + "    post:\n" + "      operationId: srirachaThing\n" + "      requestBody:\n" + "        content:\n" + "          application/x-www-form-urlencoded:\n" + "            schema:\n" + "              type: object\n" + "              properties:\n" + "                id:\n" + "                  type: array\n" + "                  description: id param\n" + "                  items:\n" + "                    type: string\n" + "                name:\n" + "                  type: array\n" + "                  items:\n" + "                    type: string\n" + "            encoding:\n" + "              id:\n" + "                style: form\n" + "                explode: true\n" + "              name:\n" + "                style: form\n" + "                explode: false\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json: {}\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 54 with Yaml

use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.

the class ReaderTest method testTicket2793.

/*
    TODO: in a scenario like the one in ticket 2793, currently no NPE is thrown
    but map is still not supported. When solved, update expected yaml in test case accordingly
     */
@Test(description = "no NPE resolving map")
public void testTicket2793() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket2793Resource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /distances:\n" + "    get:\n" + "      operationId: getDistances\n" + "      responses:\n" + "        \"200\":\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/DistancesResponse'\n" + "components:\n" + "  schemas:\n" + "    DistancesResponse:\n" + "      type: object\n" + "      properties:\n" + "        empty:\n" + "          type: boolean\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 55 with Yaml

use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.

the class ReaderTest method testTicket2794.

@Test(description = "NotNull parameters")
public void testTicket2794() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket2794Resource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /notnullparameter:\n" + "    get:\n" + "      operationId: getBooks\n" + "      parameters:\n" + "      - name: page\n" + "        in: query\n" + "        required: true\n" + "        schema:\n" + "          type: integer\n" + "          format: int32\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json: {}\n" + "  /notnullparameter/newnotnull:\n" + "    post:\n" + "      operationId: insertnotnull\n" + "      requestBody:\n" + "        content:\n" + "          '*/*':\n" + "            schema:\n" + "              $ref: '#/components/schemas/Book'\n" + "        required: true\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "  /notnullparameter/new_reqBody_required:\n" + "    post:\n" + "      operationId: insert\n" + "      requestBody:\n" + "        content:\n" + "          '*/*':\n" + "            schema:\n" + "              $ref: '#/components/schemas/Book'\n" + "        required: true\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "components:\n" + "  schemas:\n" + "    Book:\n" + "      type: object\n" + "      properties:\n" + "        foo:\n" + "          type: string\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)63 OpenAPI (io.swagger.v3.oas.models.OpenAPI)55 Schema (io.swagger.v3.oas.models.media.Schema)15 Components (io.swagger.v3.oas.models.Components)13 Info (io.swagger.v3.oas.models.info.Info)13 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)9 OpenAPISpecFilter (io.swagger.v3.core.filter.OpenAPISpecFilter)8 SpecFilter (io.swagger.v3.core.filter.SpecFilter)8 StringSchema (io.swagger.v3.oas.models.media.StringSchema)8 AfterTest (org.testng.annotations.AfterTest)6 OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)5 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)5 Parameter (io.swagger.v3.oas.models.parameters.Parameter)5 DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)4 AbstractSpecFilter (io.swagger.v3.core.filter.AbstractSpecFilter)4 OpenApiConfigurationException (io.swagger.v3.oas.integration.OpenApiConfigurationException)4 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)4 IOException (java.io.IOException)4 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)3 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)3