forked from apache/camel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rest-dsl binding part 1 (apache#13688)
CAMEL-20557: Rest DSL to use openapi spec directly
- Loading branch information
Showing
14 changed files
with
821 additions
and
235 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...amel/component/platform/http/vertx/PlatformHttpRestOpenApiConsumerRestDslBindingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.component.platform.http.vertx; | ||
|
||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.component.platform.http.vertx.model.Pet; | ||
import org.apache.camel.model.rest.RestBindingMode; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class PlatformHttpRestOpenApiConsumerRestDslBindingTest { | ||
|
||
@Test | ||
public void testRestOpenApi() throws Exception { | ||
final CamelContext context = VertxPlatformHttpEngineTest.createCamelContext(); | ||
|
||
try { | ||
context.addRoutes(new RouteBuilder() { | ||
@Override | ||
public void configure() { | ||
restConfiguration().bindingMode(RestBindingMode.json); | ||
|
||
rest().openApi().specification("openapi-v3.json").missingOperation("ignore"); | ||
|
||
from("direct:getPetById") | ||
.process(e -> { | ||
// build response body as POJO | ||
Pet pet = new Pet(); | ||
pet.setId(e.getMessage().getHeader("petId", long.class)); | ||
pet.setName("tony the tiger"); | ||
pet.setStatus(Pet.Status.AVAILABLE); | ||
e.getMessage().setBody(pet); | ||
}); | ||
} | ||
}); | ||
|
||
context.start(); | ||
|
||
given() | ||
.when() | ||
.get("/api/v3/pet/123") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("{\"id\":123,\"name\":\"tony the tiger\",\"status\":\"AVAILABLE\"}")); | ||
|
||
} finally { | ||
context.stop(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...rm-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/model/Pet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.component.platform.http.vertx.model; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.xml.bind.annotation.XmlElement; | ||
import jakarta.xml.bind.annotation.XmlRootElement; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
/** | ||
* The structure of this class must adhere to the schema defined in the Pet Store OpenAPI specification JSON / YAML. | ||
*/ | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@XmlRootElement(name = "Pet") | ||
public class Pet { | ||
@XmlElement | ||
private Long id; | ||
private String name; | ||
private Category category; | ||
private List<String> photoUrls; | ||
private List<Tag> tags; | ||
private Status status; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Category getCategory() { | ||
return category; | ||
} | ||
|
||
public void setCategory(Category category) { | ||
this.category = category; | ||
} | ||
|
||
public List<Tag> getTags() { | ||
return tags; | ||
} | ||
|
||
public void setTags(List<Tag> tags) { | ||
this.tags = tags; | ||
} | ||
|
||
public List<String> getPhotoUrls() { | ||
return photoUrls; | ||
} | ||
|
||
public void setPhotoUrls(List<String> photoUrls) { | ||
this.photoUrls = photoUrls; | ||
} | ||
|
||
public Status getStatus() { | ||
return status; | ||
} | ||
|
||
public void setStatus(Status status) { | ||
this.status = status; | ||
} | ||
|
||
public enum Status { | ||
AVAILABLE, | ||
PENDING, | ||
SOLD; | ||
|
||
@JsonCreator | ||
public static Status fromString(String status) { | ||
return Status.valueOf(status.toUpperCase()); | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...rm-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/model/Tag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.component.platform.http.vertx.model; | ||
|
||
import jakarta.xml.bind.annotation.XmlRootElement; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
/** | ||
* The structure of this class must adhere to the schema defined in the Pet Store OpenAPI specification JSON / YAML. | ||
*/ | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@XmlRootElement(name = "Tag") | ||
public class Tag { | ||
private Long id; | ||
private String name; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.