From 6358e812ce14b87da1fa193955648b9baa0b4da0 Mon Sep 17 00:00:00 2001 From: bbernays Date: Wed, 2 Apr 2025 09:03:08 -0500 Subject: [PATCH 1/4] Update docs.go --- jsonschema/docs/docs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jsonschema/docs/docs.go b/jsonschema/docs/docs.go index a93b351..296db89 100644 --- a/jsonschema/docs/docs.go +++ b/jsonschema/docs/docs.go @@ -131,7 +131,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 +139,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) { From 3dac880ed6849f2c56b28c3bf3c88fef91484dbd Mon Sep 17 00:00:00 2001 From: bbernays Date: Wed, 2 Apr 2025 09:03:10 -0500 Subject: [PATCH 2/4] Update docs_test.go --- jsonschema/docs/docs_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/jsonschema/docs/docs_test.go b/jsonschema/docs/docs_test.go index 17f8c46..9115455 100644 --- a/jsonschema/docs/docs_test.go +++ b/jsonschema/docs/docs_test.go @@ -28,6 +28,8 @@ func genSnapshot(t *testing.T, fileName string) { doc, err := Generate(data, 1) require.NoError(t, err) + // print(normalizeContent(doc)) + cupaloy.New(cupaloy.SnapshotFileExtension(".md")).SnapshotT(t, normalizeContent(doc)) } @@ -58,18 +60,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") } From 0e33b3e821b986f4eccc98f4cc4b59cbe6572d56 Mon Sep 17 00:00:00 2001 From: bbernays Date: Wed, 2 Apr 2025 09:08:12 -0500 Subject: [PATCH 3/4] Update docs.go --- jsonschema/docs/docs.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jsonschema/docs/docs.go b/jsonschema/docs/docs.go index 296db89..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) } From e6632acacf1b26eb17784cb98cc509f0381ea441 Mon Sep 17 00:00:00 2001 From: bbernays Date: Wed, 2 Apr 2025 09:17:56 -0500 Subject: [PATCH 4/4] Update docs_test.go --- jsonschema/docs/docs_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/jsonschema/docs/docs_test.go b/jsonschema/docs/docs_test.go index 9115455..648c136 100644 --- a/jsonschema/docs/docs_test.go +++ b/jsonschema/docs/docs_test.go @@ -28,8 +28,6 @@ func genSnapshot(t *testing.T, fileName string) { doc, err := Generate(data, 1) require.NoError(t, err) - // print(normalizeContent(doc)) - cupaloy.New(cupaloy.SnapshotFileExtension(".md")).SnapshotT(t, normalizeContent(doc)) }