Open danlange opened 5 years ago
@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)
.
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?
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.