-
Notifications
You must be signed in to change notification settings - Fork 30
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
Manipulation of the OpenAPI instance: complex object? #194
Comments
@jmini Thanks for the question, and sorry the documentation isn't nearly where it ought to be! You should use The constructors are all private, because when the passed JSON is a reference node, and we've already parsed that JSON, we need to return a shared reference to the existing object, rather than creating a new one. The factories take care of that. There's an intention (see #12) to generate fluent builders for all the model types, but that's currently not implemented. Please close this issue if this response works for you. |
This make sense. Note that the constructors are public: Lines 20 to 28 in 6a78b07
I can ignore those, not a problem. I had a look at the mentioned factory, I do not get how the public JsonOverlay<V> create(V value, JsonOverlay<?> parent, ReferenceManager refMgr)
public JsonOverlay<V> create(JsonNode json, JsonOverlay<?> parent, ReferenceManager refMgr) a/ what are the parameters? You mention null, but I need a b/ this do not create a |
@jmini Ah, sorry, I had forgotten some of the factory evolution, and thanks for pointing out the constructors are indeed public. Unfortunately, I can see that things are a bit screwed up at the moment. In truth, I've got tests for the write methods in general, but actually "creating" a new instance via the factory for incorporation in an existing structure does not appear to be covered, and it doesn't currently appear to be possible, at least not in a completely kosher fashion. However, that whole ReferenceManager thing is really for ensuring that references are handled consistently throughout a structure - e.g. references to the same JSON value end up being represented by shared objects in the model. I'm guessing that's not very important to your use case, at least as regards new objects you're adding after the initial parse. If that's the case, then you should be OK with something like this:
where I have to run in one minute, else I'd test this before shooting off this response, but I'll check into it later. And I'll definitely circle back and make improve on this in the code. |
Ok, so my guess above does not work. Sorry if you wasted any time on it. The following does work, but it's pretty clumsy.
I'll try to get something reasonable in the next week or so. It won't be a true builder, but it probably will take the form of a builder to be aligned with future intention. So expect something like:
and maybe a convenience method:
The latter would just do the former. And the former would later be extended with typical fluent builder methods so you could do things like:
The |
Do not worry, I am in an evaluation phase, so I am glad to hear that this feature will be improved.
This is very important. Consider a case like this: openapi: 3.0.1
info:
title: Test reference
description: API under test
version: 1.0.7
paths:
/foo/bar:
get:
responses:
200:
description: it works!
content:
application/json:
schema:
title: inline_response_200
type: object
properties:
name:
type: string
components:
schemas:
Simple:
properties:
property:
type: integer
format: int64 I would like to do: model.getPaths().get("/foo/bar").getGet().getResponse("200").getContentMediaType("application/json").setSchema(model.getSchema("Simple")); And I expect the yaml to be edited with a And of course it should also work if I do it for a new object (a new response or a new content-type). |
@jmini Yes, you're right... setting a value that's already present elsewhere in the model should result in a reference. I'm not sure I'll be able to manage that quickly, though. It gets tricky in a multi-file scenario Single file would probably be simpler, and if that's your use case I could try to do that first. |
@jmini Just a heads-up that a new major revision of the parser, v4.0.0, is now available on maven central. In this version, you will find:
Bottom line is you should now be able to write Not appearing with these changes are:
|
Given the an
OpenApi3
instance calledmodel
parsing result of this small spec:I can manipulate the OpenAPI by doing:
This is great to change a value.
But what if I want to add a server to the server list? There is this method:
It expects a
server
instance. Should I donew ServerImpl(...)
what are the requested parameter?Is there a factory somewhere to create the
server
instance that I need?Thank you in advance.
The text was updated successfully, but these errors were encountered: