datamodel-code-generator
datamodel-code-generator copied to clipboard
Extend parsing of Scientific Notation to JSON capabilites
Solves Issues https://github.com/koxudaxi/datamodel-code-generator/issues/1955#issue-2290971596 and https://github.com/koxudaxi/datamodel-code-generator/issues/1952#issue-2287818185
It boils down to yaml vs. json floating point parsing. The SafeLoader of yaml has to be extended to allow for the same range of float notations like json. See here for more background. I copied the SO-solution and it does work (for me)
This is needed to postprocess Fortran output as it often as a e (e.g. 1e-5)for scientific notation, which yaml does not accept, but json does accept.
And because the json schema input is parsed through a yaml loader, this notation is not accepted. This PR extends the yaml loader to accept json notation of scientific data representation.
@gaborbernat I rebased and added the CLI option --extend-yaml-scientifc-notation.
The current implementation uses a global variable, but this is the best solution I could come up with. Ideally the command line option is gone in the '1.0' release and with it this 'construct' so I think it is ok for now.
I added one test.
The pre-commit.ci bot does quite a lot of code changes I don't know how to prevent. This should probably be changed.
Is there anything I can do to aid the progress here? I need this to parse json schema which contains Fortran style scientific notation ( e.g. 1e-5) which is butchered by the yaml loader.
Yes, because the pre-commit bot breaks the code.
Yes, because the pre-commit bot breaks the code.
You'll need to address that 🤔 by overriding the ruff checks causing the issue.
Seems this stalled, I'll close it for now, but can reopen if you get back to it; there's now some merge conflicts that would also need fixed.