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
Related
I've been working a lot with Symfony recently, and I really like the ability to define routes in a routing.yml file. I was looking into Spring's routing system and I couldn't find any options other than placing routes in annotations on controller methods. Is it possible to accomplish something like this in Spring?
My first thought was creating an abstract controller that grabs the routes from a .yml file, but that seemed a bit hacky.
EDIT:
For some added context, I am looking to build a simple Database API with Spring. After some digging it looks like the routing.yml file is best suited for working with server-rendered pages, which is not what I aim to do with my Spring project.
Symfony and Spring are different framework. You are used to one use and want to use same it in another entirely different system. It will not work. You have to adapt to frameworks.
Spring will scan your project and collect your specific annotation like Controller/Component/Configuration/... and configures itself. Therefore, there is no need predefined project structure, unlike, for example, Laravel. So, you can define this structure if you want. Or every class can be in one package, just not beautiful.
Back to routing. You can configure them by the value of annotations only. This is interpreted at compile time. (Ofc, there are runtime annotations, but I focused parameters of annotation.) So, you can not use configuration from the file because it is already runtime. So, you should use constants or hardcode.
Or, you can use an alternative: Annotate the interfaces, then the controllers will be the implementations.
Alternative #2: If you use Spring with Kotlin, In Kotlin, you can have several classes or interfaces in one file.
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
I am using spring boot. There are some common classes to the 2 exsisting spring boot projects. I need to add common module as sub module to them .how to do this please guide me step by step.
You can create a library/jar/dependency of the common code and than you can access it from the dependent client.
A very detailed example is provided in the below article
https://blog.scottlogic.com/2016/06/13/code-reuse-in-microservices-architecture.html
You can create a Maven project/Gradle of common code project and add dependency as Maven or Gradle modules to the project that you are using,so now you can access it from the common project.
you will have projects like this below, where your common module will be shared amongst the project e.g. constants. or messages.
You can also go with parent-child project structure if your requirement is too complex.
here is link is for your reference link.
Both provided in samples/toolingApi/customModel and Feature Spotlight examples of Gradle Tooling API custom model use plugin to register the model. However in order to apply the plugin it's necessary to either change build.gradle or use initialization scripts, which are supported by GradleConnector (yet).
How can I register a custom model within Tooling API itself, so my application can retrieve projects' information in a custom format without changing their build.gradle files? How can I get a reference to ToolingModelBuilderRegistry implementation in an application code?
Init scripts are supported, they are just an argument like any other.
projectConnection.models(ModelType).withArguments('--init-script', pathToInitScript).get()
I have started creating a project using springboot. There are multiple micro modules each having different controller. How can I expose all the controllers on a single host,port combinations. Also How can I make swagger to list all apis across different controllers.
The project is like
ABCD\
--\A\A Controller
--\A\build.gradle
--\B\B Controller
--\B\build.gradle
--build.gradle
Thanks for any pointers.
Is there a way I can make a collective war having all the controllers inside it
I am using springfox.io for the same. The challenge is I can get all the api listed in springfox/swagger provided if I jar all the modules and add to the modules with springfox config. But for this I have to create separate module and everything is running on one server. I want A controller to be running in one tomcat and B in another, and springfox on either C or any of A or B, but listing all apis of A and B. There might me some use case I am missing, please let me know.