Maven Generate OpenAPI JSON for SpringBoot REST Controllers - spring-boot

Is there a Maven plugin which can generate an openapi.json file at build time for my SpringBoot RestControllers?
If not a Maven plugin, is there another simple package to generate the file at build time?
I only want the openapi.json file, I don't want Swagger UIs auto-integrated, etc.

I was able to get this working with SpringDoc.
I couldn't find a project which showed exactly my use-case (without all the swagger ui stuff), so I created an example project on GitHub for others to use as reference: springdoc-maven-plugin-demo

You can use Spring-doc which support OpenAPI 3
Look at the demos

Related

How to generate an OpenAPI from a Spring app without running the app?

I can run a Spring Boot application and then use the springdoc-openapi-maven-plugin artifact to generate an OpenAPI spec.
However, is there also a way to generate the spec without running the application first?
I currently want to generate the spec in a GitHub Action and a direct way would simplify this a lot.
you can use swagger editor: https://editor.swagger.io/
It allows you to write a json/yaml with your specifications and at the same time you can view the result.
Also, in the upper part there are 2 features, which allow you to generate the code based on the json/yaml made.
For example you can create a spring application with all the endpoints you go to specify in your json/yaml ( server).
But you can also generate HTML. (Client)

Is there a maven plugin that I can use to generate openapi spec file from JAX-RX source files

I'm trying to generate openapi/swagger spec file during the build time. Maven plugin jaxrs-gen works but it's very old and no longer maintained and creates very old version of swagger spec file which is no longer compatible with the new versions. Please note that openapi-generator-maven-plugin which creates java client end points from spec file works as expected, but I am trying to do the other way round.
I found SmallRye OpenAPI Maven Plugin which works as expected and is aligned to what I needed.

Automatic OpenAPI YAML generation

I am working on the backend of a Spring Boot application that uses OpenAPI and Swagger to provide the interface for frontend application via an schema.yml file.
When a change is done on the controllers, we use the swagger-ui to get the api-docs JSON, convert it to yaml using the online swagger editor and paste the result in th schema.yml file
Now, I want to automate this so that we can just call a maven task that will automatically generate the yaml file, but I could not find any maven plugin that does this.
Is there a way to automate the generation of the yaml file or do I need to write my own plugin?

How to generate swagger code gen for a spring boot project

I need help in getting clarification for below mentioned points
I have a swagger json. From this I want to generate Model separately by passing java as language. api and invoker clsses by passing spring as language and want to add model jar as dependency. Because I want to use model for different projects commonly. So I want to include a build task to generate model jar every time to get latest models from json. and will issue swagger code gen command with spring as language while trying to create project. Is this correct way of handling. If not can someone let me know best of handling this.
How to handle versioning from swagger.
I am new in using swagger and spring. Please suggest me best to go
I do something similar. I have my models in a separate project which is then a dependency for a bunch of API projects. This is because the APIs sometimes call each other, so need to know about each others objects.
What I do is:
Swagger structure:
In the models project I have a swagger containing just the definitions (empty object as paths)
In the API projects I have a swagger which references the definitions in the models project
Build process
Build the models project first with generateApis = false
Build the APIs with typeMappings and ImportMappings in the config, telling them to take all the models in common from that namespace
I use the maven plugin to run the codegen. I have a pretty hacky bash script that updates the type mappings in the pom when I have added new objects to the models

How to build an Angular2 type script with spring boot back end in STS

I am learning angular 2 currently and trying to hosted in springboot java application.
I created a separate project using angular cli , then I created spring starter project with web only.
Next I imported the angular cli project inside /src/main/resources/static directory.
when I opened the browser , I was not able to see the basic index.html.
Then I removed all the imported files and imported only the content of the directory , which is the resulting compiled ES5 java script after transpiling the type script files in directory, this time it worked.
My questions are:-
1) What is the best practice , to use the GUI under /src/main/statis or create /src/main/public or /src/main/webapp ?
2) Does spring understand only js and not ts ( java script and not type script)?
3) Do I need a maven plugin for typescript and if so how to tell maven bundle the compiled js with the spring war while excluding the rest directories and files
4) How to include the testing unit / e2e with maven build
I searched for step by step guide for ANgular 2 and spring boot but could not find one. It would be helpful to many if some guide like this exist.
Many thanks for your support guys.
1) What is the best practice , to use the GUI under /src/main/statis or create /src/main/public or /src/main/webapp ?
Since typescript compiles to JavaScript I strongly recommend using GULP. I have my source files under src/client and I build with gulp to add the files to src/main/public
I believe either public or webapp works and there's not a huge difference.
2) Does spring understand only js and not ts ( java script and not type script)?
The newer version of STS has support for typescript, but I prefer to use visual studio code when viewing typescript files as there is better support.
3) Do I need a maven plugin for typescript and if so how to tell maven bundle the compiled js with the spring war while excluding the rest directories and files
If you use gulp, the typescript is compiled to js and added to the src/main/public directory where your springboot app sees the files when running with maven.
4) How to include the testing unit / e2e with maven build
I searched for step by step guide for ANgular 2 and spring boot but could not find one. It would be helpful to many if some guide like this exist.
Many thanks for your support guys.
I recommend using an angular seed or starter, this seems like the most up to date one that I've found:
https://github.com/antonybudianto/angular2-starter
This uses gradle, but is spring boot and angular 2:
https://github.com/borysn/spring-boot-angular2
I shared a project on github that integrates Angular 2 With spring boot. Just need to follow the step on readme or check commit history. You can access here Angular 2 with spring boot

Resources