Search in sources :

Example 1 with DefaultClassResolver

use of org.apache.camel.impl.engine.DefaultClassResolver in project camel-spring-boot by apache.

the class ComplexTypesTest method checkSchemaGeneration.

private void checkSchemaGeneration(String uri, String apiVersion, String schemaResource) throws Exception {
    BeanConfig config = getBeanConfig(apiVersion);
    List<RestDefinition> rests = ((ModelCamelContext) context).getRestDefinitions().stream().filter(def -> def.getVerbs().isEmpty() || def.getVerbs().get(0).getPath().equals(uri)).collect(Collectors.toList());
    RestOpenApiReader reader = new RestOpenApiReader();
    OasDocument openApi = reader.read(context, rests, config, context.getName(), new DefaultClassResolver());
    assertNotNull(openApi);
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    Object dump = Library.writeNode(openApi);
    String json = mapper.writeValueAsString(dump);
    LOG.info(json);
    json = generify(json);
    InputStream is = getClass().getClassLoader().getResourceAsStream("org/apache/camel/openapi/" + schemaResource);
    assertNotNull(is);
    String expected = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
    is.close();
    assertEquals(expected, json);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) CamelAutoConfiguration(org.apache.camel.spring.boot.CamelAutoConfiguration) LoggerFactory(org.slf4j.LoggerFactory) SampleComplexRequestType(org.apache.camel.openapi.model.SampleComplexRequestType) Autowired(org.springframework.beans.factory.annotation.Autowired) BindToRegistry(org.apache.camel.BindToRegistry) CamelSpringBootTest(org.apache.camel.test.spring.junit5.CamelSpringBootTest) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CamelContext(org.apache.camel.CamelContext) Logger(org.slf4j.Logger) RestBindingMode(org.apache.camel.model.rest.RestBindingMode) Library(io.apicurio.datamodels.Library) SampleComplexResponseType(org.apache.camel.openapi.model.SampleComplexResponseType) DefaultClassResolver(org.apache.camel.impl.engine.DefaultClassResolver) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) ModelCamelContext(org.apache.camel.model.ModelCamelContext) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RouteBuilder(org.apache.camel.builder.RouteBuilder) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) Bean(org.springframework.context.annotation.Bean) BufferedReader(java.io.BufferedReader) OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) RestDefinition(org.apache.camel.model.rest.RestDefinition) InputStream(java.io.InputStream) OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) RestDefinition(org.apache.camel.model.rest.RestDefinition) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) DefaultClassResolver(org.apache.camel.impl.engine.DefaultClassResolver) BufferedReader(java.io.BufferedReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with DefaultClassResolver

use of org.apache.camel.impl.engine.DefaultClassResolver in project camel-spring-boot by apache.

the class RestOpenApiReaderFileResponseModelTest method testReaderReadV3.

@Test
public void testReaderReadV3() throws Exception {
    BeanConfig config = new BeanConfig();
    config.setHost("localhost:8080");
    config.setSchemes(new String[] { "http" });
    config.setBasePath("/api");
    Oas30Info info = new Oas30Info();
    config.setInfo(info);
    RestOpenApiReader reader = new RestOpenApiReader();
    OasDocument openApi = reader.read(context, ((ModelCamelContext) context).getRestDefinitions(), config, context.getName(), new DefaultClassResolver());
    assertNotNull(openApi);
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    Object dump = Library.writeNode(openApi);
    String json = mapper.writeValueAsString(dump);
    LOG.info(json);
    assertTrue(json.contains("\"format\" : \"binary\""));
    assertTrue(json.contains("\"type\" : \"string\""));
    context.stop();
}
Also used : OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) DefaultClassResolver(org.apache.camel.impl.engine.DefaultClassResolver) Oas30Info(io.apicurio.datamodels.openapi.v3.models.Oas30Info) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CamelSpringBootTest(org.apache.camel.test.spring.junit5.CamelSpringBootTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with DefaultClassResolver

use of org.apache.camel.impl.engine.DefaultClassResolver in project camel-spring-boot by apache.

the class RestOpenApiReaderModelApiSecurityTest method testReaderReadV3.

@Test
public void testReaderReadV3() throws Exception {
    BeanConfig config = new BeanConfig();
    config.setHost("localhost:8080");
    config.setSchemes(new String[] { "http" });
    config.setBasePath("/api");
    config.setTitle("Camel User store");
    config.setLicense("Apache 2.0");
    config.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html");
    RestOpenApiReader reader = new RestOpenApiReader();
    OasDocument openApi = reader.read(context, ((ModelCamelContext) context).getRestDefinitions(), config, context.getName(), new DefaultClassResolver());
    assertNotNull(openApi);
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    Object dump = Library.writeNode(openApi);
    String json = mapper.writeValueAsString(dump);
    log.info(json);
    assertTrue(json.contains("securitySchemes"));
    assertTrue(json.contains("\"type\" : \"oauth2\""));
    assertTrue(json.contains("\"authorizationUrl\" : \"http://petstore.swagger.io/oauth/dialog\""));
    assertTrue(json.contains("\"flows\" : {"));
    assertTrue(json.contains("\"implicit\""));
    assertTrue(json.contains("\"type\" : \"apiKey\","));
    assertTrue(json.contains("\"in\" : \"header\""));
    assertTrue(json.contains("\"url\" : \"http://localhost:8080/api\""));
    assertTrue(json.contains("\"security\" : [ {"));
    assertTrue(json.contains("\"petstore_auth\" : [ \"write:pets\", \"read:pets\" ]"));
    assertTrue(json.contains("\"api_key\" : [ ]"));
    assertTrue(json.contains("\"description\" : \"The user returned\""));
    assertTrue(json.contains("\"$ref\" : \"#/components/schemas/User\""));
    assertTrue(json.contains("\"x-className\""));
    assertTrue(json.contains("\"format\" : \"org.apache.camel.openapi.User\""));
    assertTrue(json.contains("\"type\" : \"string\""));
    assertTrue(json.contains("\"format\" : \"date\""));
    assertFalse(json.contains("\"enum\""));
    context.stop();
}
Also used : OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) DefaultClassResolver(org.apache.camel.impl.engine.DefaultClassResolver) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CamelSpringBootTest(org.apache.camel.test.spring.junit5.CamelSpringBootTest)

