KaiZen-OpenApi-Parser icon indicating copy to clipboard operation
KaiZen-OpenApi-Parser copied to clipboard

Serialization Missing

Open danlange opened this issue 6 years ago • 2 comments

The documentation says that: Serialization to JSON or YAML is supported, and by default, round-tripping will not cause any reordering of model content. And: The serialization API applies to any Overlay adapter object but most commonly will be applied to complete models. It consists of a single method: JsonNode toJson(SerializationOptions.options... options)

There was an OpenApi3.toJson() method in build 0.0.3.201803041924 but it has been missing since build 1.0.0.201803221402.

I can't find any way to serialize in builds more recent than that.

danlange avatar Sep 27 '18 19:09 danlange

@danlange Sorry, documentation is out of date. Will try to get to review & update shortly, but time for this very tight.

The toJson and many other methods that were of a generic nature and not directly related to the model elements were removed from the generated API in 1.0. They were moved to a new adapter object that can be used on any of the model classes.

The adapter class is actually part of the JsonOverlay library on which this parser depends. So for example, you would now write things like Overlay.of(model).toJson(options).

andylowry avatar Sep 28 '18 14:09 andylowry

thanks for the info @andylowry !

I've been trying and failing to modify the Path object on the parsed model.

e.g.

OpenApi3 parsed = parser.parse(new File("foobar.yaml"));
parsed.setPaths(new HashMap<>());
System.out.println(parsed.getPaths().size()); // this prints 0
JsonNode jsonNode = Overlay.of(parsed).toJson();
String yaml = new YAMLMapper().writeValueAsString(jsonNode);
System.out.println(yaml); // this prints out the original parsed yaml with all initial paths

This problem persisted even when I attempted to set a non-empty HashMap.

Calling removePath seemed to work. Calling setPath led to a stackoverflow.

I was able to modify the openapi version, which suggest to me at least some of the in-memory operations are persisting. Any tips?

My goal here is to programmatically edit specs based on tags for easier documentation generation. e.g. has this route been implemented?

davinchia avatar Jan 01 '20 00:01 davinchia