Closed oldbane closed 3 years ago
Yes, I agree that maybe fixing it in 518 makes sense. If you want, feel free to fix it there. But even your solution (with my suggestion to ignore everything starting with -
, not only -?
) should fix that problem.
Can you also add a test for this behaviour? You can use a simple test like https://github.com/tkrajina/typescriptify-golang-structs/blob/master/typescriptify/typescriptify_test.go#L350 as a template for a new test.
I think that the detection of a JSON-ignored field should have happened prior to this line. Thus, I think the solution to this issue means that we should edit the getJSONFieldName
to be more robust when dealing with ignored pointers fields. I will change my submission to be a fix in that method, and provide a test for it.
I agree, go for it 👍
@tkrajina I have updated the fix and added a test :relaxed:
Thanks @nobane !
My pleasure, thanks for making and working on this very useful project @tkrajina! I hope you have a good New Year.
I am having members show up in my typescript interfaces that are named
-?
which totally breaks the output and is incorrect. It turns out those were JSON-ignored pointer types on the go structs I was convering.The issue happens because when parsing the tag inside the method
getJSONFieldName
on lines 518-520 the field name is appended a question mark if it is a pointer regardless if that field was actually marked as JSON-ignored. This then causes incorrectly filtering out JSON-ignored fields in theconvertType
method.Another solution to this would be declaring a bool that sets to true if the field is ignored in the loop in
getJSONFieldName
and not appending a?
for ignored fields thus correctly preserving the"-"
name. I would be happy to submit the alternate fix where we update that loop and if-statement ingetJSONFieldName
if you'd prefer that instead.