Example 4 with DefaultClassResolver

use of org.apache.camel.impl.engine.DefaultClassResolver in project camel-spring-boot by apache.

the class RestOpenApiReaderModelBookOrderTest method testReaderReadV3.

@Test
public void testReaderReadV3() throws Exception {
    BeanConfig config = new BeanConfig();
    config.setHost("localhost:8080");
    config.setSchemes(new String[] { "http" });
    config.setBasePath("/api");
    config.setTitle("Camel User store");
    config.setLicense("Apache 2.0");
    config.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html");
    RestOpenApiReader reader = new RestOpenApiReader();
    OasDocument openApi = reader.read(context, ((ModelCamelContext) context).getRestDefinitions(), config, context.getName(), new DefaultClassResolver());
    assertNotNull(openApi);
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    Object dump = Library.writeNode(openApi);
    String json = mapper.writeValueAsString(dump);
    log.info(json);
    assertTrue(json.contains("\"url\" : \"http://localhost:8080/api\""));
    assertTrue(json.contains("\"description\" : \"The order returned\""));
    assertTrue(json.contains("\"BookOrder\""));
    assertTrue(json.contains("\"LineItem\""));
    assertTrue(json.contains("\"$ref\" : \"#/components/schemas/BookOrder"));
    assertTrue(json.contains("\"$ref\" : \"#/components/schemas/LineItem"));
    assertTrue(json.contains("\"x-className\""));
    assertTrue(json.contains("\"format\" : \"org.apache.camel.openapi.BookOrder\""));
    assertTrue(json.contains("\"format\" : \"org.apache.camel.openapi.LineItem\""));
    context.stop();
}
Also used : OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) DefaultClassResolver(org.apache.camel.impl.engine.DefaultClassResolver) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CamelSpringBootTest(org.apache.camel.test.spring.junit5.CamelSpringBootTest)

Example 5 with DefaultClassResolver

use of org.apache.camel.impl.engine.DefaultClassResolver in project camel-spring-boot by apache.

the class RestOpenApiReaderModelTest method testReaderReadV3.

@Test
public void testReaderReadV3() throws Exception {
    BeanConfig config = new BeanConfig();
    config.setHost("localhost:8080");
    config.setSchemes(new String[] { "http" });
    config.setBasePath("/api");
    config.setTitle("Camel User store");
    config.setLicense("Apache 2.0");
    config.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html");
    RestOpenApiReader reader = new RestOpenApiReader();
    OasDocument openApi = reader.read(context, ((ModelCamelContext) context).getRestDefinitions(), config, context.getName(), new DefaultClassResolver());
    assertNotNull(openApi);
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    Object dump = Library.writeNode(openApi);
    String json = mapper.writeValueAsString(dump);
    log.info(json);
    assertTrue(json.contains("\"url\" : \"http://localhost:8080/api\""));
    assertTrue(json.contains("\"description\" : \"The user returned\""));
    assertTrue(json.contains("\"$ref\" : \"#/components/schemas/User\""));
    assertTrue(json.contains("\"x-className\""));
    assertTrue(json.contains("\"format\" : \"org.apache.camel.openapi.User\""));
    assertTrue(json.contains("\"type\" : \"string\""));
    assertTrue(json.contains("\"format\" : \"date\""));
    assertFalse(json.contains("\"enum\""));
    context.stop();
}
Also used : OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) DefaultClassResolver(org.apache.camel.impl.engine.DefaultClassResolver) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CamelSpringBootTest(org.apache.camel.test.spring.junit5.CamelSpringBootTest)

Aggregations

DefaultClassResolver (org.apache.camel.impl.engine.DefaultClassResolver)31 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)30 OasDocument (io.apicurio.datamodels.openapi.models.OasDocument)30 Test (org.junit.jupiter.api.Test)30 CamelSpringBootTest (org.apache.camel.test.spring.junit5.CamelSpringBootTest)28 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)28 Oas20Info (io.apicurio.datamodels.openapi.v2.models.Oas20Info)3 Oas30Info (io.apicurio.datamodels.openapi.v3.models.Oas30Info)3 ModelCamelContext (org.apache.camel.model.ModelCamelContext)3 RestDefinition (org.apache.camel.model.rest.RestDefinition)2 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 Library (io.apicurio.datamodels.Library)1 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 StandardCharsets (java.nio.charset.StandardCharsets)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 BindToRegistry (org.apache.camel.BindToRegistry)1