Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

@ApiModelProperty(hidden = true) doesn't work #189

Open
aturner-tvpage opened this issue Mar 25, 2019 · 3 comments
Open

@ApiModelProperty(hidden = true) doesn't work #189

aturner-tvpage opened this issue Mar 25, 2019 · 3 comments

Comments

@aturner-tvpage
Copy link

aturner-tvpage commented Mar 25, 2019

When generating this model, the hidden parameter doesn't appear to be respected:

case class User(id: Long, firstName: String, lastName: String, email: String,
               // TODO this doesn't appear to be working for some reason
                @ApiModelProperty(hidden = true) password: String,
                lastLoginTimestamp: Option[Timestamp], createdTimestamp: Timestamp, modifiedTimestamp: Timestamp)```

Results in an API spec for User:

"User" : {
  "type" : "object",
  "required" : [ "createdTimestamp", "data", "email", "firstName", "id", "lastName", "modifiedTimestamp" ],
  "properties" : {
    "id" : {
      "type" : "integer",
      "format" : "int64"
    },
    "firstName" : {
      "type" : "string"
    },
    "lastName" : {
      "type" : "string"
    },
    "email" : {
      "type" : "string"
    },
    "password" : {
      "type" : "string"
    },
    "lastLoginTimestamp" : {
      "type" : "string",
      "format": "date-time"
    },
    "createdTimestamp" : {
      "type" : "string",
      "format" : "date-time"
    },
    "modifiedTimestamp" : {
      "type" : "string",
      "format" : "date-time"
    }
  }

I would expect the password attribute to be hidden.
@jongunter
Copy link

I'm experiencing this, too.

Got around it by creating a filter. Extend AbstractSpecFilter and override isParamAllowed so it filters out parameters named password. Not ideal, but it works.

@dsnkostic
Copy link

Not sure if these are connected (in implementation sense), but the similar issue is with the query parameters hidden flag (@ApiParam) (#206). I haven't looked at the code, but my assumption (based on query parameters behavior) is that hidden is actually respected, but some other logic might be regenerating that property again.

@gaeljw
Copy link

gaeljw commented Jul 11, 2020

I just discovered that this is a known "issue" documented here: https://github.com/swagger-api/swagger-scala-module#how-to-hide-model-properties

You should be able to use something like this:

import io.swagger.annotations.{ApiModel, ApiModelProperty}
import scala.annotation.meta.{field,getter}

@ApiModel
case class Foo(
  @ApiModelProperty(value = "This will not be hidden!", hidden = true)
  stillVisible: Int,

  @(ApiModelProperty @field @getter)(value = "A hidden property", hidden = true)
  actuallyHidden: String
)

It's a bit ugly but it's related to the underlying Java reflection stuff

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants