-
Notifications
You must be signed in to change notification settings - Fork 31
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
Implement serialization #4
Comments
See also #42 which I've marked as duplicating this issue. |
Also IMHO Serialization of models should deref all models: for example. if i want json schema for a request body, the serialization should give me the complete schema, with deferenced $ref |
Thanks, there are definitely use-cases for that, but I think it should be an option. It's similar to something we did with the "Normalizer" that we implemented for Swagger 2.0 in our RepreZen API Studio product. See our article (look for "inlining" options) for details. I'll probably do #4 in a vanilla fashion first, and then think about inlining options. |
+1 for that as an option |
@slinkydeveloper Thanks for your offer of help with serialization. Here are a few thoughts that I would be going in with if I were starting to work on this:
As for the overall API, it probably makes sense to do something like this, as methods of
Let me know your thoughts, and any questions you have. I'll try to be responsive, but the same urgent work that's pulled me away from this project for a while will continue to limit my bandwidth, unfortunately. So fork away and have fun with it! |
@slinkydeveloper One other point - if you don't pay any attention to references, you should get the serialization output you prefer, rather than what I'd actually prefer as the default. But you'll fail with stack overflow on recursive structures. Might be OK as a first step, and there are some outstanding issues with references may also cause some problems along the way. Let me know if/when you want to address this aspect. |
For more informations check out GettingStarted.md diff of this commit
After a little bit of investigation, I wrote a draft of the mechanism to deference (as you said, i found that actually the method to convert to JsonNode already exists, it only needs to be declared inside interfaces to avoid the cast). Check out my commit: slinkydeveloper@a17144b , this snippet https://github.com/slinkydeveloper/KaiZen-OpenApi-Parser/blob/master/GettingStarted.md#get-jsonnode-of-a-complete-deferenced-jsonnode and run this test: https://github.com/slinkydeveloper/KaiZen-OpenApi-Parser/blob/master/kaizen-openapi-parser/src/test/java/com/reprezen/swaggerparser/test/DerefTest.java |
Refactored all my derefence mechanism, now it's a lot more simpler and doesn't affect the parsing routine. I reverted back changes i've done in Reference class. I removed the magic on/off switch (you can watch the DerefTest) and the deference mechanism doesn't affect parsing routine. Now the function
Also it seems that if you use set methods of interfaces inside model3 package, it change the internal json value so when you call |
The `toJson()` on `JsonOverlay` now checks whether its initial json is still current, and if so just uses that. Thus for the vast majority of applications that are read-only, serialization will be extremely fast. However, the mutation API methods now all notice when an overlay object's value has changed, and they mark their JSON value as no longer current. Then `toJson()` calls `createJson()`, whose job it is to create a new JSON structure representing the current overlay value. This is implemented for all but `ObjectOverlay`, for which preserving ordering of child structures is difficult and needs work.
These will support creating JSON from an ObjectOverlay, and will also replace the reflection-based field accessor mechanism.
This replaces the reflection-based accessors formerly implemented by `ObjectOverlay`. Path-based value retrieval is now implemented across all JsonOverlay classes, in the form of the `find(JsonPointer)` method. This is far more powerful than the prior feature, and without the cost of reflection. ObjectOverlay extension classes must now, at construction time, provide information required by the `ObjectOverlay` implementation of this feature. The `ObjectOverlay` constructors call out to abstract method `installPropertyAccessors` to trigger this.
Required fixing some issues with PropertyAccessors, and chaging Link.href to Link.operationRef in the test yaml
Running codegen from scratch yielded a SchemaImpl java source that was missing a required import of JsonPointer. Now that's fixed.
The `createJson` method now works for all overlay types and creates correct JSON for each. However, it blindly follows references and so does not yield the same result as a `toJson` method when the in the presence of references, and when the parsed model has not been modified. Following references should be an option, and without it, `createJson` and `toJson` should yield equivalent trees.
Also modified JsonLoader to use the trimmed model text only to guess whether it's JSON or YAML, but then actually parse the untrimmed text. Using the trimmed text had unintended potential effect of dropping a line terminator in a final block-literal string in a YAML file.
This shouldn't have changed anything, but a reformatted version of SecurityRequirementImpl had been mistakenly checked in. This is now as produced by code generator, to avoid future confusion.
Boolean option enables link following in both toJson and createJson methods. Locally available JSON object in a JsonOverlay object should be one that includes references, so toJson only updates locally stored JSON if followRefs is false.
Also changed getJson method to protected, as it shouldn't be part of the public API
Initial implementation in #82 |
Should be mostly straightforward, but will need to implement a means of keeping track of ordering of member initialization in ObjectOverlay types. The corresponding JSON structures should appear in the same order by default in serialized output.
The text was updated successfully, but these errors were encountered: