use of io.swagger.v3.parser.util.OpenAPIDeserializer in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readRequestBodyObject.
@Test(dataProvider = "data")
public void readRequestBodyObject(JsonNode rootNode) throws Exception {
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
final Paths paths = openAPI.getPaths();
Assert.assertNotNull(paths);
PathItem petByStatusEndpoint = paths.get("/pet/findByStatus");
Assert.assertNotNull(petByStatusEndpoint.getGet().getRequestBody());
Assert.assertEquals(petByStatusEndpoint.getGet().getRequestBody().getDescription(), "pet store to add to the system");
assertTrue(petByStatusEndpoint.getGet().getRequestBody().getRequired(), "true");
Assert.assertNotNull(petByStatusEndpoint.getGet().getRequestBody().getContent().get("multipart/mixed"));
Assert.assertEquals(petByStatusEndpoint.getGet().getRequestBody().getContent().get("multipart/mixed").getSchema().getType(), "object");
Assert.assertNotNull(petByStatusEndpoint.getGet().getRequestBody().getContent().get("multipart/mixed").getSchema().getProperties());
Assert.assertEquals(petByStatusEndpoint.getGet().getRequestBody().getContent().get("multipart/mixed").getEncoding().get("historyMetadata").getContentType(), "application/xml; charset=utf-8");
Assert.assertNotNull(petByStatusEndpoint.getGet().getRequestBody().getContent().get("multipart/mixed").getEncoding().get("profileImage").getHeaders());
Assert.assertNotNull(petByStatusEndpoint.getGet().getRequestBody().getContent().get("multipart/mixed").getEncoding().get("profileImage").getHeaders().get("X-Rate-Limit"));
}
use of io.swagger.v3.parser.util.OpenAPIDeserializer in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readEmptyServerObject.
@Test
public void readEmptyServerObject() throws Exception {
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
final JsonNode rootNode = mapper.readTree(Files.readAllBytes(java.nio.file.Paths.get(getClass().getResource("/oas2.yaml.template").toURI())));
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
assertEquals(openAPI.getServers().get(0).getUrl(), "/");
}
use of io.swagger.v3.parser.util.OpenAPIDeserializer in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readSecuritySchemesObject.
@Test(dataProvider = "data")
public void readSecuritySchemesObject(JsonNode rootNode) throws Exception {
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
List<String> messages = result.getMessages();
assertTrue(!messages.contains("attribute components.securitySchemes'.petstore_auth'.name is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.petstore_auth'.in is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.petstore_auth'.scheme is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.petstore_auth'.openIdConnectUrl is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.petstore_auth'.tokenUrl is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.petstore_auth_password'.authorizationUrl is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.petstore_auth_clientCredentials'.authorizationUrl is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.api_key'.scheme is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.api_key'.flows is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.api_key'.openIdConnectUrl is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.http'.name is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.http'.in is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.http'.flows is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.http'.openIdConnectUrl is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.openID'.name is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.openID'.in is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.openID'.scheme is missing"));
assertTrue(!messages.contains("attribute components.securitySchemes'.openID'.flows is missing"));
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
final Map<String, SecurityScheme> securitySchemes = openAPI.getComponents().getSecuritySchemes();
Assert.assertNotNull(securitySchemes);
Assert.assertEquals(securitySchemes.size(), 10);
SecurityScheme securityScheme = securitySchemes.get("reference");
assertTrue(securityScheme.get$ref().equals("#/components/securitySchemes/api_key"));
securityScheme = securitySchemes.get("remote_reference");
assertTrue(securityScheme.get$ref().equals("http://localhost:${dynamicPort}/remote/security#/petstore_remote"));
securityScheme = securitySchemes.get("petstore_auth");
assertTrue(securityScheme.getType() == SecurityScheme.Type.OAUTH2);
securityScheme = securitySchemes.get("petstore_auth_password");
assertTrue(securityScheme.getType() == SecurityScheme.Type.OAUTH2);
securityScheme = securitySchemes.get("petstore_auth_clientCredentials");
assertTrue(securityScheme.getType() == SecurityScheme.Type.OAUTH2);
securityScheme = securitySchemes.get("petstore_auth_authorizationCode");
assertTrue(securityScheme.getType() == SecurityScheme.Type.OAUTH2);
securityScheme = securitySchemes.get("api_key");
assertTrue(securityScheme.getType() == SecurityScheme.Type.APIKEY);
assertTrue(securityScheme.getIn() == SecurityScheme.In.HEADER);
securityScheme = securitySchemes.get("api_key_cookie");
assertTrue(securityScheme.getType() == SecurityScheme.Type.APIKEY);
assertTrue(securityScheme.getIn() == SecurityScheme.In.COOKIE);
securityScheme = securitySchemes.get("http");
assertTrue(securityScheme.getType() == SecurityScheme.Type.HTTP);
securityScheme = securitySchemes.get("openID");
assertTrue(securityScheme.getType() == SecurityScheme.Type.OPENIDCONNECT);
}
use of io.swagger.v3.parser.util.OpenAPIDeserializer in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readInfoObject.
@Test(dataProvider = "data")
public void readInfoObject(JsonNode rootNode) throws Exception {
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
Assert.assertEquals(openAPI.getOpenapi(), "3.0.1");
final Info info = openAPI.getInfo();
Assert.assertNotNull(info);
Assert.assertEquals(info.getTitle(), "Sample Pet Store App");
Assert.assertEquals(info.getDescription(), "This is a sample server Petstore");
Assert.assertEquals(info.getTermsOfService(), "http://swagger.io/terms/");
Assert.assertNotNull(info.getExtensions().get("x-info"));
Assert.assertEquals(info.getExtensions().get("x-info").toString(), "info extension");
final Contact contact = info.getContact();
Assert.assertNotNull(contact);
Assert.assertEquals(contact.getName(), "API Support");
Assert.assertEquals(contact.getUrl(), "http://www.example.com/support");
Assert.assertEquals(contact.getEmail(), "support@example.com");
Assert.assertNotNull(contact.getExtensions().get("x-contact"));
Assert.assertEquals(contact.getExtensions().get("x-contact").toString(), "contact extension");
final License license = info.getLicense();
Assert.assertNotNull(license);
Assert.assertEquals(license.getName(), "Apache 2.0");
Assert.assertEquals(license.getUrl(), "http://www.apache.org/licenses/LICENSE-2.0.html");
Assert.assertNotNull(license.getExtensions());
Assert.assertEquals(info.getVersion(), "1.0.1");
}
use of io.swagger.v3.parser.util.OpenAPIDeserializer in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readSchemaArray.
@Test(dataProvider = "data")
public void readSchemaArray(JsonNode rootNode) throws Exception {
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
final Paths paths = openAPI.getPaths();
Assert.assertNotNull(paths);
Assert.assertEquals(paths.size(), 19);
// parameters operation get
PathItem petByStatusEndpoint = paths.get("/pet/findByTags");
Assert.assertNotNull(petByStatusEndpoint.getGet());
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().size(), 1);
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters().get(0).getSchema());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getSchema().getType(), "array");
Assert.assertEquals(((ArraySchema) (petByStatusEndpoint.getGet().getParameters().get(0).getSchema())).getItems().getType(), "string");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getName(), "tags");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getExplode(), Boolean.TRUE);
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getStyle(), StyleEnum.FORM);
}
Aggregations