diff --git a/jsonschema/docs/docs.go b/jsonschema/docs/docs.go index a93b351..160cf73 100644 --- a/jsonschema/docs/docs.go +++ b/jsonschema/docs/docs.go @@ -17,6 +17,8 @@ func generateDoc(root jsonschema.Schema, headerLevel int) (string, error) { return toc + "\n\n" + buff.String(), err } +// GenerateFromSchema generates a markdown documentation from a jsonschema.Schema. During the writing process the `Comment` attribute can be overwritten +// To avoid this use the `Generate` function which will not modify the original schema func GenerateFromSchema(schema jsonschema.Schema, headerLevel int) (string, error) { return generateDoc(schema, headerLevel) } @@ -131,7 +133,7 @@ func writeProperty(property *jsonschema.Schema, required bool, buff *strings.Bui } func writeDescription(sc *jsonschema.Schema, buff *strings.Builder) { - if len(sc.Description) == 0 { + if len(sc.Description) == 0 || sc.Comments == "skip_description" { return } @@ -139,7 +141,7 @@ func writeDescription(sc *jsonschema.Schema, buff *strings.Builder) { buff.WriteString(strings.ReplaceAll(sc.Description, "\n", "\n ")) buff.WriteString("\n") - sc.Description = "" // already used + sc.Comments = "skip_description" } func writeValueAnnotations(sc *jsonschema.Schema, buff *strings.Builder) { diff --git a/jsonschema/docs/docs_test.go b/jsonschema/docs/docs_test.go index 17f8c46..648c136 100644 --- a/jsonschema/docs/docs_test.go +++ b/jsonschema/docs/docs_test.go @@ -58,18 +58,18 @@ func TestGCP(t *testing.T) { func TestClickHouse(t *testing.T) { genSnapshot(t, "testdata/clickhouse.json") - genSnapshot(t, "testdata/clickhouse.json") + genSnapshotStruct(t, "testdata/clickhouse.json") } func TestFiletypes(t *testing.T) { genSnapshot(t, "testdata/filetypes.json") - genSnapshot(t, "testdata/filetypes.json") + genSnapshotStruct(t, "testdata/filetypes.json") } func TestFileDestination(t *testing.T) { genSnapshot(t, "testdata/file-destination.json") - genSnapshot(t, "testdata/file-destination.json") + genSnapshotStruct(t, "testdata/file-destination.json") }