Search in sources :

Example 71 with ApiConfig

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);
}
Also used : SwaggerContext(com.google.api.server.spi.swagger.SwaggerGenerator.SwaggerContext) Swagger(io.swagger.models.Swagger) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Example 72 with ApiConfig

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);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ApiConfig(com.google.api.server.spi.config.model.ApiConfig)

Example 73 with ApiConfig

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;
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) Schema(com.google.api.server.spi.config.model.Schema) JsonSchema(com.google.api.services.discovery.model.JsonSchema) JsonSchema(com.google.api.services.discovery.model.JsonSchema) RestDescription(com.google.api.services.discovery.model.RestDescription) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) ApiNamespaceConfig(com.google.api.server.spi.config.model.ApiNamespaceConfig)

Example 74 with ApiConfig

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;
}
Also used : ApiKey(com.google.api.server.spi.config.model.ApiKey) NotFoundException(com.google.api.server.spi.response.NotFoundException) ApiConfig(com.google.api.server.spi.config.model.ApiConfig)

Example 75 with ApiConfig

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());
}
Also used : ApiKey(com.google.api.server.spi.config.model.ApiKey) ApiConfigValidator(com.google.api.server.spi.config.validation.ApiConfigValidator) TypeLoader(com.google.api.server.spi.TypeLoader) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Aggregations

ApiConfig (com.google.api.server.spi.config.model.ApiConfig)91 Test (org.junit.Test)72 Api (com.google.api.server.spi.config.Api)29 ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)26 SimpleLevelOverridingInheritedApi (com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi)20 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)18 ApiKey (com.google.api.server.spi.config.model.ApiKey)9 Swagger (io.swagger.models.Swagger)8 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)7 TypeLoader (com.google.api.server.spi.TypeLoader)5 ApiConfigLoader (com.google.api.server.spi.config.ApiConfigLoader)4 ApiConfigValidator (com.google.api.server.spi.config.validation.ApiConfigValidator)4 ServiceContext (com.google.api.server.spi.ServiceContext)3 ApiConfigAnnotationReader (com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ApiClass (com.google.api.server.spi.config.ApiClass)2 ApiFrontendLimits (com.google.api.server.spi.config.ApiFrontendLimits)2 ApiReference (com.google.api.server.spi.config.ApiReference)2 Named (com.google.api.server.spi.config.Named)2 ApiAuthConfig (com.google.api.server.spi.config.model.ApiAuthConfig)2