Beispiel #1
0
        public static JsonSchema BuildJsonSchemaDynamic(this Schema schema, PartitionResolver partitionResolver,
                                                        ResolvedComponents components,
                                                        JsonTypeFactory?factory = null,
                                                        bool withHidden         = false,
                                                        bool withComponents     = false)
        {
            Guard.NotNull(partitionResolver);
            Guard.NotNull(components);

            factory ??= DefaultFactory;

            var jsonSchema = JsonTypeBuilder.Object();

            foreach (var field in schema.Fields.ForApi(withHidden))
            {
                var property =
                    JsonTypeVisitor.BuildProperty(
                        field, components, schema,
                        factory,
                        withHidden,
                        withComponents);

                // Property is null for UI fields.
                if (property != null)
                {
                    var propertyObj = JsonTypeBuilder.ObjectProperty(property);

                    // Property is not required because not all languages might be required.
                    propertyObj.SetRequired(false);
                    propertyObj.SetDescription(field);

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

            return(jsonSchema);
        }