Validate Swagger OpenAPI Specification yaml - maven

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?

Related

Best practice sharing a Openapi yaml between Backend and Frontend

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.

Custom Spring starter vs standard Jar

Why should we build our own custom starters when we could just use a standard jar (ie. putting all your common codes and component into a single project, build the jar and use it in another SpringApplication)?

Generate OpenAPI YAML File from Swagger Annotations

I have a java class with the openapi documented using swagger annotations as below. I want to generate the JSON file for this documentation using gradle, but I am unable to do so. I have tried using the OpenAPI Generator Gradle Plugin but I believe this plugin works the other way around. How can I generate the JSON file from the swagger annotations?

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.

Spring framework library

Can I make a library with Spring framework, and then include that library in an application that uses the Spring framework?
Yes you can make a library that uses Spring, and then include a dependency on that jar in another application created with Spring. You will want a build tool that handles dependencies, like Maven or Gradle, and probably a repository manager like Nexus or Artifactory to store artifacts that you create.
You have to make sure that the jar gets included in the component scan performed by the hosting application. See the Spring reference documentation on Importing configurations.
If the library has its own Configuration, importing the Confuguration gets it included in the component scan.
Alternatively create a marker interface in your library like this:
#ComponentScan
public interface MyLibrary {}
then in the including application have a Configuration class annotated with
#ComponentScan(basePackageClasses= { MyLibrary.class })
and the including application will scan all Components in the package hierarchy starting from the package of the marker interface.
Spring is open source so you can contribute to it. Refer to https://github.com/spring-projects/spring-framework/blob/master/CONTRIBUTING.md for more details.
Yes, any Java based applicaiton (like spring framework) can be packaged as a JAR file and published to a repository (or store it locally to start simple)
This Jar file can be included as a dependency in another Java based application (like spring framework)
To add dependencies you can either use Maven or place it in a directory and add it to local classpath for the next application to use the library.
Your library becomes a reusable library (usually a JAR file) for all other java based applications

Resources