Decode JSON input specs using YAMLDecoder#34
Merged
liamnichols merged 6 commits intoCreateAPI:mainCreateAPI/CreateAPI:mainfrom Jun 10, 2022
liamnichols:ln/json-preserving-property-orderliamnichols/CreateAPI:ln/json-preserving-property-orderCopy head branch name to clipboard
Merged
Decode JSON input specs using YAMLDecoder#34liamnichols merged 6 commits intoCreateAPI:mainCreateAPI/CreateAPI:mainfrom liamnichols:ln/json-preserving-property-orderliamnichols/CreateAPI:ln/json-preserving-property-orderCopy head branch name to clipboard
YAMLDecoder#34liamnichols merged 6 commits intoCreateAPI:mainCreateAPI/CreateAPI:mainfrom
liamnichols:ln/json-preserving-property-orderliamnichols/CreateAPI:ln/json-preserving-property-orderCopy head branch name to clipboard
Conversation
Member
Author
|
There were about 10 packages missing from Tests/GeneratedPackages.xcodeproj so I just deleted everything and dragged all 38 of them back in 899107f |
…for file extension instead of assuming yaml
…JSON file formats
899107f to
ee0d7d3
Compare
ee0d7d3 to
463592d
Compare
imjn
approved these changes
Jun 10, 2022
Member
imjn
left a comment
There was a problem hiding this comment.
I think this is ready to be merged 👍🏽
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Background
.jsonfile #12When loading OpenAPI schemas that are encoded in JSON format,
Generatewill useJSONDecoderto load it as anOpenAPI.Document. This is inconvenient compared to yaml files for two reasons:YAMLDecoderis thread safe, meaning we can useParallelDocumentParserto decode quickerJSONDecoderdoes not preserve the ordering of dictionaries that it deserialises resulting in unstable generated output unless you enableisSortingPropertiesAlphabeticallySince most common JSON is also valid YAML, we could save some code and also solve the two problems above by using
YAMLDecoderwhen decoding json files as well.How
In this PR, I pretty much do just that. In the changes to Generate.swift, I tweak
parseInputSpec()so that we check the file format before loading the data and then I remove the call toJSONDecoderso thatYAMLDecoderis used regardless of file format.To support this change, I have also updated some of the test helper methods to require an
extparameter when loading/testing specs since I've also added cookpad.json, which is a really simple Open API schema we use for a small static API that makes up part of our hiring process.While the schema I committed to the specs is quite small, I can also confirm that we've already been using this approach on a much larger schema for a few months now without issues. In addition, I also converted github.yaml to JSON and re-ran the tests to see if there are any changes - there weren't. If you'd like me to commit convert one of the bigger existing schemas to json as well, do let me know.
One thing to note however is this:
YAMLDecoder's handling when decoding empty strings into optional types jpsim/Yams#351With the current versions of Yams, there is one bug that might come up if your schema has empty strings anywhere - they might be mistakenly considered asnilin some cases. This is actually why I didn't updatereadOptions()to useYAMLDecoderfor json configs, since one in the specs falls victim of the bug.Hopefully that patch will be merged relatively soon though and this won't be too much of a problem. Happy to put this PR on hold though if you'd prefer to wait for the Yams patch to land upstream first.I merged this patch to our fork anyway.