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

ExtensionProperty missing in JSON #1523

Closed
Inge72 opened this issue Oct 27, 2015 · 14 comments
Closed

ExtensionProperty missing in JSON #1523

Inge72 opened this issue Oct 27, 2015 · 14 comments
Assignees
Labels
Milestone

Comments

@Inge72
Copy link

Inge72 commented Oct 27, 2015

The ExtensionProperty is missing in JSON when placed inside the ApiOperation tag.

Example:

@ApiOperation(value = "Returns a greeting for the specified user.",
notes = "Returns a greeting for the specified user based on the given parameters.",
response = Greeting.class,
extensions = {
@extension(properties = {
@ExtensionProperty(name = "externalPath", value = "/hello-world/v1/{endUserId}")
})})

I would expect to find "x-externalPath": "/hello-world/v1/{endUserId}" in the JSON file, but it is missing.

This has been tested with version 1.5.4 of swagger-jersey2-jaxrs.
Note: It works fine for ExtensionProperty placed in @SwaggerDefinition@Info.

@olensmar olensmar self-assigned this Oct 27, 2015
@webron webron added this to the v1.5.5 milestone Oct 27, 2015
@olensmar
Copy link
Contributor

Hi - I can't see any immediate reason to why this would fail - can you share the entire resource class to give some more context?

@olensmar
Copy link
Contributor

i've pushed some related fixes to https://github.com/swagger-api/swagger-core/tree/issue-1523 - although I would be surprised if they helped in your specific case - if you have the time to try that would of course still be helpful :-)

@Inge72
Copy link
Author

Inge72 commented Oct 28, 2015

I have made a small example:

package com.telenor.no.service.helloworld.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info;
import io.swagger.annotations.SwaggerDefinition;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

@Produces("application/json")
@Path("/rest")
@Api("hello-world-v1")
@SwaggerDefinition(info =
@Info(title = "hello-world",
        version = "v1",
        extensions = {
                @Extension(properties = {
                        @ExtensionProperty(name = "accessLevel", value = "private"),
                })}))
public class HelloWorldServiceRest {

    public HelloWorldServiceRest() {
    }

    @GET
    @Path("/test/")
    @ApiOperation(value = "Test",
            extensions = {
                    @Extension(properties = {
                            @ExtensionProperty(name = "externalPath", value = "/hello-world/v1/")
                    })})
    public Response getGreeting() {
        return Response.ok("Test").build();
    }

}

This produces this JSON:

{
  "swagger": "2.0",
  "info": {
    "version": "Swagger Server",
    "title": "",
    "x-accessLevel": "private"
  },
  "tags": [
    {
      "name": "hello-world-v1"
    }
  ],
  "schemes": [
    "http"
  ],
  "paths": {
    "/rest/test": {
      "get": {
        "tags": [
          "hello-world-v1"
        ],
        "summary": "Test",
        "description": "",
        "operationId": "getGreeting",
        "produces": [
          "application/json"
        ],
        "parameters": [],
        "responses": {
          "default": {
            "description": "successful operation"
          }
        }
      }
    }
  }
}

The x-accessLevel field is present, but the x-externalPath field is missing.

@olensmar
Copy link
Contributor

awesome - thank you - digging in!

@olensmar
Copy link
Contributor

so - unfortunately this works for me - how exactly are you hosting the resource? (framework, etc)

@Inge72
Copy link
Author

Inge72 commented Oct 29, 2015

We are running embedded Jetty (version 9.2.10.v20150310) with Jersey 2.22.1 and Jackson 2.6.3.

I could try to do some debugging, but I am not familiar with the swagger-jaxrs code, could you give me some hints for where in the code I should start looking? Where to set breakpoints?

@olensmar
Copy link
Contributor

sure - https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/Reader.java#L336 is where the ApiOperation extensions should be picked up when scanning your jaxrs resource - try putting one there to see if you hit it when generating the swagger definition

thanks for your help!

@Inge72
Copy link
Author

Inge72 commented Oct 29, 2015

I think I have found the problem. I have a filter defined, and the operation is cloned before the filter is executed. The vendorExtensions are not copied during this clone.

https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-core/src/main/java/io/swagger/core/filter/SpecFilter.java#L116

@olensmar
Copy link
Contributor

awesome - let me fix that right away... can you give the branch a try afterwards?

@Inge72
Copy link
Author

Inge72 commented Oct 29, 2015

I have to leave now, but I can do that tomorrow.

@olensmar
Copy link
Contributor

@Inge72
Copy link
Author

Inge72 commented Oct 30, 2015

It's working fine now :-)

@olensmar
Copy link
Contributor

awesome - thanks for confirming - i'll submit a PR for this

@webron
Copy link
Contributor

webron commented Dec 11, 2015

Fixed in #1529.

@webron webron closed this as completed Dec 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants