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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        private void BuildComponent(JsonSchema jsonSchema, IField field, ImmutableList <DomainId>?schemaIds, Args args)
        {
            jsonSchema.Properties.Add(Component.Discriminator, SchemaBuilder.StringProperty(isRequired: true));

            if (args.SchemaResolver != null)
            {
                var schemas = schemaIds?.Select(x => field.GetResolvedSchema(x)).NotNull() ?? Enumerable.Empty <Schema>();

                var discriminator = new OpenApiDiscriminator
                {
                    PropertyName = Component.Discriminator
                };

                foreach (var schema in schemas)
                {
                    var schemaName = $"{schema.TypeName()}ComponentDto";

                    var componentSchema = args.SchemaResolver(schemaName, () =>
                    {
                        var nestedArgs = args.Increment();

                        var componentSchema = SchemaBuilder.Object();

                        foreach (var sharedField in schema.Fields.ForApi(nestedArgs.WithHiddenFields))
                        {
                            var sharedProperty = sharedField.Accept(this, nestedArgs);

                            if (sharedProperty != null)
                            {
                                sharedProperty.Description = sharedField.RawProperties.Hints;
                                sharedProperty.SetRequired(sharedField.RawProperties.IsRequired);

                                componentSchema.Properties.Add(sharedField.Name, sharedProperty);
                            }
                        }

                        componentSchema.Properties.Add(Component.Discriminator, SchemaBuilder.StringProperty(isRequired: true));

                        return(componentSchema);
                    });

                    jsonSchema.OneOf.Add(componentSchema);

                    discriminator.Mapping[schemaName] = componentSchema;
                }

                jsonSchema.DiscriminatorObject = discriminator;
            }
            else
            {
                jsonSchema.AllowAdditionalProperties = true;
            }
        }
Esempio n. 4
0
        public JsonSchemaProperty?Visit(IField <StringFieldProperties> field)
        {
            var property = SchemaBuilder.StringProperty();

            property.MaxLength = field.Properties.MaxLength;
            property.MinLength = field.Properties.MinLength;
            property.Pattern   = field.Properties.Pattern;

            if (field.Properties.AllowedValues != null)
            {
                var names = property.EnumerationNames ??= new Collection <string>();

                foreach (var value in field.Properties.AllowedValues)
                {
                    names.Add(value);
                }
            }

            return(property);
        }