-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unstable order when reading spec from .json
file
#12
Comments
Unfortunately, that seems to be the case. It's recommended to use YAML. OpenAPIKit uses ordered dictionaries to preserve the order of the keys when it can (YAML). To convert, you can use Swagger Editor. See File / Convert and save as JSON. There is also a CreateAPI option to sort properties alphabetically which is disabled by default: entities:
isSortingPropertiesAlphabetically: true |
It should be perfectly valid to use I didn't run into any issues with the OpenAPI specs I tried (two small internal ones), but that feels like too small of a sample size to conclusively rule out any nasty edge cases. |
Not sure if "you will likely get good results" is good enough, but I'd argue that entity generation with JSON as input should currently be considered broken, as its behavior is unexpected for anyone unfamiliar with the JSON specification. Would you be interested in a PR that switches the JSON parser over to |
As in the ordering, or are there more issues?
Yeah, absolutely. Let's give it a try. If it resolved the ordering issue, that would be fantastic. I have a private repo with 1KK lines of specs, but they are all YAML. I'll give you access in case you need it. It's not perfectly structured. It was initially part of this project, so I just copied it and symlinked the sources for now. But I think adding a JSON+YAML test to this repo should be enough. |
I had a go at doing this, but I found a bug in Yams that is a slight blocker (it caused one of the specs that decodes a json configuration to fail): Other than the empty string/optional issue though, Yams has been pretty good at handling our 31,500 line OpenAPI schema in JSON format, we've just been renaming it to .yml (so that CreateAPI uses Yams and preserves the ordering) but not converting it from JSON. |
Fixed in 0.0.4! Thanks 🚀 |
https://github.com/kean/CreateAPI/blob/87ba65d28a657ef7b94a758697cbf68d6075dbb9/Sources/CreateAPI/Generate.swift#L159-L160
In addition to not being thread-safe,
JSONDecoder
also does not appear to guarantee any explicit order of object keys.Spec
Output
The easiest workaround is to convert the
.json
spec to a.yaml
spec beforehand.The text was updated successfully, but these errors were encountered: