Skip to content
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

Serialization Missing #227

Open
danlange opened this issue Sep 27, 2018 · 2 comments
Open

Serialization Missing #227

danlange opened this issue Sep 27, 2018 · 2 comments

Comments

@danlange
Copy link

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.

@andylowry
Copy link
Contributor

@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).

@davinchia
Copy link

davinchia commented Jan 1, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants