Fix header hierarchy for properties in allOf/anyOf composition schemas #679
+190
−18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Properties defined within
allOf/anyOf/oneOfcomposition constructs were rendered with incorrect header levels, breaking document hierarchy when schemas contain nested composition patterns.Problem
For a schema like:
{ "properties": { "docker": { "allOf": [ { "anyOf": [ { "properties": { "testSteps": {...} } } ] }, { "properties": { "preTestSteps": {...} } } ] } } }Property detail sections for
testStepsandpreTestStepsused base level 1, resulting in:# Properties(level 1)## propertyName(level 2)But since these are nested within
docker(which itself is at level 3), they should use higher levels to maintain hierarchy.Changes
Header level calculation (
lib/markdownBuilder.js)/allOf/,/anyOf/, or/oneOf/in JSON pointer path/properties/segmentsResult: Composition schema properties now render as:
## Properties(level 2)### propertyName(level 3)#### Type(level 4)This preserves hierarchy when documentation is assembled or viewed in context.
Testing
Added test fixture with nested
allOf/anyOfstructure and 3 test cases validating correct header levels for composition schemas vs regular properties.Original prompt
This section details on the original issue you should resolve
<issue_title>Incorrect header hierarchy for nested properties in allOf with anyOf</issue_title>
<issue_description>
Description
When using
allOfwith multiple schemas where one contains ananyOf, the generated markdown documentation has incorrect header hierarchy for the property detail sections. Specifically, properties that are defined in separateallOfitems appear with headers at the wrong level.Expected Behavior
For a schema structure like:
All detail sections under
tests.dockershould be at level 4 (####) since they're nested under a level 3 header (###).Actual Behavior
The generated markdown has inconsistent header levels:
The detail sections for
testStepsandpreTestStepsare promoted to level 2 and 3 respectively, breaking the document hierarchy.Minimal Reproduction
See also:
jsonschema2md-hirachie-test.zip
Input Schema (
schema.json):{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Example Schema", "type": "object", "properties": { "tests": { "title": "Tests Configuration", "description": "Configure test execution", "type": "object", "properties": { "docker": { "title": "Docker Tests", "description": "Run Docker-based tests", "type": "object", "allOf": [ { "title": "test-options", "description": "Test execution options", "anyOf": [ { "title": "script", "properties": { "testScript": { "title": "Test Script", "description": "Script to execute for testing", "type": "string" } }, "required": ["testScript"] }, { "title": "stepList", "properties": { "testSteps": { "title": "Test Steps", "description": "List of test steps to execute", "type": "array", "items": { "type": "object" } } }, "required": ["testSteps"] } ] }, { "properties": { "preTestSteps": { "title": "Pre-test Steps", "description": "Steps to execute before running tests", "type": "array", "items": { "type": "object" } } } } ] } } } } }Code to generate markdown:
Problematic output (lines 90 and 107):
Environment
Workaround
As a temporary workaround, we:
allOfitems to put simpler properties before complex ones (withanyOf/oneOf)Impact
This breaks the logical document structure and makes navigation difficult, especially in documentation systems that rely on proper heading hierarchy for table of contents generation. Thi sis a simplified example and in complex documents it gets unreadable.
</issue_description>
<agent_instructions>reproduce the issue in a test first, then fix the issu...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.