Micronaut Swagger multimodule - maven

I am trying to visualize the API definitions from a Multimodule project. First I want to start from simple, and I want to visualize the yaml from the parent module. Then I will add other APIs in my Swagger Controller to call the specific url as is done in the example https://github.com/frehov/micronaut-swagger-server
I have my Swagger Controller and my SwaggerConfiguration with my index.hbs inside resource > views.swagger I took the example from the repo https://github.com/frehov/micronaut-swagger-server
This is my Result:
Instead of something like:
When I compared the two project, somehow my view.swagger package from my target folder gets generated into a different way, compared with the example:
What I am missing?
Could you please look at my repo:
https://github.com/amhg/swagger
Thank you

The folder containing the swagger-ui-wrapper (index.hbs) in your project is called 'views.swagger', while the sample has defined 'views/swagger' (so swagger is a folder inside of views). Change that and you get the views/swagger result in your target.
You also need to enable the micronaut handlebars-views (i.e. serving the .hbs files from a controller); add these to the pom.xml of startup (not at the root-pom!):
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-views</artifactId>
</dependency>
<dependency>
<groupId>com.github.jknack</groupId>
<artifactId>handlebars</artifactId>
<version>4.1.0</version>
<scope>runtime</scope>
</dependency>
These will perform the magic of rendering the configuration you return from the controller into an html-page.
Depending on where you're going to put the swagger-annotated controllers, you might also want to add
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger.version}</version>
<scope>compile</scope>
</dependency>

Related

Swagger Jersey project, openapi.json is missing "maximum" and "minimum" etc

Jersey project using following Swagger Core:
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.0.2</version>
</dependency>
open and compare "path/openapi.json" and "path/swagger.json", openapi.json is missing information like "maximum" and "minimum". for some reason I have to use openapi.json instead of swagger.json. Please refer to the image below.

Using different JBoss BOM in profiles

I have a general question about the usage of the BOM from JBoss and WildFly.
Is the a way to build a project for both JBoss 7 and WildFly 10 using a different profile?
I tried to copy the BOM definition from WildFly into a profile like this:
<profile>
<id>WildFly10</id>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-javaee7-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- JSON -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>${version.json}</version>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
Of course accourdingly with a JBoss7 profile.
But this way it won't add important libraries to the lib folder, i.e. this definition is in an ear pom and a subproject (war) adds the json dependency. Without a profile maven adds the json jar inside the lib folder, but not if I put it inside a profile.
After I read that changing dependencies in a profile is an anti-pattern [1] I would like to know how I can build my project for both JBoss7 and WildFly 10.
Update
Ok sorry for this quick shot of a question. Here are more details.
project structure:
|-parent (pom)
|- myapp (war)
|- core (jar)
|- deployment (ear)
So deployment is the project building the whole ear containing myapp as a web apllication and core as a library. myapp has a dependency to core and core to json.
In order to have all needed depenedencies with the correct version I included wildfly-javaee7-with-tools in the dependencyManagment. Also is the version of json defined in there. The core project has the json library as a normal dependency.
At this point this should be quite standard. But the thing is I want to be able to build for JBoss 7 and WildFly 10, for what I have to change
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-javaee7-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
to
<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>jboss-javaee-6.0-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Of course ${version.jboss.bom} will be changed from 10.1.0.Final for WildFly to 1.0.7.Final for JBoss.
In order to do so I tried to move wildfly-javaee7-with-tools into a profile. My first guess was to only move this dependency to a profile. But then the json jar doesn't get included. After that I also tried to move jsonlike above.
Without seeing the original not-profiled nor profiled pom in whole cannot say anything accurate but educated guess.
You have json in profiles dependency management.
Is it also in poms main dependencies without version? If not it will not be copied to lib nor packed. It is only managed by profiles <dependencyManagement>.
Does json need managing per profile? It seems to have ${version.json} which then anyway would be same for each profile if copied as it is in the example.
For me it seems that fix might be that you remove the json from profiles dependencyManagement and add it to main dependencies as normal dependency - this just to make profiling more simple - it can be managed but if not needed set the version of json directly to dependency.

Where to use which scope in maven pom.xml

