io.swagger.oas.inflector.models.RequestContext Java Examples
The following examples show how to use
io.swagger.oas.inflector.models.RequestContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 6 votes |
@Test public void testValidateInvalid20SpecByContent() throws Exception { final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); final JsonNode rootNode = mapper.readTree(Files.readAllBytes(java.nio.file.Paths.get(getClass().getResource(INVALID_20_YAML).toURI()))); ValidatorController validator = new ValidatorController(); ResponseContext response = validator.validateByContent(new RequestContext(), rootNode); Assert.assertEquals(IMAGE, response.getContentType().getType()); Assert.assertEquals(PNG, response.getContentType().getSubtype()); InputStream entity = (InputStream)response.getEntity(); InputStream valid = this.getClass().getClassLoader().getResourceAsStream(INVALID_IMAGE); Assert.assertTrue( validateEquals(entity,valid) == true); }
Example #2
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 6 votes |
@Test public void testDebugInvalid30SpecByContent() throws Exception { final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); final JsonNode rootNode = mapper.readTree(Files.readAllBytes(java.nio.file.Paths.get(getClass().getResource(INVALID_30_YAML).toURI()))); ValidatorController validator = new ValidatorController(); ResponseContext response = validator.reviewByContent(new RequestContext(), rootNode); // since inflector 2.0.3 content type is managed by inflector according to request headers and spec /* Assert.assertEquals(APPLICATION, response.getContentType().getType()); Assert.assertEquals(JSON, response.getContentType().getSubtype()); */ ValidationResponse validationResponse = (ValidationResponse) response.getEntity(); Assert.assertTrue(validationResponse.getMessages().contains(INFO_MISSING)); Assert.assertTrue(validationResponse.getSchemaValidationMessages().get(0).getMessage().equals(INFO_MISSING_SCHEMA)); }
Example #3
Source File: ValidatorController.java From validator-badge with Apache License 2.0 | 6 votes |
public ResponseContext validateByUrl(RequestContext request , String url) { if(url == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity( "No specification supplied in either the url or request body. Try again?" ); } ValidationResponse validationResponse = null; try { validationResponse = debugByUrl(request, url); }catch (Exception e){ return new ResponseContext().status(Response.Status.INTERNAL_SERVER_ERROR).entity( "Failed to process URL" ); } return processValidationResponse(validationResponse); }
Example #4
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 6 votes |
@Test public void testDebugInvalid20SpecByUrl() throws Exception { String url = "http://localhost:${dynamicPort}/invalidswagger/yaml"; url = url.replace("${dynamicPort}", String.valueOf(this.serverPort)); ValidatorController validator = new ValidatorController(); ResponseContext response = validator.reviewByUrl(new RequestContext(), url); // since inflector 2.0.3 content type is managed by inflector according to request headers and spec /* Assert.assertEquals(APPLICATION, response.getContentType().getType()); Assert.assertEquals(JSON, response.getContentType().getSubtype()); */ ValidationResponse validationResponse = (ValidationResponse) response.getEntity(); Assert.assertTrue(validationResponse.getMessages().contains(INFO_MISSING)); Assert.assertTrue(validationResponse.getSchemaValidationMessages().get(0).getMessage().equals(INFO_MISSING_SCHEMA)); }
Example #5
Source File: UserController.java From swagger-petstore with Apache License 2.0 | 6 votes |
public ResponseContext deleteUser(final RequestContext request, final String username) { if (username == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity("No username provided. Try again?"); } userData.deleteUser(username); final User user = userData.findUserByName(username); if (null == user) { return new ResponseContext() .contentType(Util.getMediaType(request)) .entity(user); } else { return new ResponseContext().status(Response.Status.NOT_MODIFIED).entity("User couldn't be deleted."); } }
Example #6
Source File: UserController.java From swagger-petstore with Apache License 2.0 | 6 votes |
public ResponseContext updateUser(final RequestContext request, final String username, final User user) { if (username == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity("No Username provided. Try again?"); } if (user == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity("No User provided. Try again?"); } final User existingUser = userData.findUserByName(username); if (existingUser == null) { return new ResponseContext().status(Response.Status.NOT_FOUND).entity("User not found"); } userData.deleteUser(existingUser.getUsername()); userData.addUser(user); return new ResponseContext() .contentType(Util.getMediaType(request)) .entity(user); }
Example #7
Source File: OpenAPIOperationControllerTest.java From swagger-inflector with Apache License 2.0 | 6 votes |
@Test public void testAddsRequestAndResponseToRequestContext() throws Exception { final String remoteAddr = "10.11.12.13"; HttpServletRequest request = mock(HttpServletRequest.class); when(request.getRemoteAddr()).thenReturn(remoteAddr); HttpServletResponse response = mock(HttpServletResponse.class); Provider<HttpServletRequest> requestProvider = () -> request; Provider<HttpServletResponse> responseProvider = () -> response; OpenAPIOperationController controller = new OpenAPIOperationController(mock(Configuration.class), "/any_path", "GET", mock(Operation.class), "application/json", Collections.emptyMap(), requestProvider, responseProvider ); ContainerRequestContext context = mock(ContainerRequestContext.class); RequestContext requestContext = controller.createContext(context); assertSame(requestContext.getRequest(), request); assertSame(requestContext.getResponse(), response); assertEquals(requestContext.getRemoteAddr(), remoteAddr); }
Example #8
Source File: PetController.java From swagger-petstore with Apache License 2.0 | 6 votes |
public ResponseContext findPetsByStatus(final RequestContext request, final String status) { if (status == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity("No status provided. Try again?"); } final List<Pet> petByStatus = petData.findPetByStatus(status); if (petByStatus == null) { return new ResponseContext().status(Response.Status.NOT_FOUND).entity("Pets not found"); } return new ResponseContext() .contentType(Util.getMediaType(request)) .entity(petByStatus); }
Example #9
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 6 votes |
@Test public void testDebugInvalid20SpecByContent() throws Exception { final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); final JsonNode rootNode = mapper.readTree(Files.readAllBytes(java.nio.file.Paths.get(getClass().getResource(INVALID_20_YAML).toURI()))); ValidatorController validator = new ValidatorController(); ResponseContext response = validator.reviewByContent(new RequestContext(), rootNode); // since inflector 2.0.3 content type is managed by inflector according to request headers and spec /* Assert.assertEquals(APPLICATION, response.getContentType().getType()); Assert.assertEquals(JSON, response.getContentType().getSubtype()); */ ValidationResponse validationResponse = (ValidationResponse) response.getEntity(); Assert.assertTrue(validationResponse.getMessages().contains(INFO_MISSING)); Assert.assertTrue(validationResponse.getSchemaValidationMessages().get(0).getMessage().equals(INFO_MISSING_SCHEMA)); }
Example #10
Source File: OrderController.java From swagger-petstore with Apache License 2.0 | 6 votes |
public ResponseContext deleteOrder(final RequestContext request, final Long orderId) { if (orderId == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity("No orderId provided. Try again?"); } orderData.deleteOrderById(orderId); final Order order = orderData.getOrderById(orderId); if (null == order) { return new ResponseContext() .contentType(Util.getMediaType(request)) .entity(order); } else { return new ResponseContext().status(Response.Status.NOT_MODIFIED).entity("Order couldn't be deleted."); } }
Example #11
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 6 votes |
@Test public void testDebugValid20SpecByContent() throws Exception { final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); final JsonNode rootNode = mapper.readTree(Files.readAllBytes(java.nio.file.Paths.get(getClass().getResource(VALID_20_YAML).toURI()))); ValidatorController validator = new ValidatorController(); ResponseContext response = validator.reviewByContent(new RequestContext(), rootNode); // since inflector 2.0.3 content type is managed by inflector according to request headers and spec /* Assert.assertEquals(APPLICATION, response.getContentType().getType()); Assert.assertEquals(JSON, response.getContentType().getSubtype()); */ ValidationResponse validationResponse = (ValidationResponse) response.getEntity(); Assert.assertTrue(validationResponse.getMessages() == null || validationResponse.getMessages().size() == 0); Assert.assertTrue(validationResponse.getSchemaValidationMessages() == null || validationResponse.getSchemaValidationMessages().size() == 0); }
Example #12
Source File: OrderController.java From swagger-petstore with Apache License 2.0 | 6 votes |
public ResponseContext getOrderById(final RequestContext request, final Long orderId) { if (orderId == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity("No orderId provided. Try again?"); } final Order order = orderData.getOrderById(orderId); if (order != null) { return new ResponseContext() .contentType(Util.getMediaType(request)) .entity(order); } return new ResponseContext().status(Response.Status.NOT_FOUND).entity("Order not found"); }
Example #13
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 6 votes |
@Test public void testDebugValid30SpecByContent() throws Exception { final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); final JsonNode rootNode = mapper.readTree(Files.readAllBytes(java.nio.file.Paths.get(getClass().getResource(VALID_30_YAML).toURI()))); ValidatorController validator = new ValidatorController(); ResponseContext response = validator.reviewByContent(new RequestContext(), rootNode); // since inflector 2.0.3 content type is managed by inflector according to request headers and spec /* Assert.assertEquals(APPLICATION, response.getContentType().getType()); Assert.assertEquals(JSON, response.getContentType().getSubtype()); */ ValidationResponse validationResponse = (ValidationResponse) response.getEntity(); Assert.assertTrue(validationResponse.getMessages() == null || validationResponse.getMessages().size() == 0); Assert.assertTrue(validationResponse.getSchemaValidationMessages() == null || validationResponse.getSchemaValidationMessages().size() == 0); }
Example #14
Source File: UserController.java From swagger-petstore with Apache License 2.0 | 6 votes |
public ResponseContext getUserByName(final RequestContext request, final String username) { if (username == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity("No username provided. Try again?"); } final User user = userData.findUserByName(username); if (user == null) { return new ResponseContext().status(Response.Status.NOT_FOUND).entity("User not found"); } return new ResponseContext() .contentType(Util.getMediaType(request)) .entity(user); }
Example #15
Source File: ValidatorController.java From validator-badge with Apache License 2.0 | 6 votes |
public ResponseContext validateByContent(RequestContext request, JsonNode inputSpec) { if(inputSpec == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity( "No specification supplied in either the url or request body. Try again?" ); } String inputAsString = Json.pretty(inputSpec); ValidationResponse validationResponse = null; try { validationResponse = debugByContent(request ,inputAsString); }catch (Exception e){ return new ResponseContext().status(Response.Status.INTERNAL_SERVER_ERROR).entity( "Failed to process URL" ); } return processValidationResponse(validationResponse); }
Example #16
Source File: PetController.java From swagger-petstore with Apache License 2.0 | 6 votes |
public ResponseContext deletePet(final RequestContext request, final String apiKey, final Long petId) { if (petId == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity("No petId provided. Try again?"); } petData.deletePetById(petId); final MediaType outputType = Util.getMediaType(request); final Pet pet = petData.getPetById(petId); if (null == pet) { return new ResponseContext() .contentType(outputType) .entity("Pet deleted"); } else { return new ResponseContext().status(Response.Status.NOT_MODIFIED).entity("Pet couldn't be deleted."); } }
Example #17
Source File: ValidatorController.java From validator-badge with Apache License 2.0 | 6 votes |
public ResponseContext reviewByUrl(RequestContext request , String url) { if(url == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity( "No specification supplied in either the url or request body. Try again?" ); } ValidationResponse validationResponse = null; try { validationResponse = debugByUrl(request, url); }catch (Exception e){ return new ResponseContext().status(Response.Status.INTERNAL_SERVER_ERROR).entity( "Failed to process specification" ); } return new ResponseContext() .entity(validationResponse); //return processDebugValidationResponse(validationResponse); }
Example #18
Source File: ValidatorController.java From validator-badge with Apache License 2.0 | 6 votes |
public ResponseContext reviewByContent(RequestContext request, JsonNode inputSpec) { if(inputSpec == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity( "No specification supplied in either the url or request body. Try again?" ); } String inputAsString = Json.pretty(inputSpec); ValidationResponse validationResponse = null; try { validationResponse = debugByContent(request ,inputAsString); }catch (Exception e){ return new ResponseContext().status(Response.Status.INTERNAL_SERVER_ERROR).entity( "Failed to process specification" ); } return new ResponseContext() .entity(validationResponse); //return processDebugValidationResponse(validationResponse); }
Example #19
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 6 votes |
@Test public void testDebugInvalid30SpecByUrl() throws Exception { String url = "http://localhost:${dynamicPort}/invalid/yaml"; url = url.replace("${dynamicPort}", String.valueOf(this.serverPort)); ValidatorController validator = new ValidatorController(); ResponseContext response = validator.reviewByUrl(new RequestContext(), url); // since inflector 2.0.3 content type is managed by inflector according to request headers and spec /* Assert.assertEquals(APPLICATION, response.getContentType().getType()); Assert.assertEquals(JSON, response.getContentType().getSubtype()); */ ValidationResponse validationResponse = (ValidationResponse) response.getEntity(); Assert.assertTrue(validationResponse.getMessages().contains(INFO_MISSING)); Assert.assertTrue(validationResponse.getSchemaValidationMessages().get(0).getMessage().equals(INFO_MISSING_SCHEMA)); }
Example #20
Source File: PetController.java From swagger-petstore with Apache License 2.0 | 6 votes |
public ResponseContext updatePet(final RequestContext request, final Pet pet) { if (pet == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity("No Pet provided. Try again?"); } final Pet existingPet = petData.getPetById(pet.getId()); if (existingPet == null) { return new ResponseContext().status(Response.Status.NOT_FOUND).entity("Pet not found"); } petData.deletePetById(existingPet.getId()); petData.addPet(pet); return new ResponseContext() .contentType(Util.getMediaType(request)) .entity(pet); }
Example #21
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 6 votes |
@Test public void testDebugValid20SpecByUrl() throws Exception { String url = "http://localhost:${dynamicPort}/validswagger/yaml"; url = url.replace("${dynamicPort}", String.valueOf(this.serverPort)); ValidatorController validator = new ValidatorController(); ResponseContext response = validator.reviewByUrl(new RequestContext(), url); // since inflector 2.0.3 content type is managed by inflector according to request headers and spec /* Assert.assertEquals(APPLICATION, response.getContentType().getType()); Assert.assertEquals(JSON, response.getContentType().getSubtype()); */ ValidationResponse validationResponse = (ValidationResponse) response.getEntity(); Assert.assertTrue(validationResponse.getMessages() == null || validationResponse.getMessages().size() == 0); Assert.assertTrue(validationResponse.getSchemaValidationMessages() == null || validationResponse.getSchemaValidationMessages().size() == 0); }
Example #22
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 6 votes |
@Test public void testValidateValid20SpecByUrl() throws Exception { String url = "http://localhost:${dynamicPort}/validswagger/yaml"; url = url.replace("${dynamicPort}", String.valueOf(this.serverPort)); ValidatorController validator = new ValidatorController(); ResponseContext response = validator.validateByUrl(new RequestContext(), url); Assert.assertEquals(IMAGE, response.getContentType().getType()); Assert.assertEquals(PNG, response.getContentType().getSubtype()); InputStream entity = (InputStream)response.getEntity(); InputStream valid = this.getClass().getClassLoader().getResourceAsStream(VALID_IMAGE); Assert.assertTrue( validateEquals(entity,valid) == true); }
Example #23
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 6 votes |
@Test public void testValidateValid30SpecByUrl() throws Exception { String url = "http://localhost:${dynamicPort}/valid/yaml"; url = url.replace("${dynamicPort}", String.valueOf(this.serverPort)); ValidatorController validator = new ValidatorController(); ResponseContext response = validator.validateByUrl(new RequestContext(), url); Assert.assertEquals(IMAGE, response.getContentType().getType()); Assert.assertEquals(PNG, response.getContentType().getSubtype()); InputStream entity = (InputStream)response.getEntity(); InputStream valid = this.getClass().getClassLoader().getResourceAsStream(VALID_IMAGE); Assert.assertTrue( validateEquals(entity,valid) == true); }
Example #24
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 6 votes |
@Test public void testValidateInvalid30SpecByUrl() throws Exception { String url = "http://localhost:${dynamicPort}/invalid/yaml"; url = url.replace("${dynamicPort}", String.valueOf(this.serverPort)); ValidatorController validator = new ValidatorController(); ResponseContext response = validator.validateByUrl(new RequestContext(), url); Assert.assertEquals(IMAGE, response.getContentType().getType()); Assert.assertEquals(PNG, response.getContentType().getSubtype()); InputStream entity = (InputStream)response.getEntity(); InputStream valid = this.getClass().getClassLoader().getResourceAsStream(INVALID_IMAGE); Assert.assertTrue( validateEquals(entity,valid) == true); }
Example #25
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 6 votes |
@Test public void testValidateInvalid20SpecByUrl() throws Exception { String url = "http://localhost:${dynamicPort}/invalidswagger/yaml"; url = url.replace("${dynamicPort}", String.valueOf(this.serverPort)); ValidatorController validator = new ValidatorController(); ResponseContext response = validator.validateByUrl(new RequestContext(), url); Assert.assertEquals(IMAGE, response.getContentType().getType()); Assert.assertEquals(PNG, response.getContentType().getSubtype()); InputStream entity = (InputStream)response.getEntity(); InputStream valid = this.getClass().getClassLoader().getResourceAsStream(INVALID_IMAGE); Assert.assertTrue( validateEquals(entity,valid) == true); }
Example #26
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 6 votes |
@Test public void testDebugValid30SpecByUrl() throws Exception { String url = "http://localhost:${dynamicPort}/valid/yaml"; url = url.replace("${dynamicPort}", String.valueOf(this.serverPort)); ValidatorController validator = new ValidatorController(); ResponseContext response = validator.reviewByUrl(new RequestContext(), url); // since inflector 2.0.3 content type is managed by inflector according to request headers and spec /* Assert.assertEquals(APPLICATION, response.getContentType().getType()); Assert.assertEquals(JSON, response.getContentType().getSubtype()); */ ValidationResponse validationResponse = (ValidationResponse) response.getEntity(); Assert.assertTrue(validationResponse.getMessages() == null || validationResponse.getMessages().size() == 0); Assert.assertTrue(validationResponse.getSchemaValidationMessages() == null || validationResponse.getSchemaValidationMessages().size() == 0); }
Example #27
Source File: TestController.java From swagger-inflector with Apache License 2.0 | 6 votes |
public ResponseContext withModel(RequestContext request, String id, Address address) { if("-1".equals(id)) { return new ResponseContext() .status(Status.OK) .entity("oops! This isn't valid!"); } else { if(address == null) { address = new Address(); } address.setStreet(id + " street"); return new ResponseContext() .status(Status.OK) .entity(address); } }
Example #28
Source File: ValidatorTest.java From validator-badge with Apache License 2.0 | 6 votes |
@Test public void testValidateInvalid30SpecByContent() throws Exception { final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); final JsonNode rootNode = mapper.readTree(Files.readAllBytes(java.nio.file.Paths.get(getClass().getResource(INVALID_30_YAML).toURI()))); ValidatorController validator = new ValidatorController(); ResponseContext response = validator.validateByContent(new RequestContext(), rootNode); Assert.assertEquals(IMAGE, response.getContentType().getType()); Assert.assertEquals(PNG, response.getContentType().getSubtype()); InputStream entity = (InputStream)response.getEntity(); InputStream valid = this.getClass().getClassLoader().getResourceAsStream(INVALID_IMAGE); Assert.assertTrue( validateEquals(entity,valid) == true); }
Example #29
Source File: PetController.java From swagger-petstore with Apache License 2.0 | 6 votes |
public ResponseContext getPetById(final RequestContext request, final Long petId) { if (petId == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity("No petId provided. Try again?"); } final Pet pet = petData.getPetById(petId); if (pet != null) { return new ResponseContext() .contentType(Util.getMediaType(request)) .entity(pet); } return new ResponseContext().status(Response.Status.NOT_FOUND).entity("Pet not found"); }
Example #30
Source File: TestController.java From swagger-inflector with Apache License 2.0 | 5 votes |
public ResponseContext postFormData(RequestContext request, Long id, String name) { // show a sample response return new ResponseContext() .status(Status.OK) .contentType(MediaType.APPLICATION_JSON_TYPE) .entity(new User() .id(id) .user(name)); }