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

Now we can find controllers in other jar files / merging openapi.json #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Tijs-2
Copy link
Contributor

@Tijs-2 Tijs-2 commented Mar 2, 2021

I have tried something, it was a lot of work and I am not sure if it is a good thing but it works.
I now can locate controllers in other jar files and add them to the openapi.json file

So it could be a solution for #51

But as I said it kind of is a large change on top of your code. It seems to work and I have compared the openapi.json that is created on a few types of parameters / returns types. With and without lists etc.

One thing that is also important to mention you need to add the following to your pom file to keep the parameter names so they can be used for generating the openapi.json file.

    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-compiler-plugin</artifactId>
       <configuration>
            <compilerArgument>-parameters</compilerArgument>
            <source>${maven.compiler.source}</source>
            <target>${maven.compiler.target}</target>
            <parameters>true</parameters>
        </configuration>
    </plugin>

Please let me know if it could be something useful or not...
Tijs

@rbygrave
Copy link
Contributor

rbygrave commented Jul 7, 2021

I think we should be able to "merge" the openapi.json files. Something like load each of the openapi.json files as resources and then merge the models.

@rbygrave
Copy link
Contributor

rbygrave commented Jul 7, 2021

Apologies this has taken me so long to back on this.

@Tijs-2
Copy link
Contributor Author

Tijs-2 commented Jul 23, 2021

No problem, I have also been a bit busy lately. I did look at merging the json files again and found something interesting:
https://github.com/kpramesh2212/openapi-merger-plugin

I did not try it but seems like a nice tool if it works.

Other thing I found was this:
https://stackoverflow.com/questions/39945039/java-merge-json-files

The first one seems the best choice to look at because it is made for openapi files.

rbygrave added a commit that referenced this pull request Jan 16, 2023
@Mechite
Copy link
Contributor

Mechite commented Jan 22, 2023

Library for this (but it is written in Kotlin) https://github.com/savvasdalkitsis/json-merge
It is a single file, so it will literally be super trivial to convert to Java, I could probably send a gist here for a Java port of it (using Jackson so it can be used as a good reference).

@Mechite
Copy link
Contributor

Mechite commented Apr 4, 2023

https://github.com/flipkart-incubator/zjsonpatch should be used in this case. We can merge until we have one large document, but we should ensure the current projects' openapi.json is the last document to be "appended" so that we end up with its other fields being the ones that take effect.

Trivial example:

    JsonNode merge(JsonNode mainNode, JsonNode updateNode) throws Exception {
        // generate a patch between the main and update JSON objects
        JsonNode patchNode = JsonDiff.asJson(mainNode, updateNode);
        
        // apply the patch to the main JSON object to create a new merged object
        JsonNode mergedNode = JsonPatch.fromJson(patchNode).apply(mainNode);
        
        return mergedNode;
    }

@rbygrave rbygrave changed the title Now we can find controllers in other jar files Now we can find controllers in other jar files / merging openapi.json Oct 10, 2024
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

Successfully merging this pull request may close these issues.

3 participants