I have a project "framework-ws" that contains 3 modules (api, dictionary, webapp).
This project is used has a parent project for multiples other web-services project.
For example, the project "core-ws" has "framework-ws" for parent. It also contains 3 modules (api, dictionary, webapp).
Each of these modules has the framework as dependency.
core-ws-api => framework-ws-api
core-ws-dictionary => framework-ws-dictionary
core-ws-webapp => framework-ws-webapp
(subproject => dependency)
Now I have other dependencies (lombok for example) that is used in every project (framework + child-project).
I don't understand where I need the declare this dependency.
In the parent project with a "provided" scope, and in each
child-project without scope
In the parent project with no scope, and no dependency in each
child-project
Another solution that I didn't think of
The second solution seems cleaner because I don't need to duplicate the dependencies in each pom.xml. But I don't know if it's the best practice.
EDIT : Here is a picture of projects structure.
In your parent pom use a dependency management section see https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</dependencyManagement>
Then in your child pom you will use the dependency but not specify a version, i.e. the version will be specified in the parent once for all children. You still need to include the dependency in each module.
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
</dependency>
</dependencies>
In terms of scope read this https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope the default scope is compile which is what you will usually use. I think you are confused about the meaning of scope from readinf your question.

Not Able to Resolve View Using Spring boot

I have put all jsp on classpath in views folder.
Folder structure is :
src/main/resources/
src/main/resources/static/
src/main/resources/static/views/
src/main/resources/static/views/*.jsp
src/main/resources/static/views/*.png
I am able to retrieve images file from static folder. But When It comes to jsp I am getting following error.
While hitting url:http://localhost:9001/login
There was an unexpected error (type=Not Found, status=404).
/views/login/login.jsp
However login.jsp exists on given location.
You can place your JSP files in "src/main/resources/META-INF/resources" folder location.
I have created a "WEB-INF/jsp" folder under "src/main/resources/META-INF/resources" and placed the JSP file there.It works. Check the screenshot.
https://i.stack.imgur.com/P3jUI.png
Alternatively, You can create "WEB-INF/jsp" folder under "src/main/webapp" and placed the JSP file there.But for this you have to package it as ".war" extension.
Springboot default tomcat container does not handle JSP. so we need to use below dependency to handle it :
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
And if you are using JSTL tags in JSP then add below jar as well :
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
A template such as a JSP is the exact opposite of static content such as an image file. Put your template in src/main/resources/templates.
Put them in folder :
src/main/resources/templates
2.These three dependencies could help you:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
I believe by default Spring Boot looks for html files. To change that behavior you have to change your application.properties as following to use jsp-s: spring.view.suffix: .jsp
Maybe even change spring.view.prefix as well to point to static resources.
I would personally suggest to use html-s with Thymeleaf though.
I was supposed to use war as packaging. Jar packaging does not work in case of jsp.

GWT ERROR: No source code is available for type org.hibernate.validator.constraints.impl.SizeValidatorForString

I am trying to set up client-side validation for my GWT app by following instructions provided by the following link:
http://code.google.com/p/google-web-toolkit/wiki/BeanValidation
...and by looking at the validation sample provided in:
http://code.google.com/p/google-web-toolkit/source/browse/trunk/samples/validation
I have set up the exact same project as in the validation sample, but as a regular GWT project - not using Maven. I have hibernate-validator-4.2.0.Final.jar and slf4j-api-1.6.1.jar on both my client and server classpaths. However; I am still getting the following error at runtime:
No source code is available for type org.hibernate.validator.constraints.impl.SizeValidatorForString; did you forget to inherit a required module?
No source code is available for type org.hibernate.validator.constraints.impl.SizeValidatorForCollection; did you forget to inherit a required module?
No source code is available for type org.hibernate.validator.constraints.impl.SizeValidatorForMap; did you forget to inherit a required module?
The classes mentioned are in hibernate-validator-4.2.0.Final.jar. Therefore, I am a bit confused. Could it be that the super-source statement in Validation.gwt.xml that is hiding the classes defined in the jar?
Note the error: it isn't that the classes, but that the source is missing. Make sure you have a jar with the classes on the client classpath as well.
The super-source statement is used to define a package that contains source that should be used to provide client-equivalent functionality for some non-client package.
you need to have in your classpath both:hibernate-validator-4.2.0.Final-sources.jar and hibernate-validator-4.2.0.Final.jar
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
<classifier>sources</classifier>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>

Resources