Best practice sharing a Openapi yaml between Backend and Frontend - maven

in my new project we are using Openapi to share the API endpoints with each other. At the moment the yaml is part of the backend project and we copy it the frontend to create the client interface with the openapi generator. No the plan is to push the yaml into its own repository and publish it to our Nexus.
The backend is sprint-boot java based with maven and the frontend is react with npm.
Questions: if we publish the yaml to nexus (which worked easiely) how can we use it in the backend as dependency to create server part? Since we published just the yaml, maven tries to find a jar.
Questions: is this good practice or is there any better way to do this.

Related

Validate Swagger OpenAPI Specification yaml

I have a Spring Boot application that contains the OpenAPI .yaml specification file in the resources folder and using the openapi-generator-maven-plugin, building the project it generates the API interfaces and then can be used as a maven artifact in another project to implement those APIs.
Currently, I am validating the specification file locally using the Swagger CLI validate command through the terminal.
Is there a way to validate the specification.yaml file when building the project using another plugin or something like that?
If no, is there any dependency I can use to validate the .yaml file while running the project?

External Custom library for Gradle project

I am building a SpringBoot application in which i want to handle some of the cross cutting concerns like logging, caching, persistence in to a project on its own so in future other rest spring boot components can adopt it and use it as a dependency.
I am using Gradle for dependency management. My question is :-
How can i manage this concerns without publishing it to the public artifactory.
If i have to publish then which is the free artifactory i can use for my development practice
If creating jar is an option as a temp solution then how can it be achieved via gradle. Most of the examples over the internet is for creating the executable jar files.
What are the other options i can try.
How can i manage this concerns without publishing it to the public artifactory.
Publishing has to happen regardless where it will be published to. You can use a private solution such as Nexus Repository.
If i have to publish then which is the free artifactory i can use for my development practice
For development, you can simply publish to your local Maven repository. This is typically ~/.m2. Using the Maven Publish plugin, you can easily publish locally by invoking the publishToMavenLocal task.
If creating jar is an option as a temp solution then how can it be achieved via gradle. Most of the examples over the internet is for creating the executable jar files.
Since you're creating a Spring Boot library, use the Java Library plugin to create the JAR artifact and in combination with the Maven Publish plugin to publish.
In the end, there are 2-3 key components that get published when using Gradle:
JAR artifact
pom.xml: https://maven.apache.org/pom.html
Gradle Module Metadata: https://docs.gradle.org/current/userguide/publishing_gradle_module_metadata.html

Adding Swagger API Documentation to Maven Site

I have a Spring Boot project and I'm using swagger to test and document the API. The project also contains a bunch of classes that are used as libraries and I'm using scala docs to document those. Is there a way to unify API docs (from swagger) and Scala Docs as I'm hosting the docs using maven site plugin.

Details about Github repository spring-project/spring-framework

What's the purpose of spring-project/spring-framework repository in GitHub?
How to run this applications using eclipse?
This is where Spring Framework source code is hosted.
If you want to start using Spring, you don't need their Github repository, I'd recommend starting at their official site: https://projects.spring.io/spring-framework/ There you can find the documentation, description of the subprojects that comprise Spring Framework, as well as instructions of how to use it. There is an example on their main page.
If you want to build an application, you could take a look at Spring Boot: https://projects.spring.io/spring-boot/ The site, again, contains documentation, guides, examples and so on.
Here you can find information on how to run your Spring Boot application in Eclipse: https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-running-your-application.html
They have their own IDE based on Eclipse: https://spring.io/tools/sts
And if you want to rebuild Spring from source or (more likely) learn how it works, then its Github repo will be useful for you.

Example using Jersey (REST resource), OSGi (Apache Felix), and Maven (build and deploy)?

I seem to be really struggling here. What I want to do (in this order) is:
1) Build a RESTful resource using a Jersey application and resource w/annotations (this is not the issue).
2) Package, install, and start that bundle into the Felix OSGi container, as an HTTP service, including dependencies.
3) Package, install, and start a WAR in the OSGi container that may incorporate #2 as a dependency.
And I would like to be able to do all of this using Maven.
I cannot seem to find a working example of even the individual steps, especially involving Maven, that work let alone the combination of those steps. I have tried cobbling together various q&a from across the web with varying levels of success but not an end-to-end working example yet.
Any pointers would be appreciated...
I do not have an example for Jersey but I have a tutorial for CXF with Apache Karaf (which uses Felix). It shows how to create a Rest service and build it with maven. Using Apache Karaf you can then deploy the bundle directly from the maven repo. Moving this to Jersey probably just means to exchange the lib and use another blueprint config to initialize the rest service.
Apache Karaf also allows to deploy wars and wabs but I have not yet tested them.
Apache Stanbol does most or all of this (not sure if the war packaging is included out of the box) to implement its RESTful services.
You'll have to dig through its codebase but searching for Jax-RS annotations in there should point you to the right places.
I also am really struggling with exactly what you are attempting to do. So far, I seem to be really close but alas not quite there, here's what I've been doing:
creating a War with Maven that defines my Jersey Resource's
bundling it with maven bundle plugin ( see section Adding OSGi metadata to existing projects without changing the packaging type ). Which allows me to run the restlets in Tomcat and test.
define a target in Eclipse that includes resources from my locally defined p2 site which I create with the p2-maven-plugin plugin. In this way I can gather up any of the dependencies from the WAR project into a p2 site, which I can deploy to an Eclipse defined target
Where I am stuck is trying to register the Jersey Resource's as services, for which I've tried:
using the JAX-RS OSGI connector, for which I eventually gave up on because it uses glassfish jersey which seems to export a version 2 API of Jersey when Jersey hasn't even defined a version 2 API yet. This caused package resolution problems when I wanted to use version 1.17 of Jersey libs.
registering the Resources using a Whiteboard a la Apache Felix HTTP Service, my current approach which doesn't seem to work yet.
And, finally, if the preceding doesn't work I'll try Amdatu
Another route I might try is from the Jersey project OSGI chapter
I tried this combination and made it up and running -
1- Modularity Specification-->OSGi specification
2- OSGi implementation-->Apache Felix 4.4.0
3- OSGi Runtime-->Apache Karaf 3.0.3
4- Software Architecture Specification of REST – JAX-RS
5- JAX-RX implementation-->Apache CXF – 2.7.5
You can refer this nice tutorial - http://java.dzone.com/articles/building-cxf-rest-service-osgi
Now, I am also planning to move to Jersey from CXF as the Jersey is the light wait reference implementation of JAX-RS. Now I am planning to use Jersey with Apache Felix/Apache Karaf. You can install Jersey in Karaf and deploy your Jersey Rest Web Services as Bundle. You can refer this tutorial - https://vzurczak.wordpress.com/2014/09/30/web-applications-with-osgi-working-with-jersey/
Here's a good example on github : https://github.com/ddragosd/jax-rs-on-karaf

Resources