Skip to content

Commit fb2d4b9

Browse files
committed
fix for #475, allows fields to be hidden with a single annotation
1 parent 6a6508c commit fb2d4b9

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

modules/swagger-annotations/src/main/java/com/wordnik/swagger/annotations/ApiModelProperty.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,9 @@
6868
* ordering, you should specify property order to keep models consistent across different VM implementations and versions.
6969
*/
7070
int position() default 0;
71+
72+
/**
73+
* Allows a model property to be marked as hidden in the swagger model definition
74+
*/
75+
boolean hidden() default false;
7176
}

modules/swagger-core/src/main/scala/com/wordnik/swagger/converter/ModelPropertyParser.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
226226
isDocumented = true
227227
allowableValues = Some(toAllowableValues(e.allowableValues))
228228
paramAccess = readString(e.access)
229+
isTransient = e.hidden
229230
}
230231
case e: XmlAttribute => {
231232
updatedName = readString(e.name, name, "##default")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package converter
2+
3+
import converter.models._
4+
5+
import com.wordnik.swagger.converter._
6+
import com.wordnik.swagger.core.util._
7+
import com.wordnik.swagger.model._
8+
import com.wordnik.swagger.annotations._
9+
10+
import java.util.Date
11+
12+
import scala.reflect.BeanProperty
13+
14+
import org.junit.runner.RunWith
15+
import org.scalatest.junit.JUnitRunner
16+
import org.scalatest.FlatSpec
17+
import org.scalatest.matchers.ShouldMatchers
18+
19+
@RunWith(classOf[JUnitRunner])
20+
class HiddenFieldTest extends FlatSpec with ShouldMatchers {
21+
it should "ignore a hidden field" in {
22+
val model = ModelConverters.read(classOf[ModelWithHiddenFields]).getOrElse(fail("no model found"))
23+
model.id should be ("ModelWithHiddenFields")
24+
model.properties.size should be (2)
25+
26+
val idValue = model.properties("id")
27+
idValue.`type` should be ("long")
28+
idValue.required should be (true)
29+
30+
val nameValue = model.properties("name")
31+
nameValue.`type` should be ("string")
32+
nameValue.required should be (true)
33+
}
34+
}
35+
36+
class ModelWithHiddenFields {
37+
@BeanProperty
38+
@ApiModelProperty(required=true)
39+
var id: Long = _
40+
41+
@BeanProperty
42+
@ApiModelProperty(required=true, hidden=false)
43+
var name: String = _
44+
45+
@BeanProperty
46+
@ApiModelProperty(hidden=true)
47+
var password: String = _
48+
}

0 commit comments

Comments
 (0)