use of com.google.api.server.spi.config.model.ApiConfig in project endpoints-java by cloudendpoints.
the class SwaggerGeneratorTest method testWriteSwagger_FooEndpointDefaultContext.
@Test
public void testWriteSwagger_FooEndpointDefaultContext() throws Exception {
ApiConfig config = configLoader.loadConfiguration(ServiceContext.create(), FooEndpoint.class);
Swagger swagger = generator.writeSwagger(ImmutableList.of(config), false, new SwaggerContext());
Swagger expected = readExpectedAsSwagger("foo_endpoint_default_context.swagger");
compareSwagger(expected, swagger);
}
use of com.google.api.server.spi.config.model.ApiConfig in project endpoints-java by cloudendpoints.
the class JsonConfigWriter method convertApiMethods.
private void convertApiMethods(Iterable<? extends ApiConfig> configs, ObjectNode root) throws IllegalArgumentException, SecurityException, ApiConfigException {
ObjectNode methodsNode = objectMapper.createObjectNode();
ObjectNode descriptorNode = objectMapper.createObjectNode();
ObjectNode descriptorSchemasNode = objectMapper.createObjectNode();
ObjectNode descriptorMethodsNode = objectMapper.createObjectNode();
descriptorNode.set("schemas", descriptorSchemasNode);
descriptorNode.set("methods", descriptorMethodsNode);
for (ApiConfig config : configs) {
convertApiMethods(methodsNode, descriptorSchemasNode, descriptorMethodsNode, config);
}
root.set("methods", methodsNode);
root.set("descriptor", descriptorNode);
}
use of com.google.api.server.spi.config.model.ApiConfig in project endpoints-java by cloudendpoints.
the class DiscoveryGenerator method writeApi.
private RestDescription writeApi(ApiKey apiKey, Iterable<ApiConfig> apiConfigs, DiscoveryContext context, SchemaRepository repo) {
// The first step is to scan all methods and try to extract a base path, aka a common prefix
// for all methods. This prefix must end in a slash and can't contain any path parameters.
String servicePath = computeApiServicePath(apiConfigs);
String basePath = context.basePath + "/" + servicePath;
RestDescription doc = REST_SKELETON.clone().setBasePath(basePath).setBaseUrl(context.getApiRoot() + "/" + servicePath).setId(apiKey.getName() + ":" + apiKey.getVersion()).setName(apiKey.getName()).setRootUrl(context.getApiRoot() + "/").setServicePath(servicePath).setVersion(apiKey.getVersion());
for (ApiConfig config : apiConfigs) {
// precedence here if there happens to be divergence.
if (config.getDescription() != null) {
doc.setDescription(config.getDescription());
}
if (config.getTitle() != null) {
doc.setTitle(config.getTitle());
}
if (config.getDocumentationLink() != null) {
doc.setDocumentationLink(config.getDocumentationLink());
}
if (config.getNamespaceConfig() != null) {
ApiNamespaceConfig namespaceConfig = config.getNamespaceConfig();
if (!Strings.isEmptyOrWhitespace(namespaceConfig.getOwnerName())) {
doc.setOwnerName(namespaceConfig.getOwnerName());
}
if (!Strings.isEmptyOrWhitespace(namespaceConfig.getOwnerDomain())) {
doc.setOwnerDomain(namespaceConfig.getOwnerDomain());
}
if (!Strings.isEmptyOrWhitespace(namespaceConfig.getPackagePath())) {
doc.setPackagePath(namespaceConfig.getPackagePath());
}
}
if (config.getCanonicalName() != null) {
doc.setCanonicalName(config.getCanonicalName());
}
for (ApiMethodConfig methodConfig : config.getApiClassConfig().getMethods().values()) {
if (!methodConfig.isIgnored()) {
writeApiMethod(config, servicePath, doc, methodConfig, repo);
}
}
}
List<Schema> schemas = repo.getAllSchemaForApi(apiKey);
if (!schemas.isEmpty()) {
Map<String, JsonSchema> docSchemas = Maps.newTreeMap();
for (Schema schema : schemas) {
docSchemas.put(schema.name(), convertToDiscoverySchema(schema));
}
doc.setSchemas(docSchemas);
}
return doc;
}
use of com.google.api.server.spi.config.model.ApiConfig in project endpoints-java by cloudendpoints.
the class AbstractDiscoveryProvider method getApiConfigs.
ImmutableList<ApiConfig> getApiConfigs(String name, String version) throws NotFoundException {
ApiKey key = new ApiKey(name, version, null);
ImmutableList<ApiConfig> configs = configsByKey.get(key);
if (configs.isEmpty()) {
logger.info("No configuration found for name: " + name + ", version: " + version);
throw new NotFoundException("Not Found");
}
return configs;
}
use of com.google.api.server.spi.config.model.ApiConfig in project endpoints-java by cloudendpoints.
the class JsonConfigWriterTest method writeConfigOrderIsPreservedMulticlass.
@Test
public void writeConfigOrderIsPreservedMulticlass() throws Exception {
@Api(name = "onetoday", description = "OneToday API")
final class OneToday {
}
@Api(name = "onetoday", description = "OneToday API")
final class OneToday2 {
}
@Api(name = "onetodayadmin", description = "One Today Admin API")
final class OneTodayAdmin {
}
@Api(name = "onetodayadmin", description = "One Today Admin API")
final class OneTodayAdmin2 {
}
ApiConfigValidator validator = Mockito.mock(ApiConfigValidator.class);
TypeLoader typeLoader = new TypeLoader();
JsonConfigWriter writer = new JsonConfigWriter(new TypeLoader(JsonConfigWriter.class.getClassLoader()), validator);
ApiConfig oneToday = new ApiConfig.Factory().create(serviceContext, typeLoader, OneToday.class);
ApiConfig oneToday2 = new ApiConfig.Factory().create(serviceContext, typeLoader, OneToday2.class);
ApiConfig oneTodayAdmin = new ApiConfig.Factory().create(serviceContext, typeLoader, OneTodayAdmin.class);
ApiConfig oneTodayAdmin2 = new ApiConfig.Factory().create(serviceContext, typeLoader, OneTodayAdmin2.class);
oneToday.setName("onetoday");
oneToday.setVersion("v1");
oneToday2.setName("onetoday");
oneToday2.setVersion("v1");
oneTodayAdmin.setName("onetodayadmin");
oneTodayAdmin.setVersion("v1");
oneTodayAdmin2.setName("onetodayadmin");
oneTodayAdmin2.setVersion("v1");
Map<ApiKey, String> configs = writer.writeConfig(Lists.newArrayList(oneToday, oneTodayAdmin, oneTodayAdmin2, oneToday2));
Iterator<ApiKey> iterator = configs.keySet().iterator();
assertEquals(new ApiKey("onetoday", "v1", "https://myapp.appspot.com/_ah/api"), iterator.next());
assertEquals(new ApiKey("onetodayadmin", "v1", "https://myapp.appspot.com/_ah/api"), iterator.next());
}
Aggregations