Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@ApplicationPath is not working? #3935

Closed
rider87 opened this issue Apr 19, 2021 · 8 comments
Closed

@ApplicationPath is not working? #3935

rider87 opened this issue Apr 19, 2021 · 8 comments

Comments

@rider87
Copy link

rider87 commented Apr 19, 2021

Hi,

I´m currently installing Swagger, but it seems the @ApplicationPath is not working as expected.

I have the following code:

@ApplicationPath("/service")
@Api( tags = "docs" )
@OpenAPIDefinition(info = @Info(
        title = "My application", 
        version = "1.0.0", 

)
public class SwaggerApplicationConfig extends Application {
	
}

In Web.xml:

<servlet-mapping>
		<servlet-name>javax.ws.rs.core.Application</servlet-name>
		<url-pattern>/service/*</url-pattern>
	</servlet-mapping>

Example Endpoint:

/**
 * Customer Endpoints
 */
@Path("/customer")
@Tag(name = "Customer", description = "Returns all information for customers")
public class CustomerWebservice {

	@GET
	@Path("/")
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "Returns all Customer", notes = "Returns Customer", response = Response.class)
	@ApiResponses(value = {
			@ApiResponse(responseCode = "200", description = "Successful, returning the value"),
			@ApiResponse(responseCode = "404", description = "Not found"),
			@ApiResponse(responseCode = "500", description = "Internal Server Error")
	})
	public Response findAllCustomers() {
		try {
				return Response.ok(customerDtoList, MediaType.APPLICATION_JSON)
					.build();

		} catch (Exception e) {
			LOGGER.error(ExceptionUtils.getFullStackTrace(e));

			ErrorMessage errorMessage = new ErrorMessage(e.getMessage(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
			return Response.status(Status.INTERNAL_SERVER_ERROR).entity(errorMessage).type(MediaType.APPLICATION_JSON)
					.build();
		}
	}

I´m using those libs:
`<dependency>
			<groupId>io.swagger.core.v3</groupId>
			<artifactId>swagger-jaxrs2</artifactId>
			<version>2.1.8</version>
		</dependency>
		<dependency>
			<groupId>io.swagger.core.v3</groupId>
			<artifactId>swagger-jaxrs2-servlet-initializer-v2</artifactId>
			<version>2.1.8</version>
		</dependency>

The json File is generated, but the URL is only:
http://localhost:8080/customer

But it should be:
http://localhost:8080/service/customer

Here in the Swagger GUI:
image

Any idea what needs to be changed?

@frantuma
Copy link
Member

Can you share some more details about your configuration, like a test project / scenario reproducing the issue?

@rider87
Copy link
Author

rider87 commented Apr 19, 2021

What kind of other configuration are needed besides my first code?
Is there anything which is not correct from my first post?

@frantuma
Copy link
Member

for example there is no clue about which JAX-RS implementation you are using, the full deps of your project, the server in use and how you launch, how resources are registered, if there is any additional config

@rider87
Copy link
Author

rider87 commented Apr 19, 2021

Ok, thanks....

I´m using

  • Wildfly 21
  • import javax.ws.rs.core.Application;
  • Maven build the .war file
	<dependency>
			<groupId>io.swagger.core.v3</groupId>
			<artifactId>swagger-jaxrs2</artifactId>
			<version>2.1.8</version>
		</dependency>
		<dependency>
			<groupId>io.swagger.core.v3</groupId>
			<artifactId>swagger-jaxrs2-servlet-initializer-v2</artifactId>
			<version>2.1.8</version>
		</dependency>

<dependency>
			<groupId>jakarta.platform</groupId>
			<artifactId>jakarta.jakartaee-api</artifactId>
			<version>8.0.0</version>
			<scope>provided</scope>
		</dependency>

In my web.xml
`
javax.ws.rs.core.Application
/service/*

<servlet>
	<servlet-name>OpenApi</servlet-name>
	<servlet-class>io.swagger.v3.jaxrs2.integration.OpenApiServlet</servlet-class>
	<init-param>
		<param-name>openApi.configuration.resourcePackages</param-name>
		<param-value>io.swagger.sample.resource</param-value>
	</init-param>
</servlet>
<servlet-mapping>
	<servlet-name>OpenApi</servlet-name>
	<url-pattern>/openapi/*</url-pattern>
</servlet-mapping>`

My config:

@ApplicationPath("/service")
@Api( tags = "docs" )
@OpenAPIDefinition(info = @Info(
        title = "My application", 
        version = "1.0.0", 

)
public class SwaggerApplicationConfig extends Application {
	
}

@frantuma
Copy link
Member

Please try with version 2.1.9 and adding init-param (or via configuration) alwaysResolveAppPath like:

    <init-param>
        <param-name>openApi.configuration.alwaysResolveAppPath</param-name>
        <param-value>true</param-value>
    </init-param>

see also #3060

Please close tickets if it solves your issue

@rider87
Copy link
Author

rider87 commented Apr 20, 2021

Thanks, but 2.1.9 is not available on maven?
Latest is 2.1.8

Please see also:
https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-jaxrs2

I´ve tried:

<dependency>
			<groupId>io.swagger.core.v3</groupId>
			<artifactId>swagger-jaxrs2</artifactId>
			<version>2.1.9</version>
		</dependency>
		<dependency>
			<groupId>io.swagger.core.v3</groupId>
			<artifactId>swagger-jaxrs2-servlet-initializer-v2</artifactId>
			<version>2.1.9</version>
		</dependency>

@frantuma
Copy link
Member

It takes up to a few hours for sonatype to publish release, please check again in a bit

adagios pushed a commit to adagios/swagger-core that referenced this issue Apr 20, 2021
@rider87
Copy link
Author

rider87 commented Apr 21, 2021

Great, it´s working. Many thanks

@rider87 rider87 closed this as completed Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants