Search in sources :

Example 96 with Info

use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method testDeserializeBinaryString.

@Test
public void testDeserializeBinaryString() {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + "  title: foo\n" + "  version: ''\n" + "paths:\n" + "  /test:\n" + "    post:\n" + "      responses:\n" + "        '200':\n" + "          description: ok\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: string\n" + "              format: binary";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(yaml, null, null);
    final OpenAPI resolved = new OpenAPIResolver(result.getOpenAPI(), null).resolve();
    assertTrue(resolved.getPaths().get("/test").getPost().getRequestBody().getContent().get("application/json").getSchema() instanceof BinarySchema);
}
Also used : BinarySchema(io.swagger.v3.oas.models.media.BinarySchema) OpenAPIResolver(io.swagger.v3.parser.OpenAPIResolver) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 97 with Info

use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method testDeserializeDateTimeString.

@Test
public void testDeserializeDateTimeString() {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + "  version: 0.0.0\n" + "  title: My Title\n" + "paths:\n" + "  /persons:\n" + "    get:\n" + "      description: a test\n" + "      responses:\n" + "        '200':\n" + "          description: Successful response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                type: object\n" + "                properties:\n" + "                  dateTime:\n" + "                    $ref: '#/components/schemas/DateTimeString'\n" + "components:\n" + "  schemas:\n" + "    DateTimeString:\n" + "      type: string\n" + "      format: date-time\n" + "      default: 2019-01-01T00:00:00Z\n" + "      enum:\n" + "        - null\n" + "        - Nunh uh\n" + "        - 2019-01-01T00:00:00Z\n" + "        - 2018-02-02T23:59:59.999-05:00\n" + "        - 2017-03-03T11:22:33+06:00\n" + "        - 2016-04-04T22:33:44.555Z\n" + "";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(yaml, null, null);
    final OpenAPI resolved = new OpenAPIResolver(result.getOpenAPI(), null).resolve();
    Schema dateTimeModel = resolved.getComponents().getSchemas().get("DateTimeString");
    assertTrue(dateTimeModel instanceof DateTimeSchema);
    List<OffsetDateTime> dateTimeValues = dateTimeModel.getEnum();
    assertEquals(dateTimeValues.size(), 5);
    assertEquals(dateTimeValues.get(0), null);
    assertEquals(dateTimeValues.get(1), OffsetDateTime.of(2019, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC));
    assertEquals(dateTimeValues.get(2), OffsetDateTime.of(2018, 2, 2, 23, 59, 59, 999000000, ZoneOffset.ofHours(-5)));
    assertEquals(dateTimeValues.get(3), OffsetDateTime.of(2017, 3, 3, 11, 22, 33, 0, ZoneOffset.ofHours(6)));
    assertEquals(dateTimeValues.get(4), OffsetDateTime.of(2016, 4, 4, 22, 33, 44, 555000000, ZoneOffset.UTC));
    assertEquals(dateTimeModel.getDefault(), OffsetDateTime.of(2019, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC));
    assertEquals(result.getMessages(), Arrays.asList("attribute components.schemas.DateTimeString.enum=`Nunh uh` is not of type `date-time`"));
}
Also used : DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) OffsetDateTime(java.time.OffsetDateTime) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) BinarySchema(io.swagger.v3.oas.models.media.BinarySchema) OpenAPIResolver(io.swagger.v3.parser.OpenAPIResolver) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 98 with Info

use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method testToplevelExtension.

@Test(description = "it should read a top-level extension per https://github.com/openAPI-api/validator-badge/issues/59")
public void testToplevelExtension() throws Exception {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "x-foo: woof\n" + "info:\n" + "  version: 0.0.0\n" + "  title: Simple API\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      responses:\n" + "        '200':\n" + "          description: OK";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(yaml, null, null);
    assertNotNull(result.getOpenAPI().getExtensions());
}
Also used : SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) Test(org.testng.annotations.Test)

Example 99 with Info

use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.

the class RelativeReferenceTest method testIssue409.

@Test
public void testIssue409() {
    String yaml = "openapi: 3.0.0\n" + "servers:\n" + "  - url: /\n" + "info:\n" + "  title: My API\n" + "  description: It works.\n" + "  version: 1.0.0\n" + "paths: {}\n" + "components:\n" + "  schemas:\n" + "\n" + "  # ===============================================================================\n" + "  # Fragments\n" + "  # ===============================================================================\n" + "\n" + "    ID:\n" + "      description: An entity identifer\n" + "      type: integer\n" + "      format: int64\n" + "      readOnly: true\n" + "\n" + "  # ===========================================================================\n" + "  # Users\n" + "  # ===========================================================================\n" + "\n" + "    User:\n" + "      type: object\n" + "      required:\n" + "        - emailAddress\n" + "      properties:\n" + "        id:\n" + "          $ref: '#/components/schemas/ID'\n" + "        emailAddress:\n" + "          type: string\n" + "          format: email\n" + "          minLength: 6\n" + "          maxLength: 254";
    OpenAPI swagger = (new OpenAPIV3Parser().readContents(yaml, null, null)).getOpenAPI();
    assertNotNull(swagger.getComponents().getSchemas().get("ID"));
}
Also used : OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 100 with Info

use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.

the class OpenAPIParserTest method testConverterWithFlatten.

@Test
public void testConverterWithFlatten() {
    String yaml = "swagger: \"2.0\"\n" + "info:\n" + "  description: \"Foo\"\n" + "  version: \"1.0.0\"\n" + "host: \"something.com\"\n" + "basePath: \"/\"\n" + "schemes:\n" + "  - \"https\"\n" + "consumes:\n" + "  - \"application/json\"\n" + "produces:\n" + "  - \"application/json\"\n" + "paths:\n" + "  /example:\n" + "    get:\n" + "      responses:\n" + "        200:\n" + "          description: \"OK\"\n" + "          schema:\n" + "            $ref: \"#/definitions/Foo\"\n" + "    parameters: []\n" + "definitions:\n" + "  Foo:\n" + "    type: \"object\"\n" + "    required:\n" + "    properties:\n" + "      nested:\n" + "        type: \"object\"\n" + "        properties:\n" + "          color:\n" + "            type: \"string\"";
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setFlatten(true);
    SwaggerParseResult result = new OpenAPIParser().readContents(yaml, null, options);
    OpenAPI openAPI = result.getOpenAPI();
    assertEquals(openAPI.getComponents().getSchemas().size(), 2);
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.junit.Test)

Aggregations

Test (org.testng.annotations.Test)91 OpenAPI (io.swagger.v3.oas.models.OpenAPI)77 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)60 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)56 Info (io.swagger.v3.oas.models.info.Info)39 Schema (io.swagger.v3.oas.models.media.Schema)24 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)22 StringSchema (io.swagger.v3.oas.models.media.StringSchema)22 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)19 Components (io.swagger.v3.oas.models.Components)18 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)18 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)17 Parameter (io.swagger.v3.oas.models.parameters.Parameter)17 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)15 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)15 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)15 BinarySchema (io.swagger.v3.oas.models.media.BinarySchema)14 MapSchema (io.swagger.v3.oas.models.media.MapSchema)14 DateSchema (io.swagger.v3.oas.models.media.DateSchema)13 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)13