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);
}
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();
}
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();
}
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();
}
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();
}
Aggregations