Openapi documentation generation

Hello
I have the task to generate openapi documentation/schema from an existing class. I have found a tool for it, GitHub - victools/jsonschema-gradle-example: Minimal example show-casing how the Java JSON Schema Generator can be used within a gradle build.

The problem I am facing is that the class that I want to generate for is built from the same gradle build. Project dependencies is not allowed for buildscript. This was my initial attempt.

I have some ideas on how to proceed.

  • Create a new build that can depend on output from the first
  • Do the generation from a test case. (I don’t like the idea)

I really would like to see if there is some better ways to get it to work.

I don’t think it makes sense to do it within the build script like shown in that example, as the build generates that class as you said.

But you can probably define a JavaExec task that has the compilation result as classpath and run some main class that then executes that generation code.

But besides that, are you aware that OpenAPI != JSON Schema?
The first is derived from an older draft of the latter and modified it, changing meaning of fields, adding fields, dropping fields, …
So a JSON Schema generator might not be what you are after.

Yes, I am aware of of that OpenAPI is not JSON schema. JSON schema is a part of OpenAPI (at least from v3). I am settling on defining the model objects.

I did a separate build system where I can depend on the built artifact.

1 Like