Comments (6)
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.
from createapi.
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
from createapi.
The primary objective of this revision is to bring YAML into compliance with JSON as an official subset.
— YAML 1.2 Specification (2009)
It should be perfectly valid to use YAMLDecoder
for json
documents.
This of course hinges on how closely Yams follows the spec.
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.
from createapi.
If retaining order is important for your use-case, I recommend the Yams and FineJSON libraries for YAML and JSON respectively. Also keep in mind that JSON is entirely valid YAML and therefore you will likely get good results from Yams decoding of JSON as well (it just won't encode as valid JSON).
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 Yams
and adds tests?
It wouldn't be necessary to check in any JSON specs, as decoding a YAML spec with Yams
and consequently encoding it with JSONEncoder
does retain order.
from createapi.
should currently be considered broke
As in the ordering, or are there more issues?
Would you be interested in a PR that switches the JSON parser over to Yams and adds tests?
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.
from createapi.
Fixed in 0.0.4! Thanks 🚀
from createapi.
Related Issues (20)
- Schema component named `Request` generates ambiguous code HOT 4
- `AnyJSON` type included unexpectedly
- Adjust behaviour of `includeDefaultValues` to favour "correctness" by default HOT 1
- integer backed enums are stored as integer properties as opposed to enums HOT 1
- generated package depends on an old version of Get HOT 3
- Tagged type for IDs? HOT 2
- FR: Entity replace substring, instead of naming template HOT 1
- Equatable conformance HOT 1
- Parameters to be passed in headers are ignored during API generation
- Acronyms change property names without changing corresponding CodingKeys
- Deduplicate identical structs/classes
- Add option to separate GET from POST and PATCH requests and only include Decodable respectively Encodable conformance
- Option for treating non-optional enum with only one case as a static value
- `type` definition in OpenAPI spec is overridden by `format` value
- Is there a way to generate `CodingKeys`?
- How to wildcard rules in include and exclude paths
- Use `Swift Syntax`
- Make 'Request' type name configurable HOT 1
- Will OpenAPI schema v3.1.0 be supported?
- Documentation on how to use decoded entity fields HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from createapi.