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);
}
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`"));
}
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());
}
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"));
}
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);
}
Aggregations