Contributions
Re: What swagger should I use with Jersey 3.0.2 REST Framework?
The main issue was in annotations of the code that I was using spring based annotations and using jakarta.ws.rs namespace. Here are my steps that solved the issue: 1. Upgraded the gradle as mentioned in the bottom 2. Fixed annotations 3. Configure jersey servlet and openapi servlet from swagger-core as mentioned below 4. Added content of `swagger-ui/dist/*` into `/src/resources/webapp` and pointed the index.html to `localhost:8080/openapi/swagger.json` where my openapi.yaml is being generated Build.gradle: plugins { id 'java' id 'application' id "io.swagger.core.v3.swagger-gradle-plugin" version "2.1.9" } group 'org.example' version '1.0-SNAPSHOT' repositories { mavenCentral() } ext { javaMainClass = "io.swagger.Main" } application { mainClassName = javaMainClass } dependencies { implementation platform('org.glassfish.jersey:jersey-bom:3.0.2') implementation 'org.glassfish.jersey.containers:jersey-container-grizzly2-http' implementation 'org.glassfish.jersey.inject:jersey-hk2' implementation 'org.glassfish.jersey.media:jersey-media-json-binding' implementation 'org.apache.commons:commons-lang3:3.7' implementation 'io.swagger.core.v3:swagger-jaxrs2-jakarta:2.1.9' implementation 'jakarta.ws.rs:jakarta.ws.rs-api:3.0.0' implementation 'jakarta.servlet:jakarta.servlet-api:5.0.0' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' } resolve { outputFileName = 'MyRestAPI' outputFormat = 'JSON' prettyPrint = 'TRUE' classpath = sourceSets.main.runtimeClasspath buildClasspath = classpath resourcePackages = ['io.swagger'] outputDir = file('test') } Jersey & openapi servlet into Jetty Server: // Setup Jetty Servlet ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); servletContextHandler.setContextPath("/"); contexts.addHandler(servletContextHandler); // Setup API resources ServletHolder jersey = servletContextHandler.addServlet(ServletContainer.class, "/api/*"); jersey.setInitOrder(1); jersey.setInitParameter("jersey.config.server.provider.packages", "com.cloudian.hfs.handlers;io.swagger.v3.jaxrs2.integration.resources"); // Expose API definition independently into yaml/json ServletHolder openApi = servletContextHandler.addServlet(OpenApiServlet.class, "/openapi/*"); openApi.setInitOrder(2); openApi.setInitParameter("openApi.configuration.resourcePackages", "com.cloudian.hfs.handlers"); // Setup Swagger-UI static resources String resourceBasePath = ServiceLoader.class.getResource("/webapp").toExternalForm(); servletContextHandler.setWelcomeFiles(new String[] {"index.html"}); servletContextHandler.setResourceBase(resourceBasePath); servletContextHandler.addServlet(new ServletHolder(new DefaultServlet()), "/*"); And then I was able to access swagger.json at http://localhost:8080/3.1KViews0likes0CommentsAnnotate a required queryParam
I am using swagger-core 2.1.9 with Jersey 3.x JAX-RS API and Jakarta namespace. I have a query that looks likehttp://127.0.0.1:8080/FeatureGroup/NetflixData?RecordIdentifierValueAsString=s146&FeatureName=show_id&FeatureName=cast&FeatureName=time. My method definition is: @GET @Path("/{featureGroup}") public void getRecord( @PathParam("featureGroup") String featureGroup, @Schema Jedis jedis, @Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException, JedisException, JSONException {} I want to annotate a required/notnull queryParamRecordIdentifierValueAsStringas somewhere for this call. But when I do that, it says that local variable can not be annotated - @NotNull @QueryParam("RecordIdentifierValueAsString") String recordIdentifier; How can I annotate a query param if its not used as an argument to the method?412Views0likes0CommentsWhat swagger should I use with Jersey 3.0.2 REST Framework?
I am working on a code-first approach in following environment: Jetty 11 Jersey 3.0.2 Jakarta.ws.rs (since Jetty 11 is part of Jakarta EE 9 big bang) Gradle 7.0 I configured the jersey rest framework in the jetty server and it is already detecting all my APIs. This also means I am done annotating my APIs. Now I need to hook up swagger-core into my project. And I am referring - Documenting Your Existing APIs guide (OAS Generating During Runtime) Swagger setup for Embedded Jetty Server Swagger 2.X Integration and Configuration In one of the links above, it has been mentioned that: Depending on the way Jersey is configured in your web service, you could hook up Swagger Core to your application using Spring, the Jersey’s container Servlet, or manually. Since I am using Jersey 3.0.2 REST Framework into Jetty, what swagger-core version should I use to hook up swagger into my jersey container's servlet? Or is there a better approach to solve this issue easily?3.4KViews0likes2CommentsRe: Need help enabling OpenAPI into non-spring java project
joejoycehugomarioI am trying to user swagger-core-gradle-plugin. But I am confused about 1 thing - whether I need to specify jakarta artifact. I have set my gradle plugin as follows: id "io.swagger.core.v3.swagger-gradle-plugin" version "2.1.9" But since I am using Jetty 11 which works with jakarta namespace only, do I need to set buildClasspath = classpath so that my gradle dependencies will refer to jakarta based builds? If I use the plugin with suffix `jakarta`, that does not seem to have fetching the packages. Can someone please help?3.1KViews0likes0CommentsRe: Need help enabling OpenAPI into non-spring java project
joejoyceI think swagger core project is what I am looking for. But I need some more help about this. In theWhere to startsection, it says - since version 2.0.5,swagger-coreproject also providesmavenandgradleplugins to resolve an OpenAPI definitionat build time. As these are based on the same resolving and configuration mechanisms, most information in the wiki applies also in this case. I have added theswagger-core Gradle plugin in the id section and other dependencies in the Jakarta namespace in dependencies. Now if my code is annotated, should I see the swagger-ui directly when I run my project or I need to configure swagger-ui in my main method?3.1KViews0likes1CommentRe: Need help enabling OpenAPI into non-spring java project
joejoycethis is a great suggestion. Infact I am looking for solution in Jakarta namespace only. I will try to use this. But would this automatically generate the OpenAPI yaml after code annotation? Or I will have to use some tool to get the yaml first? I am trying to generate yaml from code annotations. Can you provide something about this confusion?3.3KViews0likes1CommentNeed help enabling OpenAPI into non-spring java project
I am using jetty server that is initiated with a port and threadconnectionpool. I add the handlers to the contexts object and then all my APIs are in the com.example.handler package. I am very very new to the OpenAPI and I want to document all my above apis. How do I get started from scratch? I mean what kind of dependencies do I need and also what should I do to hook up my project with openApi?3.2KViews0likes8Comments