Exemple #1
0
        public PackageModel(RestDescription discoveryDoc, Features features, PackageEnumStorage enumStorage)
        {
            _features     = features;
            _discoveryDoc = discoveryDoc;
            ApiName       = discoveryDoc.Name;

            // Note that spaces are removed first, because the Python code doesn't Pascal-case them. For example,
            // the "Cloud Memorystore for Memcached" API has a package name of "CloudMemorystoreforMemcached".
            // It's awful, but that's the way it works...
            ClassName  = (discoveryDoc.CanonicalName ?? discoveryDoc.Name).Replace(" ", "").ToMemberName();
            ApiVersion = discoveryDoc.Version;
            string versionNoDots        = discoveryDoc.Version.Replace('.', '_');
            var    camelizedPackagePath = discoveryDoc.PackagePath is null
                ? ""
                : string.Join('.', discoveryDoc.PackagePath.Split('/').Select(part => part.ToUpperCamelCase())) + ".";

            PackageName = $"Google.Apis.{camelizedPackagePath}{ClassName}.{versionNoDots}";
            DataModels  = discoveryDoc.Schemas.ToReadOnlyList(pair => new DataModel(this, parent: null, name: pair.Key, schema: pair.Value));

            // Populate the data model dictionary early, as methods and resources refer to the data model types.
            foreach (var dm in DataModels)
            {
                _dataModelsById[dm.Id] = dm;
            }
            Resources = discoveryDoc.Resources.ToReadOnlyList(pair => new ResourceModel(this, parent: null, pair.Key, pair.Value));
            // TODO: Ordering?
            AuthScopes = (discoveryDoc.Auth?.Oauth2?.Scopes).ToReadOnlyList(pair => new AuthScope(pair.Key, pair.Value.Description));
            ServiceTyp = Typ.Manual(PackageName, $"{ClassName}Service");
            GenericBaseRequestTypDef = Typ.Manual(PackageName, $"{ClassName}BaseServiceRequest");
            Methods            = discoveryDoc.Methods.ToReadOnlyList(pair => new MethodModel(this, null, pair.Key, pair.Value));
            PackageEnumStorage = enumStorage;
        }
Exemple #2
0
        public PackageModel(RestDescription discoveryDoc)
        {
            _discoveryDoc = discoveryDoc;
            ApiName       = discoveryDoc.Name;

            // Note that spaces are removed first, because the Python code doesn't Pascal-case them. For example,
            // the "Cloud Memorystore for Memcached" API has a package name of "CloudMemorystoreforMemcached".
            // It's awful, but that's the way it works...
            ClassName        = (discoveryDoc.CanonicalName ?? discoveryDoc.Name).Replace(" ", "").ToMemberName();
            ServiceClassName = $"{ClassName}Service";
            ApiVersion       = discoveryDoc.Version;
            VersionNoDots    = discoveryDoc.Version.Replace('.', '_');
            PackageName      = $"Google.Apis.{ClassName}.{VersionNoDots}";
            DataModels       = discoveryDoc.Schemas.ToReadOnlyList(pair => new DataModel(this, parent: null, name: pair.Key, schema: pair.Value));

            // Populate the data model dictionary early, as methods and resources refer to the data model types.
            foreach (var dm in DataModels)
            {
                _dataModels[dm.Id] = dm;
            }
            Resources   = discoveryDoc.Resources.ToReadOnlyList(pair => new ResourceModel(this, parent: null, pair.Key, pair.Value));
            ApiFeatures = discoveryDoc.Features.ToReadOnlyList();
            // TODO: Ordering?
            AuthScopes = (discoveryDoc.Auth?.Oauth2?.Scopes).ToReadOnlyList(pair => new AuthScope(pair.Key, pair.Value.Description));
            ServiceTyp = Typ.Manual(PackageName, ServiceClassName);
            GenericBaseRequestTypDef = Typ.Manual(PackageName, $"{ClassName}BaseServiceRequest");
            BaseRequestTyp           = Typ.Generic(GenericBaseRequestTypDef, Typ.GenericParam("TResponse"));
            BaseUri   = discoveryDoc.RootUrl + discoveryDoc.ServicePath;
            BasePath  = discoveryDoc.ServicePath;
            BatchUri  = discoveryDoc.RootUrl + discoveryDoc.BatchPath;
            BatchPath = discoveryDoc.BatchPath;
            Title     = discoveryDoc.Title;
            Methods   = discoveryDoc.Methods.ToReadOnlyList(pair => new MethodModel(this, null, pair.Key, pair.Value));
        }
Exemple #3
0
 public PackageModel(RestDescription discoveryDoc)
 {
     _discoveryDoc    = discoveryDoc;
     ApiName          = discoveryDoc.Name;
     ClassName        = ToClassName(discoveryDoc.CanonicalName);
     ServiceClassName = $"{ClassName}Service";
     ApiVersion       = discoveryDoc.Version;
     PackageName      = $"Google.Apis.{ClassName}.{ApiVersion}";
     VersionNoDots    = discoveryDoc.Version.Replace('.', '_');
     Resources        = discoveryDoc.Resources.ToReadOnlyList(pair => new ResourceModel(this, pair.Key, pair.Value));
     Features         = discoveryDoc.Features.ToReadOnlyList();
     // TODO: Ordering?
     AuthScopes = (discoveryDoc.Auth?.Oauth2?.Scopes).ToReadOnlyList(pair => new AuthScope(pair.Key, pair.Value.Description));
     ServiceTyp = Typ.Manual(PackageName, ServiceClassName);
     BaseUri    = discoveryDoc.RootUrl + discoveryDoc.ServicePath;
     BasePath   = discoveryDoc.ServicePath;
     BatchUri   = discoveryDoc.RootUrl + discoveryDoc.BatchPath;
     BatchPath  = discoveryDoc.BatchPath;
     Title      = discoveryDoc.Title;
     // TODO: Add in the anonymous schemas from method definitions
     DataModels = discoveryDoc.Schemas.ToReadOnlyList(pair => new DataModel(this, pair.Key, pair.Value));
     Methods    = discoveryDoc.Methods.ToReadOnlyList(pair => new MethodModel(this, pair.Key, pair.Value));
 }