예제 #1
0
        static (string, string) PropType(JsonSchemaBase schema)
        {
            switch (schema.JsonSchemaType)
            {
            case JsonSchemaType.String:
            case JsonSchemaType.Boolean:
            case JsonSchemaType.Integer:
            case JsonSchemaType.Number:
            case JsonSchemaType.Object:
            case JsonSchemaType.Array:
                return(null, schema.ValueType);

            case JsonSchemaType.EnumString:
                return(null, schema.ValueType);
            }

            throw new NotImplementedException();
        }
예제 #2
0
        static string GetProtoType(JsonSchemaBase s, bool required)
        {
            switch (s.JsonSchemaType)
            {
            case JsonSchemaType.EnumString:
                if (!string.IsNullOrEmpty(s.Title))
                {
                    return(s.Title);
                }
                else
                {
                    var name = s.ClassName.Split("__").Last();
                    if (name == "type")
                    {
                        if (s.JsonPath == ".cameras[].type")
                        {
                            return("cameraType");
                        }
                        else if (s.JsonPath == ".accessors[].type")
                        {
                            return("accessorType");
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }

                    if (name == "alphaMode" ||
                        name == "interpolation" ||
                        name == "path")
                    {
                        return(name + "Type");
                    }
                    else
                    {
                        return(name);
                    }
                }

            case JsonSchemaType.Object:
                if (s is DictionaryJsonSchema d)
                {
                    return($"map<string, {GetProtoType(d.AdditionalProperties, true)}>");
                }
                else
                {
                    if (s.ClassName.EndsWith("__extras"))
                    {
                        return("Extras");
                    }
                    else if (s.ClassName.EndsWith("__extensions"))
                    {
                        return("Extensions");
                    }
                    else
                    {
                        return(s.Title?.Replace(" ", ""));
                    }
                }

            case JsonSchemaType.String:
                return("string");

            case JsonSchemaType.Boolean:
                if (required)
                {
                    return("bool");
                }
                else
                {
                    return("google.protobuf.BoolValue");
                }

            case JsonSchemaType.Enum:
            case JsonSchemaType.Integer:
                if (required)
                {
                    return("int32");
                }
                else
                {
                    return("google.protobuf.Int32Value");
                }

            case JsonSchemaType.Number:
                if (required)
                {
                    return("float");
                }
                else
                {
                    return("google.protobuf.FloatValue");
                }

            case JsonSchemaType.Array:
                return(GetProtoType(s as ArrayJsonSchema));

            default:
                throw new NotImplementedException();
            }
        }
예제 #3
0
 static string ToClassName(JsonSchemaBase schema, in Configuration config)