Skip to content

Commit d9dca92

Browse files
committed
merged from master
1 parent 69d9028 commit d9dca92

File tree

119 files changed

+4970
-6446
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+4970
-6446
lines changed

README.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,26 @@
22

33
[![Build Status](https://travis-ci.org/wordnik/swagger-core.png)](https://travis-ci.org/wordnik/swagger-core)
44

5-
The goal of Swagger is to define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via Swagger, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interfaces have done for lower-level programming, Swager removes the guesswork in calling the service.
5+
## [See the Wiki!](https://github.com/wordnik/swagger-core/wiki)
6+
The [github wiki](https://github.com/wordnik/swagger-core/wiki) contains documentation, samples, etc. Start there
67

7-
Swagger-core is the Java/Scala implementation of Swagger. It supports *JAX-RS*, *plain Servlets*, and *Play Framework*.
8-
9-
Check out [Swagger-Spec](https://github.com/wordnik/swagger-spec) for additional information about the Swagger project, including additional libraries with support for SpringMVC, other languages and more.
10-
11-
## See the Wiki!
12-
The [github wiki](https://github.com/wordnik/swagger-core/wiki) contains documentation, samples, etc. Start there.
13-
14-
## Support
15-
The following methods are available to obtain support for Swagger:
16-
17-
- [The Swagger Google Group](https://groups.google.com/forum/#!forum/swagger-swaggersocket) - This would normally be your first stop to get support for Swagger. Here you can find previously asked question, and ask new ones. When asking a question, please provide as much information as you can regarding the environment you use (development language, library, versions.
18-
- The [Issues tab](https://github.com/wordnik/swagger-core/issues?state=open) - Please open feature requests and bugs here. If you're not sure you encountered a bug, or if it's a general usage question, please use the Google Group mentioned above.
19-
- IRC! you can find us on [freenode](irc://irc.freenode.net) in the channel #Swagger. You can talk with us directly there.
8+
## Where to get help!
9+
Search the [swagger google groups](https://groups.google.com/forum/#!forum/swagger-swaggersocket) for previously
10+
asked questions. Join #swagger on irc.freenode.net to talk to interesting human beings. And if you find a bug,
11+
file it in github:
2012

13+
* [Swagger core + server integrations](https://github.com/wordnik/swagger-core/issues) issues
14+
* [Swagger UI](https://github.com/wordnik/swagger-ui/issues)
15+
* [Swagger codegen](https://github.com/wordnik/swagger-codegen/issues)
2116

2217
## Get started with Swagger!
2318
See the guide on [getting started with swagger](https://github.com/wordnik/swagger-core/wiki/Adding-Swagger-to-your-API) to get started with adding swagger to your API.
2419

2520

2621
## Overview
2722
This is a project to build the swagger-core library, which is required for the Wordnik
28-
implementation of the Swagger spec. For more information about Wordnik's APIs, please
23+
implementation of the Swagger spec. You can find out more about both the spec and the
24+
framework at http://swagger.wordnik.com. For more information about Wordnik's APIs, please
2925
visit http://developer.wordnik.com.
3026

3127

@@ -40,7 +36,9 @@ You need the following installed and available in your $PATH:
4036

4137
<li>- Apache maven 3.0.3 or greater (http://maven.apache.org/)
4238

43-
### To build from source (currently 1.3.2)
39+
<li>- Scala 2.9.1-1 [available here](http://www.scala-lang.org). Note that 2.9.1 has a defect which causes problems with Jax-RS
40+
41+
### To build from source (currently 1.3.0)
4442
```
4543
# first time building locally
4644
mvn -N
@@ -64,6 +62,12 @@ There are a number of sample apps in the `samples` folder:
6462

6563
[scala-jaxrs](https://github.com/wordnik/swagger-core/tree/master/samples/scala-jaxrs/README.md) Scala-based swagger server with JAX-RS
6664

65+
[java-alt-resource-listing](https://github.com/wordnik/swagger-core/tree/master/samples/java-alt-resource-listing/README.md)
66+
Scala-based swagger server with JAX-RS with an alternate resource listing scheme
67+
68+
[scala-alt-resource-listing](https://github.com/wordnik/swagger-core/tree/master/samples/scala-alt-resource-listing/README.md)
69+
Scala-based swagger server with JAX-RS with an alternate resource listing scheme
70+
6771
[scala-jaxrs-apm](https://github.com/wordnik/swagger-core/tree/master/samples/scala-jaxrs-apm/README.md)
6872
Scala-based swagger server using wordnik-oss utils for Application Performance Monitoring (APM)
6973

@@ -82,6 +86,8 @@ And the [Play2](http://playframework.org) samples:
8286

8387
[scala-play2](https://github.com/wordnik/swagger-core/tree/master/samples/scala-play2) Scala-based Play2 sample app
8488

89+
[scala-play2-no-format](https://github.com/wordnik/swagger-core/tree/master/samples/scala-play2-no-format) Scala-based Play2 sample app without the .{format} in resource listing
90+
8591
To run the Play2 sample apps:
8692

8793
```
@@ -93,7 +99,7 @@ play run
9399
License
94100
-------
95101

96-
Copyright 2014 Reverb Technologies, Inc.
102+
Copyright 2013 Reverb Technologies, Inc.
97103

98104
Licensed under the Apache License, Version 2.0 (the "License");
99105
you may not use this file except in compliance with the License.

modules/swagger-annotations/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<parent>
44
<groupId>com.wordnik</groupId>
55
<artifactId>swagger-project_2.10</artifactId>
6-
<version>1.3.2</version>
6+
<version>1.3.4</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<groupId>com.wordnik</groupId>
1111
<artifactId>swagger-annotations</artifactId>
12-
<version>1.3.2</version>
12+
<version>1.3.4</version>
1313
<packaging>jar</packaging>
1414
<name>swagger-annotations</name>
1515

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-annotations/src/main/java/com/wordnik/swagger/annotations/ApiOperation.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@
6767

6868
/** authorizations required by this Api */
6969
Authorization[] authorizations() default @Authorization("");
70+
71+
/**
72+
* Allows an operation to be marked as hidden
73+
*/
74+
boolean hidden() default false;
7075
}

modules/swagger-core/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<parent>
33
<groupId>com.wordnik</groupId>
44
<artifactId>swagger-project_2.10</artifactId>
5-
<version>1.3.2</version>
5+
<version>1.3.4</version>
66
<relativePath>../..</relativePath>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<groupId>com.wordnik</groupId>
1010
<artifactId>swagger-core_2.10</artifactId>
1111
<packaging>jar</packaging>
1212
<name>swagger-core</name>
13-
<version>1.3.2</version>
13+
<version>1.3.4</version>
1414
<build>
1515
<sourceDirectory>src/main/java</sourceDirectory>
1616
<defaultGoal>install</defaultGoal>
@@ -80,19 +80,19 @@
8080
<dependency>
8181
<groupId>org.json4s</groupId>
8282
<artifactId>json4s-ext_2.10</artifactId>
83-
<version>3.2.4</version>
83+
<version>${json4s-version}</version>
8484
<scope>compile</scope>
8585
</dependency>
8686
<dependency>
8787
<groupId>org.json4s</groupId>
8888
<artifactId>json4s-native_2.10</artifactId>
89-
<version>3.2.4</version>
89+
<version>${json4s-version}</version>
9090
<scope>compile</scope>
9191
</dependency>
9292
<dependency>
9393
<groupId>org.json4s</groupId>
9494
<artifactId>json4s-jackson_2.10</artifactId>
95-
<version>3.2.4</version>
95+
<version>${json4s-version}</version>
9696
<scope>compile</scope>
9797
</dependency>
9898
<dependency>

modules/swagger-core/src/main/resources/logback.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</layout>
77
</appender>
88
<logger name="com.wordnik" level="ERROR"/>
9-
<root level="debug">
9+
<root level="error">
1010
<appender-ref ref="STDOUT" />
1111
</root>
1212
</configuration>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class JodaDateTimeConverter extends ModelConverter with BaseConverter {
1717
// }
1818
//
1919
// (note the keys are lowercase when matching)
20-
override def typeMap = Map("datetime" -> "Date")
20+
override def typeMap = Map("datetime" -> "Date", "xmlgregoriancalendar" -> "Date")
2121

2222
// don't expand DateTime models
23-
override def ignoredClasses: Set[String] = Set("org.joda.time.DateTime")
23+
override def ignoredClasses: Set[String] = Set("org.joda.time.DateTime", "javax.xml.datatype.XMLGregorianCalendar")
2424
}

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
5353
def parseField(field: Field) = {
5454
LOGGER.debug("processing field " + field)
5555
val returnClass = field.getDeclaringClass
56-
parsePropertyAnnotations(returnClass, field.getName, field.getAnnotations, field.getGenericType, field.getType)
56+
parsePropertyAnnotations(returnClass, field.getName, field.getAnnotations, field.getGenericType, field.getType, true)
5757
}
5858

5959
def parseMethod(method: Method) = {
60-
if (method.getParameterTypes == null || method.getParameterTypes.length == 0) {
60+
if ((method.getParameterTypes == null || method.getParameterTypes.length == 0) && !method.isBridge) {
6161
LOGGER.debug("processing method " + method)
6262
val returnClass = method.getReturnType
63-
parsePropertyAnnotations(returnClass, method.getName, method.getAnnotations, method.getGenericReturnType, method.getReturnType)
63+
parsePropertyAnnotations(returnClass, method.getName, method.getAnnotations, method.getGenericReturnType, method.getReturnType, false)
6464
}
6565
}
6666

@@ -78,8 +78,11 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
7878
}
7979
}
8080

81-
def parsePropertyAnnotations(returnClass: Class[_], propertyName: String, propertyAnnotations: Array[Annotation], genericReturnType: Type, returnType: Type): Any = {
82-
val e = extractGetterProperty(propertyName)
81+
def parsePropertyAnnotations(returnClass: Class[_], propertyName: String, propertyAnnotations: Array[Annotation], genericReturnType: Type, returnType: Type, isField: Boolean): Any = {
82+
val e = isField match {
83+
case true => (propertyName, false)
84+
case false => extractGetterProperty(propertyName)
85+
}
8386
var originalName = e._1
8487
var isGetter = e._2
8588

@@ -103,26 +106,32 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
103106
var isXmlElement = processedAnnotations("isXmlElement").asInstanceOf[Boolean]
104107
val isDocumented = processedAnnotations("isDocumented").asInstanceOf[Boolean]
105108
var allowableValues = {
106-
if(returnClass.isEnum)
109+
if(returnClass.isEnum)
107110
Some(AllowableListValues((for(v <- returnClass.getEnumConstants) yield v.toString).toList))
108111
else
109112
processedAnnotations("allowableValues").asInstanceOf[Option[AllowableValues]]
110113
}
111114

112115
try {
113-
val fieldAnnotations = getDeclaredField(this.cls, name).getAnnotations()
114-
var propAnnoOutput = processAnnotations(name, fieldAnnotations)
116+
val fieldAnnotations = getDeclaredField(this.cls, originalName).getAnnotations()
117+
var propAnnoOutput = processAnnotations(originalName, fieldAnnotations)
115118
var propPosition = propAnnoOutput("position").asInstanceOf[Int]
116119

117-
if(allowableValues == None)
120+
if (name == null || name.equals(originalName)) {
121+
name = propAnnoOutput("name").asInstanceOf[String]
122+
}
123+
124+
if(allowableValues == None)
118125
allowableValues = propAnnoOutput("allowableValues").asInstanceOf[Option[AllowableValues]]
119-
if(description == None && propAnnoOutput.contains("description") && propAnnoOutput("description") != null)
126+
if(description == None && propAnnoOutput.contains("description") && propAnnoOutput("description") != null)
120127
description = Some(propAnnoOutput("description").asInstanceOf[String])
121128
if(propPosition != 0) position = propAnnoOutput("position").asInstanceOf[Int]
122129
if(required == false) required = propAnnoOutput("required").asInstanceOf[Boolean]
123130
isFieldExists = true
124131
if (!isTransient) isTransient = propAnnoOutput("isTransient").asInstanceOf[Boolean]
125132
if (!isXmlElement) isXmlElement = propAnnoOutput("isXmlElement").asInstanceOf[Boolean]
133+
134+
if (name == null) name = originalName
126135
isJsonProperty = propAnnoOutput("isJsonProperty").asInstanceOf[Boolean]
127136
} catch {
128137
//this means there is no field declared to look for field level annotations.
@@ -226,6 +235,7 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
226235
isDocumented = true
227236
allowableValues = Some(toAllowableValues(e.allowableValues))
228237
paramAccess = readString(e.access)
238+
isTransient = e.hidden
229239
}
230240
case e: XmlAttribute => {
231241
updatedName = readString(e.name, name, "##default")
@@ -235,7 +245,6 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
235245
}
236246
case e: XmlElement => {
237247
updatedName = readString(e.name, name, "##default")
238-
// updatedName = readString(name, name)
239248
defaultValue = readString(e.defaultValue, defaultValue, "\u0000")
240249

241250
required = e.required
@@ -253,7 +262,7 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
253262
updatedName = readString(e.value, name)
254263
isJsonProperty = true
255264
}
256-
case _ =>
265+
case _ =>
257266
}
258267
}
259268
val output = new HashMap[String, Any]
@@ -349,10 +358,6 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
349358
val parameterizedType = genericReturnType.asInstanceOf[java.lang.reflect.ParameterizedType]
350359
val valueType = parameterizedType.getActualTypeArguments.head
351360
"Set[" + getDataType(valueType, valueType, isSimple) + "]"
352-
} else if (TypeUtil.isParameterizedCollection(genericReturnType)) {
353-
val parameterizedType = genericReturnType.asInstanceOf[java.lang.reflect.ParameterizedType]
354-
val valueType = parameterizedType.getActualTypeArguments.head
355-
"Array[" + getDataType(valueType, valueType, isSimple) + "]"
356361
} else if (TypeUtil.isParameterizedMap(genericReturnType)) {
357362
val parameterizedType = genericReturnType.asInstanceOf[java.lang.reflect.ParameterizedType]
358363
val typeArgs = parameterizedType.getActualTypeArguments
@@ -402,7 +407,7 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
402407
else hostClass.getName
403408
} else if (xmlRootElement != null) {
404409
if ("##default".equals(xmlRootElement.name())) {
405-
if (isSimple) hostClass.getSimpleName
410+
if (isSimple) hostClass.getSimpleName
406411
else hostClass.getName
407412
} else {
408413
if (isSimple) readString(xmlRootElement.name())

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ class SwaggerSchemaConverter
2828
}
2929
}
3030
newProperties ++= properties
31-
val p = (for((key, value) <- newProperties.reverse)
31+
val p = (for((key, value) <- newProperties)
3232
yield (value.position, key, value)
3333
).toList
3434

3535
val sortedProperties = new LinkedHashMap[String, ModelProperty]()
36-
p.sortWith(_._1 <= _._1).foreach(e => sortedProperties += e._2 -> e._3)
36+
p.sortWith(_._1 < _._1).foreach(e => sortedProperties += e._2 -> e._3)
3737

3838
val parent = Option(cls.getAnnotation(classOf[ApiModel])) match {
3939
case Some(e) => Some(e.parent.getName)
@@ -46,7 +46,7 @@ class SwaggerSchemaConverter
4646
apiAnno.discriminator
4747
else if(cls.getAnnotation(classOf[JsonTypeInfo]) != null)
4848
cls.getAnnotation(classOf[JsonTypeInfo]).property
49-
else ""
49+
else ""
5050
}
5151
if(v != null && v != "") Some(v)
5252
else None

modules/swagger-core/src/main/scala/com/wordnik/swagger/core/util/TypeUtil.scala

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,7 @@ object TypeUtil {
6262
def isParameterizedList(gt: Type): Boolean = {
6363
if (classOf[ParameterizedType].isAssignableFrom(gt.getClass)) {
6464
val tp = gt.asInstanceOf[ParameterizedType].getRawType
65-
(tp == classOf[java.util.List[_]] || tp == classOf[scala.List[_]] || tp == classOf[Seq[_]])
66-
}
67-
else false
68-
}
69-
70-
def isParameterizedCollection(gt: Type): Boolean = {
71-
if (classOf[ParameterizedType].isAssignableFrom(gt.getClass)) {
72-
val tp = gt.asInstanceOf[ParameterizedType].getRawType
73-
(tp == classOf[java.util.Collection[_]])
65+
(tp == classOf[java.util.List[_]] || tp == classOf[scala.List[_]] || tp == classOf[Seq[_]])
7466
}
7567
else false
7668
}

0 commit comments

Comments
 (0)