swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
http://swagger.io
Apache License 2.0
7.36k stars 2.17k forks source link

@JsonIgnore is not ignoring all getters #318

Closed jknova closed 10 years ago

jknova commented 10 years ago

I'm trying to ignore some fields in my model, but it still seems to be showing up in my swagger ui. I'm using swagger jaxrs:

  <groupId>com.wordnik</groupId>
  <artifactId>swagger-jersey-jaxrs_2.10</artifactId>
  <version>1.3.0</version>

and my code is:

public static class Person
{
    private String name = "hello world";

    @ApiModelProperty(value = "The name of the person", required=true)
    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    @JsonIgnore
    public String getMiddleName()
    {
        return "ignore middle name";
    }
}

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/people/{personId}")
@ApiOperation(value = "Find Person", response = Person.class)
public Response getPerson(
        @ApiParam(value = "ID of the Person to fetch", required = true)
        @PathParam("personId")
        String personId)
{
        return Response.ok().entity(new Person()).build();
}

In the Swagger UI, the "middleName" property is showing up in Person model even though I've set the JsonIgnore annotation. Am I doing something wrong here?

jknova commented 10 years ago

I added a fix to my own repo:

jknova/swagger-core@85ee010ced2d18a030b4f9f6f58e36cd8198c50b

Seems to be working...

rage-shadowman commented 10 years ago

If not for all the activity around swagger-ui I would assume this project must be dead since this is still broken 4 months later.

fehguy commented 10 years ago

@rage-shadowman ?

rage-shadowman commented 10 years ago

I'm just surprised that this issue is still present, even though there was a pull request to fix it 4 months ago.

fehguy commented 10 years ago

Pull requests with tests get priority, in general. Also when there are pieces changing, they won't be merged immediately.

rage-shadowman commented 10 years ago

PS - We do appreciate all the work you guys are doing, and I can clearly see a lot of activity and fast responses on the swagger-ui repo, so I know you guys are still working on this stuff. Thank you.

fehguy commented 10 years ago

fixed in the develop branch and in 1.3.2-SNAPSHOT in sonatype oss