How to integrate swagger to my existing java project ? - java

I have an existing project having java code for Rest Web Services. I integrated Swagger to the java project which in turn added lot of annotations and descriptions, messing up my existing code. Is there a way to integrate swagger and read values from another class instead of messing up my existing class?

You just need to add the following annotation with you java file:
#Api(value = "myAdmin", description = "Operation pertaining Admin UI")
Other things are taken care by the RestContoller and all byt itself.
This annotation is not at all messing up with your code.

Related

Swagger for single controller and multiple resources

I am writing a modular project where I need to integrate the swagger on different resources which uses the common controller.
So is it possible to generate the swagger UI for different resources manually writing code without annotation? If so can you please add an example of how can it be done?
Example:
Controller {
GET /{resource-name}
}
APIs:
GET /Patient
GET /Employee
GET /Student
Now I have one controller but 3 different resources. how can I have 3 different APIs in swagger?
SpringBoot + Java + Swagger
Thanks and regards,
Suraj Jannu

Is it possible to: Java DTO --> Swagger --> Java DTO?

In a very big Java app with lot's of DTOs, I want to export to an external project only the DTOs that are relevant to REST calls, and even better to export a part of them (the minimum required for REST calls).
The project uses Swagger and I am wondering if it is possible to take the output of Swagger (uses Java DTOs to create JSON\YAML files), which have the exact content I need, as an input to generate new Java DTO files. The generated files will be only those needed for REST and I will be able to easily export them.
Is this possible?
If not, what is the best approach to do that?
Maybe check out swagger.generator.io where you can generate a whole client library (including DTO classes) for your specified swagger definition file. For documentation please refer to their github page. You can also do the generation of the API client locally utizing the swagger codegen tools.

How to scan for Annotations and the values assigned to them Using Spring

I want to scan for #Controller #Path etc other annotations in my application (Controller), since I wanted to document the REST based services. I am not able to find an appropriate solution for the same and wanted to device my own solution. I was wondering if there is a component in Spring that would help me to scan through all the controller and help me to fetch out this information. I would like to have a custom build scanner from scratch. Please point me to the API in Spring that would help me do so. I would like to build a customized documentation tool.
One way to fetch all classes from your package and check through reflection like
SomeController.class.isAnnotationPresent(Controller.class)
and the other good way is already specified by #Ralph

Use Spring module without using Spring and Maven?

I'm currently working on a project that involves building a REST api using JavaEE. The setup of the project is Tomcat, Hibernate, Wink and Jackson Json for the different json-views. At the moment the unit testing of the rest resources is very poor, we've written custom classes that using introspection find the method that corresponds to a given resource but it is getting in our way (all the workarounds that we need to do in order to execute a simple unit test). I did a little research and found this.
My question is how to "install(add)" the MockServletInvocationTest class and its dependencies to the project? We're not using Maven, nor Spring. Is there a way to use Spring modules (I think this mock class is in the Spring test-module) outside Spring and if yes, how?
I found a solution, so for those who are interested: just add the following jars to your WebContent/WEB-INF/lib:
spring-test-xx.jar
spring-core-xx.jar
wink-component-test-support-xx-incubating.jar
commons-logging-xx.jar
And everything workds fine.

Spring 3 Annotations

I can't get spring annotations to work at all, I'm just trying to get the simplest thing to work...
.../mycontext/something -> invokes method:
#RequestMapping(value = "/something")
#ResponseBody
public String helloWorld() {
System.out.println("hello world");
return "Hello World";
}
My main problem is no matter how hard I try, I can't find a complete SIMPLE example of the configuration files needed, every spring tutorial is filled with junk, I just one one controller to handle a request with a mapping and can't get it to work
does anyone know of a simple and complete spring example. pet-clinic is no good, it's way too complicated, I have a tiny basic use case and it's proving to be a real pain to get working (this always happens with Spring)
You should try Spring Roo. It will generate a simple Spring application for you using simple commands and then you can incrementally extend it. It is a great tool for learning Spring as well as for rapid application development.
You can also find several examples of Spring 3.0 MVC framework.
the absolute simplest alternative if you're familiar with Eclipse is to use SpringSource Tool Suite (Eclipse plugins)
This product has a tcServer bundled inside.
By default, STS will start with "dashboard" page in the editor window. From here, you can click on creating a controller as demonstrated by this screenshot:
This is a quite simple controller and all you have to do to get it deployed on the bundled tcServer (Tomcat with some extra management features) is to click "next" a few times in the wizard.
That's a very good starting point for doing your own testing!
I endorse this blog post,Layered architecture with Hibernate and Spring. It was a great help for me when I tried to move from the declared xml approach to annotations. It contains the usages of annotations in Entity, Dao and Service layers.
I'd recommend you checkout some of projects from here
and try going trough book spring in action(manning) they give very good example on how to use aspects
or refer to this question

Categories

Resources