Exemplo n.º 1
0
 private BaseOutputClass CreateDefinition(string name, DocumentSchema schema)
 {
     if (schema.Ref != null)
     {
         var refName = schema.Ref.Remove("#/components/schemas/".Length);
         var @class  = new OutputClass()
         {
             Name = refName
         };
         return(@class);
     }
     if (schema.Enum != null)
     {
         //create enum
         var @enum = new OutputEnum()
         {
             Name = name
         };
         @enum.SetType(schema);
         @enum.Types = schema.Enum;
         return(@enum);
     }
     else
     {
         //create class
         var @class = new OutputClass()
         {
             Name = name
         };
         @class.SetType(schema);
         return(@class);
     }
 }
Exemplo n.º 2
0
        private string GenerateConstructor(OutputClass @class)
        {
            var sb = new StringBuilder();

            sb.AppendLine("\tconstructor() {");
            foreach (var type in @class.Properties)
            {
                sb.AppendLine($"\t\tthis.{type.Name} = {type.Class.DefaultValue};");
            }
            sb.AppendLine("\t}");
            return(sb.ToString());
        }
Exemplo n.º 3
0
        public static BaseOutputClass GetClassDefinition(DocumentSchema schema, List <BaseOutputClass> baseOutputClasses = null)
        {
            if (schema.Ref != null)
            {
                var refName = schema.Ref.Substring("#/components/schemas/".Length);

                if (baseOutputClasses != null)
                {
                    var item = baseOutputClasses.FirstOrDefault(p => p.Name == refName);

                    if (item != null)
                    {
                        if (item is OutputEnum)
                        {
                            var @enum = new OutputEnum()
                            {
                                Name = refName
                            };
                            return(@enum);
                        }
                    }
                }
                var @class = new OutputClass()
                {
                    Name = refName
                };
                return(@class);
            }
            if (schema.Enum != null)
            {
                //create enum
                var @enum = new OutputEnum()
                {
                };
                @enum.SetType(schema);
                @enum.Types = schema.Enum;
                return(@enum);
            }
            else
            {
                //create class
                var @class = new OutputClass()
                {
                };
                @class.SetType(schema);
                return(@class);
            }
        }
Exemplo n.º 4
0
        private List <BaseOutputClass> CollectAllReferenceTypes(OutputClass @class)
        {
            var referenceTypes = new List <BaseOutputClass>();

            foreach (var property in @class.Properties)
            {
                var referenceClass = GetReferenceClass(property.Class);
                if (referenceClass != null)
                {
                    if (!referenceTypes.Any(p => p.Name == referenceClass.Name))
                    {
                        referenceTypes.Add(referenceClass);
                    }
                }
            }
            return(referenceTypes);
        }
Exemplo n.º 5
0
        private string GenerateContentClass(OutputClass @class)
        {
            var sb = new StringBuilder();

            sb.AppendLine(GetAngularAllReferenceTypes(@class));
            sb.AppendLine($"export class {@class.AngularName} {{");
            foreach (var type in @class.Properties)
            {
                sb.AppendLine($"\t{type.Name} : {type.Class.AngularType};");
            }
            sb.AppendLine($"");

            sb.AppendLine(GenerateConstructor(@class));

            sb.AppendLine($"");
            sb.AppendLine($"}}");
            return(sb.ToString());
        }
Exemplo n.º 6
0
 internal BaseOutputClass CreateDefinitionWithDeep(DocumentSchema schema, List <BaseOutputClass> list)
 {
     if (schema.Enum != null)
     {
         return(ClassFactory.GetClassDefinition(schema));
     }
     else
     {
         //create class
         var @class = new OutputClass()
         {
         };
         @class.SetType(schema);
         @class.SetProperties(this, list, schema);
         @class.SetInnerClass(this, list, schema);
         return(@class);
     }
 }
Exemplo n.º 7
0
        private string GetAngularAllReferenceTypes(OutputClass @class)
        {
            var referenceTypes = CollectAllReferenceTypes(@class);
            var sb             = new StringBuilder();

            foreach (var referenceType in referenceTypes)
            {
                if (referenceType is OutputClass)
                {
                    sb.AppendLine($"import {{ {referenceType.AngularName} }} from './{referenceType.AngularName.GetKebabName()}.class';");
                }
                if (referenceType is OutputEnum)
                {
                    sb.AppendLine($"import {{ {referenceType.AngularName} }} from '../enums/{referenceType.AngularName.GetKebabName()}.enum';");
                }
            }
            if (referenceTypes.Count > 0)
            {
                sb.AppendLine("");
            }
            return(sb.ToString());
        }