Top Level Information copied down a level
jdhaines opened this issue · comments
Hi, great library! I'm having a strange issue and I can't sort out where to fix it in the code. If you give me a hint I could potentially submit a PR.
With small input files:
demo.yaml
#' ChangeDetailscomments
ChangeDetails:
#' commit comments
commit: 19393
#' commitDate comments
commitDate: 2023-06-02
#' version comments
version: 3.3.2
#' repositoryLink comments
repositoryLink: github
demo.schema
$schema: "https://json-schema.org/draft-04/schema#"
ChangeDetails:
type: object
# or
# type: object
# properties:
# ChangeDetails:
properties:
commit:
type: string
commitDate:
type: string
version:
type: string
repositoryLink:
type: string
environmentBeforeChange:
type: string
environmentAfterChange:
type: string
creates the markdown:
Configuration Parameters Reference
Any information about this page goes here.
## `ChangeDetails`
ChangeDetailscomments
### Member variables:
| Key | Value | Type | Information |
| :-: | :-: | :-: | :-- |
| `commit` | `19393` | string | ChangeDetailscomments commit comments |
| `commitDate` | `2023-06-02` | string | commitDate comments |
| `version` | `3.3.2` | string | version comments |
| `repositoryLink` | `github` | string | repositoryLink comments |
Problem: The information for the top key (ChangeDetailscomments) is also put at the beginning of the information for the lower level key commit. I'm not sure why, and printing various outputs from the python code didn't seem to give me a clue.
I'm seeing the same issue in your two level text example. Thanks again for the cool library!
I'm still not sure about how to fix the issue, but I took an hour or so to put together a test case showing the failure. If you add the following line to the top of /test/test_examples.py
import sys, io
Then add the following class to the test examples:
class TestMarkdown(unittest.TestCase):
def test_basic(self):
old_stdout = sys.stdout
new_stdout = io.StringIO()
sys.stdout = new_stdout
markdown_result = yamldoc.main(yaml_path = "test/yaml/basic.yaml", schema_path = "test/schema/basic.schema")
output = new_stdout.getvalue()
sys.stdout = old_stdout
proper_markdown = """# Configuration Parameters Reference\n\nAny information about this page goes here.\n\n| Key | Value | Type | Information |\n| :-: | :-: | :-: | :-- |\n| `meta` | `"Data"` | string | Here is some meta data. |\n| `fun` | `True` | bool | And here is some more split over a couple of<br />lines. |\n\n\n\n---\nGenerated by [yamldoc](https://github.com/chris1221/yaml.doc) v0.1.6 on 2023-06-06\n"""
self.assertTrue(output == proper_markdown)
def test_two_level(self):
old_stdout = sys.stdout
new_stdout = io.StringIO()
sys.stdout = new_stdout
markdown_result = yamldoc.main(yaml_path = "test/yaml/two_level.yaml", schema_path = "test/schema/two_level.schema")
output = new_stdout.getvalue()
sys.stdout = old_stdout
proper_markdown = """# Configuration Parameters Reference\n\nAny information about this page goes here.\n\n| Key | Value | Type | Information |\n| :-: | :-: | :-: | :-- |\n| `flat` | `"yes"` | string | This is a flat entry. |\n\n\n\n## `two`\n\n But this is a two level thing.\n\n### Member variables:\n\n| Key | Value | Type | Information |\n| :-: | :-: | :-: | :-- |\n| `entry` | `"hi"` | [\'string\', \'number\'] | These can have<br />documentation too. |\n\n\n\n---\nGenerated by [yamldoc](https://github.com/chris1221/yaml.doc) v0.1.6 on 2023-06-06\n"""
print("\n\nActual Output:\n\n", output)
print("\n\nExpected Output:\n\n", proper_markdown)
self.assertTrue(output == proper_markdown)
I have the basic test passing with the expected Markdown. The two-level has the strange piece of information and the print statements in the test show it the current way and the expected way. If it's valuable, I can submit a PR at least for the test updates... the fix still isn't clear to me yet. Hope this is helpful!
Thanks very much for using the package, Josh! Some parts of the code are (very) janky, I appreciate you taking a look and investigating the issue. I don't immediately know what is causing this issue but having the test case will be incredibly valuable, if it's not too much trouble would you mind submitting that as a PR against the devel
branch? I'm in a bit of a busy period with work right now but should have some time to look at it this weekend and hopefully figure out what is going on. I've been meaning to back and clean up the code anyway, thank you again for the report!
... if it's not too much trouble would you mind submitting that as a PR against the
devel
branch...
Done!
Hey @jdhaines, I think I figured it out. Would you mind seeing if the proposed solution in #9 works for you? I tried it on your simple case above and it looks correct to me, but I'm sure your actual file is larger so wanted to circle back and see if there are any other lingering bugs to fix
yamldoc demo.yaml -s demo.schema
gives the expected Markdown without ChangeDetailscomments
in the commit
entry:
ChangeDetails
ChangeDetailscomments
Member variables:
Key | Value | Type | Information |
---|---|---|---|
commit |
19393 |
string | commit comments |
commitDate |
2023-06-02 |
string | commitDate comments |
version |
3.3.2 |
string | version comments |
repositoryLink |
github |
string | repositoryLink comments |
Generated by yamldoc v0.1.6 on 2023-06-10
Hey, @Chris1221 this looks good to me. Thanks for pushing the fix so quickly! It seems obvious now that I see what you updated.
Great! Happy to be of assistance and very much appreciate you finding the bug