コード例 #1
0
        public static List <string> ImportFrom(this IType type, string ns)
        {
            List <string> imports        = new List <string>();
            var           sequenceType   = type as SequenceType;
            var           dictionaryType = type as DictionaryType;
            var           primaryType    = type as PrimaryType;
            var           compositeType  = type as CompositeType;

            if (sequenceType != null)
            {
                imports.Add("java.util.List");
                imports.AddRange(sequenceType.ElementType.ImportFrom(ns));
            }
            else if (dictionaryType != null)
            {
                imports.Add("java.util.Map");
                imports.AddRange(dictionaryType.ValueType.ImportFrom(ns));
            }
            else if (compositeType != null && ns != null)
            {
                if (type.Name.Contains('<'))
                {
                    imports.AddRange(compositeType.ParseGenericType().SelectMany(t => t.ImportFrom(ns)));
                }
                else if (compositeType.Extensions.ContainsKey(ExternalExtension) &&
                         (bool)compositeType.Extensions[ExternalExtension])
                {
                    imports.Add(string.Join(
                                    ".",
                                    "com.microsoft.rest",
                                    type.Name));
                }
                else
                {
                    imports.Add(string.Join(
                                    ".",
                                    ns.ToLower(CultureInfo.InvariantCulture),
                                    "models",
                                    type.Name));
                }
            }
            else if (type is EnumType && ns != null)
            {
                imports.Add(string.Join(
                                ".",
                                ns.ToLower(CultureInfo.InvariantCulture),
                                "models",
                                type.Name));
            }
            else if (primaryType != null)
            {
                var importedFrom = JavaCodeNamer.GetJavaType(primaryType);
                if (importedFrom != null)
                {
                    imports.Add(importedFrom);
                }
            }
            return(imports);
        }
コード例 #2
0
 public static List <string> ImportFrom(this IType type, string ns, JavaCodeNamer namer)
 {
     if (namer == null)
     {
         return(null);
     }
     return(namer.ImportType(type, ns));
 }
コード例 #3
0
 public ModelTemplateModel(CompositeType source, ServiceClient serviceClient)
 {
     this.LoadFrom(source);
     ServiceClient = serviceClient;
     if (source.BaseModelType != null)
     {
         _parent = new ModelTemplateModel(source.BaseModelType, serviceClient);
     }
     _namer         = new JavaCodeNamer(serviceClient.Namespace);
     PropertyModels = new List <PropertyModel>();
     Properties.ForEach(p => PropertyModels.Add(new PropertyModel(p, serviceClient.Namespace)));
 }
コード例 #4
0
 public ModelTemplateModel(CompositeType source, ServiceClient serviceClient)
 {
     this.LoadFrom(source);
     ServiceClient = serviceClient;
     if(source.BaseModelType != null)
     {
         _parent = new ModelTemplateModel(source.BaseModelType, serviceClient);
     }
     _namer = new JavaCodeNamer(serviceClient.Namespace);
     PropertyModels = new List<PropertyModel>();
     Properties.ForEach(p => PropertyModels.Add(new PropertyModel(p, serviceClient.Namespace)));
 }
コード例 #5
0
        public static HashSet <string> TypeImports(this IList <IType> types, String ns)
        {
            HashSet <string> imports = new HashSet <string>();

            if (types == null || ns == null)
            {
                return(imports);
            }

            for (int i = 0; i < types.Count; i++)
            {
                var type           = types[i];
                var sequenceType   = type as SequenceType;
                var dictionaryType = type as DictionaryType;
                var primaryType    = type as PrimaryType;
                if (sequenceType != null)
                {
                    imports.Add("java.util.List");
                    types.Add(sequenceType.ElementType);
                }
                else if (dictionaryType != null)
                {
                    imports.Add("java.util.Map");
                    types.Add(dictionaryType.ValueType);
                }
                else if (type is CompositeType || type is EnumType)
                {
                    imports.Add(string.Join(
                                    ".",
                                    ns.ToLower(CultureInfo.InvariantCulture),
                                    "models",
                                    type.Name));
                }
                else if (primaryType != null)
                {
                    var importedFrom = JavaCodeNamer.ImportedFrom(primaryType);
                    if (importedFrom != null)
                    {
                        imports.Add(importedFrom);
                    }
                }
            }
            return(imports);
        }
コード例 #6
0
        public void TestClientNameJavaNormalization()
        {
            var setting = new Settings
            {
                Namespace = "Test",
                Input     = Path.Combine("Swagger", "swagger-x-ms-client-name.json")
            };

            var modeler     = new SwaggerModeler(setting);
            var clientModel = modeler.Build();

            SwaggerExtensions.NormalizeClientModel(clientModel, setting);
            var namer = new JavaCodeNamer(setting.Namespace);

            namer.NormalizeClientModel(clientModel);

            Assert.NotNull(clientModel);
            Assert.Equal(2, clientModel.Methods.Count);

            Assert.Equal(2, clientModel.Methods[0].Parameters.Where(p => !p.IsClientProperty).Count());

            Assert.Equal("subscription", clientModel.Methods[0].Parameters[0].GetClientName());
            Assert.Equal("version", clientModel.Methods[0].Parameters[1].GetClientName());
            Assert.Equal("subscription", clientModel.Methods[0].Parameters[0].Name);
            Assert.Equal("version", clientModel.Methods[0].Parameters[1].Name);

            Assert.Equal(2, clientModel.Properties.Count);
            Assert.Equal(0, clientModel.Methods[1].Parameters.Where(p => !p.IsClientProperty).Count());

            Assert.Equal("subscription", clientModel.Properties[0].GetClientName());
            Assert.Equal("_version", clientModel.Properties[1].GetClientName());
            Assert.Equal("subscription", clientModel.Properties[0].Name);
            Assert.Equal("_version", clientModel.Properties[1].Name);

            var type = clientModel.ModelTypes.First();

            Assert.Equal("errorCode", type.Properties[0].Name);
            Assert.Equal("errorMessage", type.Properties[1].Name);
            Assert.Equal("parentError", type.Properties[2].Name);
        }