public JsonSchema CreateContentSchema(Schema schema, JsonSchema dataSchema)
        {
            Guard.NotNull(schema, nameof(schema));
            Guard.NotNull(dataSchema, nameof(dataSchema));

            var schemaName = schema.Properties.Label.WithFallback(schema.Name);

            var contentSchema = new JsonSchema
            {
                Properties =
                {
                    ["id"]             = SchemaBuilder.GuidProperty($"The id of the {schemaName} content.",                                         true),
                    ["data"]           = SchemaBuilder.ObjectProperty(dataSchema,                                                                   $"The data of the {schemaName}.",       true),
                    ["dataDraft"]      = SchemaBuilder.ObjectProperty(dataSchema,                                                                   $"The draft data of the {schemaName}."),
                    ["version"]        = SchemaBuilder.NumberProperty($"The version of the {schemaName}.",                                          true),
                    ["created"]        = SchemaBuilder.DateTimeProperty($"The date and time when the {schemaName} content has been created.",       true),
                    ["createdBy"]      = SchemaBuilder.StringProperty($"The user that has created the {schemaName} content.",                       true),
                    ["lastModified"]   = SchemaBuilder.DateTimeProperty($"The date and time when the {schemaName} content has been modified last.", true),
                    ["lastModifiedBy"] = SchemaBuilder.StringProperty($"The user that has updated the {schemaName} content last.",                  true),
                    ["status"]         = SchemaBuilder.StringProperty($"The status of the content.",                                                true)
                },
                Type = JsonObjectType.Object
            };

            return(contentSchema);
        }
示例#2
0
        public JsonSchemaProperty?Visit(IField <GeolocationFieldProperties> field)
        {
            var geolocationSchema = SchemaBuilder.Object();

            geolocationSchema.Properties.Add("latitude", new JsonSchemaProperty
            {
                Type          = JsonObjectType.Number,
                IsNullableRaw = false,
                IsRequired    = true,
                Maximum       = 90,
                Minimum       = -90
            });

            geolocationSchema.Properties.Add("longitude", new JsonSchemaProperty
            {
                Type          = JsonObjectType.Number,
                IsNullableRaw = false,
                IsRequired    = true,
                Maximum       = 180,
                Minimum       = -180
            });

            var reference = schemaResolver("GeolocationDto", geolocationSchema);

            return(SchemaBuilder.ObjectProperty(reference));
        }
示例#3
0
        public JsonSchemaProperty?Visit(IField <GeolocationFieldProperties> field, Args args)
        {
            var reference = args.SchemaResolver("GeolocationDto", () =>
            {
                var geolocationSchema = SchemaBuilder.Object();

                geolocationSchema.Format = GeoJson.Format;

                geolocationSchema.Properties.Add("latitude", new JsonSchemaProperty
                {
                    Type    = JsonObjectType.Number,
                    Maximum = 90,
                    Minimum = -90
                }.SetRequired(true));

                geolocationSchema.Properties.Add("longitude", new JsonSchemaProperty
                {
                    Type    = JsonObjectType.Number,
                    Maximum = 180,
                    Minimum = -180
                }.SetRequired(true));

                return(geolocationSchema);
            });

            return(SchemaBuilder.ObjectProperty(reference));
        }
示例#4
0
        public static JsonSchema BuildSchema(string name, JsonSchema?dataSchema, bool extended = false)
        {
            var jsonSchema = new JsonSchema
            {
                Properties =
                {
                    ["id"]             = SchemaBuilder.StringProperty($"The id of the {name} content.",                                       true),
                    ["created"]        = SchemaBuilder.DateTimeProperty($"The date and time when the {name} content has been created.",       true),
                    ["createdBy"]      = SchemaBuilder.StringProperty($"The user that has created the {name} content.",                       true),
                    ["lastModified"]   = SchemaBuilder.DateTimeProperty($"The date and time when the {name} content has been modified last.", true),
                    ["lastModifiedBy"] = SchemaBuilder.StringProperty($"The user that has updated the {name} content last.",                  true),
                    ["newStatus"]      = SchemaBuilder.StringProperty("The new status of the content."),
                    ["status"]         = SchemaBuilder.StringProperty("The status of the content.",                                           true),
                },
                Type = JsonObjectType.Object
            };

            if (extended)
            {
                jsonSchema.Properties["newStatusColor"] = SchemaBuilder.StringProperty("The color of the new status.", false);
                jsonSchema.Properties["schema"]         = SchemaBuilder.StringProperty("The name of the schema.", true);
                jsonSchema.Properties["SchemaName"]     = SchemaBuilder.StringProperty("The display name of the schema.", true);
                jsonSchema.Properties["statusColor"]    = SchemaBuilder.StringProperty("The color of the status.", true);
            }

            if (dataSchema != null)
            {
                jsonSchema.Properties["data"]      = SchemaBuilder.ObjectProperty(dataSchema, $"The data of the {name}.", true);
                jsonSchema.Properties["dataDraft"] = SchemaBuilder.ObjectProperty(dataSchema, $"The draft data of the {name}.");
            }

            return(jsonSchema);
        }
示例#5
0
        public JsonSchemaProperty?Visit(IField <GeolocationFieldProperties> field, Args args)
        {
            var property = SchemaBuilder.ObjectProperty();

            property.Format = GeoJson.Format;

            return(property);
        }
示例#6
0
        public JsonSchemaProperty?Visit(IField <ComponentFieldProperties> field, Args args)
        {
            if (args.Level > MaxDepth)
            {
                return(null);
            }

            var property = SchemaBuilder.ObjectProperty();

            BuildComponent(property, field, field.Properties.SchemaIds, args);

            return(property);
        }
示例#7
0
        public static JsonSchemaProperty CreateProperty(IField field, JsonSchema reference)
        {
            var jsonProperty = SchemaBuilder.ObjectProperty(reference);

            if (!string.IsNullOrWhiteSpace(field.RawProperties.Hints))
            {
                jsonProperty.Description = $"{field.Name} ({field.RawProperties.Hints})";
            }
            else
            {
                jsonProperty.Description = field.Name;
            }

            jsonProperty.SetRequired(field.RawProperties.IsRequired);

            return(jsonProperty);
        }
示例#8
0
        public static JsonSchema BuildDynamicJsonSchema(this Schema schema, SchemaResolver schemaResolver, bool withHidden = false)
        {
            Guard.NotNull(schemaResolver, nameof(schemaResolver));

            var jsonSchema = SchemaBuilder.Object();

            foreach (var field in schema.Fields.ForApi(withHidden))
            {
                var propertyItem = JsonTypeVisitor.BuildProperty(field, null, withHidden);

                if (propertyItem != null)
                {
                    var property =
                        SchemaBuilder.ObjectProperty(propertyItem)
                        .SetDescription(field)
                        .SetRequired(field.RawProperties.IsRequired);

                    jsonSchema.Properties.Add(field.Name, property);
                }
            }

            return(jsonSchema);
        }