コード例 #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);
     }
 }
コード例 #2
0
        private string GenerateContentEnum(OutputEnum @enum)
        {
            var sb = new StringBuilder();

            sb.AppendLine($"export enum {@enum.Name} {{");
            foreach (var type in @enum.Types)
            {
                if (type is int || type is long)
                {
                    int.TryParse(type.ToString(), out int result);
                    if (result < 0)
                    {
                        sb.AppendLine($"\tNUMBER_MINUS_{-result} = {result}, ");
                    }
                    else
                    {
                        sb.AppendLine($"\tNUMBER_{result} = {result}, ");
                    }
                }
                else
                {
                    sb.AppendLine($"\t{type.ToString()}, ");
                }
            }
            sb.AppendLine($"}}");
            return(sb.ToString());
        }
コード例 #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);
            }
        }