コード例 #1
0
        private void AddHeaderAnnotation()
        {
            for (var i = 0; i < _numAnnotationColumns; i++)
            {
                var annotation = SaJsonKeyAnnotation.CreateFromProperties(ValueTypes[i], Categories[i], Descriptions[i]);

                JsonSchema?.AddAnnotation(_tags[i + NumRequiredColumns], annotation);
            }
        }
コード例 #2
0
        public void OutputKeyAnnotation_AsExpected()
        {
            var sb         = new StringBuilder();
            var jsonSchema = new SaJsonSchema(sb);

            jsonSchema.AddAnnotation("name", SaJsonKeyAnnotation.CreateFromProperties(SaJsonValueType.String, 0, null));
            jsonSchema.OutputKeyAnnotation("name");
            Assert.Equal("\"name\":{\"type\":\"string\"}", sb.ToString());
        }
コード例 #3
0
ファイル: ClinVarSchema.cs プロジェクト: wangdi2014/Nirvana
        public static SaJsonSchema Get()
        {
            var jsonSchema = SaJsonSchema.Create(new StringBuilder(), SaCommon.ClinvarTag, PrimaryValueType, JsonKeys);

            jsonSchema.SetNonSaKeys(new [] { "isAlleleSpecific" });

            foreach ((string key, var valueType) in JsonKeys.Zip(ValueTypes, (a, b) => (a, b)))
            {
                jsonSchema.AddAnnotation(key, SaJsonKeyAnnotation.CreateFromProperties(valueType, 0, null));
            }

            return(jsonSchema);
        }
コード例 #4
0
        public void GetJsonString_DoubleValueHandling_AsExpected()
        {
            var jsonSchema = SaJsonSchema.Create(new StringBuilder(), "test", SaJsonValueType.ObjectArray, new List <string> {
                "allAf", "doubleValue1", "doubleValue2"
            });

            jsonSchema.AddAnnotation("allAf", SaJsonKeyAnnotation.CreateFromProperties(SaJsonValueType.Number, CustomAnnotationCategories.AlleleFrequency, null));
            jsonSchema.AddAnnotation("doubleValue1", SaJsonKeyAnnotation.CreateFromProperties(SaJsonValueType.Number, 0, "A double value"));
            jsonSchema.AddAnnotation("doubleValue2", SaJsonKeyAnnotation.CreateFromProperties(SaJsonValueType.Number, 0, "Another double value"));
            var jsonString = jsonSchema.GetJsonString(new List <string[]> {
                new[] { "0.12345678" }, new[] { "0.12" }, new[] { "0.12345678" }
            });

            Assert.Equal("\"allAf\":0.123457,\"doubleValue1\":0.12,\"doubleValue2\":0.12345678", jsonString);
        }
コード例 #5
0
        public void GetJsonString_AsExpected()
        {
            var jsonSchema = SaJsonSchema.Create(new StringBuilder(), "test", SaJsonValueType.ObjectArray, new List <string> {
                "name", "phone", "employed"
            });

            jsonSchema.AddAnnotation("name", SaJsonKeyAnnotation.CreateFromProperties(SaJsonValueType.String, 0, null));
            jsonSchema.AddAnnotation("phone", SaJsonKeyAnnotation.CreateFromProperties(SaJsonValueType.Number, 0, "phone number"));
            jsonSchema.AddAnnotation("employed", SaJsonKeyAnnotation.CreateFromProperties(SaJsonValueType.Bool, 0, null));
            var jsonString = jsonSchema.GetJsonString(new List <string[]> {
                new[] { "Ada" }, new[] { "123456" }, new[] { "true" }
            });

            Assert.Equal("\"name\":\"Ada\",\"phone\":123456,\"employed\":true", jsonString);
        }
コード例 #6
0
        public void ToString_AsExpected()
        {
            var jsonSchema = SaJsonSchema.Create(new StringBuilder(), "test", SaJsonValueType.ObjectArray, new List <string> {
                "name", "phone", "employed"
            });

            jsonSchema.AddAnnotation("name", SaJsonKeyAnnotation.CreateFromProperties(SaJsonValueType.String, 0, null));
            jsonSchema.AddAnnotation("phone", SaJsonKeyAnnotation.CreateFromProperties(SaJsonValueType.Number, 0, "phone number"));
            jsonSchema.AddAnnotation("employed", SaJsonKeyAnnotation.CreateFromProperties(SaJsonValueType.Bool, 0, null));
            jsonSchema.TotalItems            = 100;
            jsonSchema.KeyCounts["name"]     = 100;
            jsonSchema.KeyCounts["phone"]    = 50;
            jsonSchema.KeyCounts["employed"] = 0;

            const string expectedJsonSchemaString = "{\"$schema\":\"" + SchemaVersion + "\",\"type\":\"object\",\"properties\":{\"test\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{"
                                                    + "\"name\":{\"type\":\"string\"},\"phone\":{\"type\":\"number\",\"description\":\"phone number\"}},"
                                                    + "\"required\":[\"name\"],\"additionalProperties\":false}}}}";

            Assert.Equal(expectedJsonSchemaString, jsonSchema.ToString());
            // make sure the returned string is the same when ToString method is called more than once
            Assert.Equal(expectedJsonSchemaString, jsonSchema.ToString());
        }