tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (TOMEE-2289) MicroProfile OpenAPI Example
Date Wed, 02 Jan 2019 12:39:00 GMT

    [ https://issues.apache.org/jira/browse/TOMEE-2289?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16732017#comment-16732017
] 

ASF GitHub Bot commented on TOMEE-2289:
---------------------------------------

Github user ivanjunckes commented on a diff in the pull request:

    https://github.com/apache/tomee/pull/340#discussion_r244726062
  
    --- Diff: examples/mp-openapi/src/test/java/org/superbiz/openapi/WeatherServiceTest.java
---
    @@ -0,0 +1,208 @@
    +package org.superbiz.openapi;
    +
    +import org.jboss.arquillian.container.test.api.Deployment;
    +import org.jboss.arquillian.junit.Arquillian;
    +import org.jboss.arquillian.test.api.ArquillianResource;
    +import org.jboss.shrinkwrap.api.ShrinkWrap;
    +import org.jboss.shrinkwrap.api.asset.StringAsset;
    +import org.jboss.shrinkwrap.api.spec.WebArchive;
    +
    +import org.junit.After;
    +import org.junit.Before;
    +import org.junit.Test;
    +import org.junit.runner.RunWith;
    +
    +import javax.json.Json;
    +import javax.json.JsonObject;
    +
    +import javax.ws.rs.client.Client;
    +import javax.ws.rs.client.ClientBuilder;
    +import javax.ws.rs.client.WebTarget;
    +import javax.ws.rs.core.MediaType;
    +import javax.ws.rs.core.Response;
    +
    +import java.io.StringReader;
    +
    +import java.net.URL;
    +import java.util.stream.Stream;
    +
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertTrue;
    +
    +@RunWith(Arquillian.class)
    +public class WeatherServiceTest {
    +
    +    @Deployment(testable = false)
    +    public static WebArchive createDeployment() {
    +        final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test.war")
    +                .addClass(WeatherService.class)
    +                .addClass(Weather.class)
    +                .addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml");
    +        return webArchive;
    +    }
    +
    +    @ArquillianResource
    +    private URL base;
    +
    +    private Client client;
    +
    +    @Before
    +    public void before() {
    +        this.client = ClientBuilder.newClient();
    +    }
    +
    +    @After
    +    public void after() {
    +        this.client.close();
    +    }
    +
    +    
    +    @Test
    +    public void dayStatus() {
    +        WebTarget webTarget = this.client.target(this.base.toExternalForm());
    +        final Response message =  webTarget.path("/openapi")
    +                .request()
    +                .accept(MediaType.APPLICATION_JSON)
    +                .get();
    +        final String metaData = message.readEntity(String.class);
    +        JsonObject jsonObject = Json.createReader(new StringReader(metaData)).readObject();
    +        JsonObject response=jsonObject.get("paths").asJsonObject().get("/weather/status/{day}").asJsonObject();
    +        final String expected = "{\r\n" + 
    +        		"            \"get\": {\r\n" + 
    +        		"                \"deprecated\": false,\r\n" + 
    +        		"                \"description\": \"Describes how the day will be.\",\r\n"
+ 
    +        		"                \"operationId\": \"dayStatus\",\r\n" + 
    +        		"                \"parameters\": [\r\n" + 
    +        		"                    {\r\n" + 
    +        		"                        \"allowEmptyValue\": false,\r\n" + 
    +        		"                        \"allowReserved\": false,\r\n" + 
    +        		"                        \"description\": \"The day for which the weather needs
to be fetched.\",\r\n" + 
    +        		"                        \"in\": \"path\",\r\n" + 
    +        		"                        \"name\": \"\",\r\n" + 
    +        		"                        \"required\": true,\r\n" + 
    +        		"                        \"schema\": {\r\n" + 
    +        		"                            \"type\": \"string\"\r\n" + 
    +        		"                        }\r\n" + 
    +        		"                    }\r\n" + 
    +        		"                ],\r\n" + 
    +        		"                \"responses\": {\r\n" + 
    +        		"                    \"400\": {\r\n" + 
    +        		"                        \"content\": {\r\n" + 
    +        		"                            \"200\": {}\r\n" + 
    +        		"                        },\r\n" + 
    +        		"                        \"description\": \"Weather for this day not found\"\r\n"
+ 
    +        		"                    }\r\n" + 
    +        		"                },\r\n" + 
    +        		"                \"summary\": \"Finds weather for day specified in the URL
\"\r\n" + 
    +        		"            }\r\n" + 
    +        		"        }";
    +        JsonObject expectedJson = Json.createReader(new StringReader(expected)).readObject();
    +        assertEquals(expectedJson.keySet().size(), response.keySet().size());
    +        String[] expectedKeys = new String[]{"deprecated", "description", "operationId",
"parameters", "responses", "summary"};
    +        Stream.of(expectedKeys).forEach((text) -> {
    +          assertTrue("Expected: " + text
    +                  + " to be present in " + expected,
    +                  expectedJson.getJsonObject("get").get(text) != null);
    +        });
    +        
    +
    +    }
    +    
    +    @Test
    +    public void detailedDayStatus() {
    +        WebTarget webTarget = this.client.target(this.base.toExternalForm());
    +        final Response message =  webTarget.path("/openapi")
    +                .request()
    +                .accept(MediaType.APPLICATION_JSON)
    +                .get();
    +        final String metaData = message.readEntity(String.class);
    +        JsonObject jsonObject = Json.createReader(new StringReader(metaData)).readObject();
    +        JsonObject response=jsonObject.get("paths").asJsonObject().get("/weather/detailedWeather/{day}").asJsonObject();
    +        final String expected = "{\r\n" + 
    +        		"            \"get\": {\r\n" + 
    +        		"                \"operationId\": \"getDetailedWeather\",\r\n" + 
    +        		"                \"parameters\": [\r\n" + 
    +        		"                    {\r\n" + 
    +        		"                        \"allowEmptyValue\": false,\r\n" + 
    --- End diff --
    
    There are a lot of values in the response that are not in the Weather pojo. This seems
to me like a bug in the implementation. Can you evaluate and raise this bug on the list?
    allowEmptyValue
    allowReserved
    required
    ... are not part of the pojo.


> MicroProfile OpenAPI Example
> ----------------------------
>
>                 Key: TOMEE-2289
>                 URL: https://issues.apache.org/jira/browse/TOMEE-2289
>             Project: TomEE
>          Issue Type: Sub-task
>          Components: Examples and Documentation
>    Affects Versions: 8.0.0-M1
>            Reporter: Ivan Junckes Filho
>            Assignee: Ivan Junckes Filho
>            Priority: Minor
>              Labels: examples, pull-request-available
>
> We would like to write an example for MicroProfile OpenApi.
> Here is the MicroProfile specification url:
> [https://download.eclipse.org/microprofile/microprofile-open-api-1.0.1/microprofile-openapi-spec.html]
> Fork / clone the TomEE project from here:
> [https://github.com/apache/tomee]
> Example name should be _mp-openapi_, following the standard already in the project.
> All the examples are in:
> [https://github.com/apache/tomee/tree/master/examples]
> See this example of Microprofile Metrics for reference:
> [https://github.com/apache/tomee/tree/master/examples/mp-metrics-counted]
>  
> What you have to do is:
> 1 - Create a JAX-RS endpoint with some methods (Using the same domain from metrics -
WeatherService would be good)
> 2 - Annotate with OpenApi annotations
> 3 - Write a test to assert the response in JSON and YAML
> 4 - Make sure all the tests pass
> After that submit a PR and we'll review it.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message