Skip to content

Commit 33424a2

Browse files
committed
Merge branch 'azhawkes-master' into develop
Conflicts: modules/swagger-oauth2-auth-server/src/main/scala/com/wordnik/swagger/auth/service/AuthService.scala modules/swagger-oauth2-auth-server/src/main/scala/com/wordnik/swagger/auth/service/TokenScope.java
2 parents 52d21ee + 0cd5aaf commit 33424a2

File tree

5 files changed

+109
-30
lines changed

5 files changed

+109
-30
lines changed

README.md

+17-23
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@
22

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

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
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.
76

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:
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.
1220

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)
1621

1722
## Get started with Swagger!
1823
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.
1924

2025

2126
## Overview
2227
This is a project to build the swagger-core library, which is required for the Wordnik
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
28+
implementation of the Swagger spec. For more information about Wordnik's APIs, please
2529
visit http://developer.wordnik.com.
2630

2731

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

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

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)
43+
### To build from source (currently 1.3.4)
4244
```
4345
# first time building locally
4446
mvn -N
@@ -62,12 +64,6 @@ There are a number of sample apps in the `samples` folder:
6264

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

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-
7167
[scala-jaxrs-apm](https://github.com/wordnik/swagger-core/tree/master/samples/scala-jaxrs-apm/README.md)
7268
Scala-based swagger server using wordnik-oss utils for Application Performance Monitoring (APM)
7369

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

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

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-
9185
To run the Play2 sample apps:
9286

9387
```
@@ -99,7 +93,7 @@ play run
9993
License
10094
-------
10195

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

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

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

+37-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.wordnik.swagger.core.{ SwaggerSpec, SwaggerTypes }
55
import com.wordnik.swagger.core.util.TypeUtil
66
import com.wordnik.swagger.annotations.ApiModelProperty
77

8-
import com.fasterxml.jackson.annotation.{JsonIgnore, JsonProperty}
8+
import com.fasterxml.jackson.annotation.{JsonIgnore, JsonProperty, JsonIgnoreProperties}
99

1010
import org.slf4j.LoggerFactory
1111

@@ -35,14 +35,33 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
3535
def parseRecursive(hostClass: Class[_]): Unit = {
3636
if(!hostClass.isEnum) {
3737
LOGGER.debug("processing class " + hostClass)
38+
39+
val ignoredProperties = parseIgnorePropertiesClassAnnotation(hostClass)
40+
3841
for (method <- hostClass.getDeclaredMethods) {
39-
if (Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers()))
40-
parseMethod(method)
42+
if (Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers())) {
43+
val (fieldName, getter) = extractGetterProperty(method.getName)
44+
45+
LOGGER.debug("field name for method " + method.getName + " is " + fieldName)
46+
47+
if (ignoredProperties.contains(fieldName)) {
48+
LOGGER.debug("ignoring property " + fieldName)
49+
} else {
50+
parseMethod(method)
51+
}
52+
}
4153
}
54+
4255
for (field <- hostClass.getDeclaredFields) {
43-
if (Modifier.isPublic(field.getModifiers()) && !Modifier.isStatic(field.getModifiers()))
44-
parseField(field)
56+
if (Modifier.isPublic(field.getModifiers()) && !Modifier.isStatic(field.getModifiers()) && !ignoredProperties.contains(field.getName)) {
57+
if (ignoredProperties.contains(field.getName)) {
58+
LOGGER.debug("ignoring property " + field.getName)
59+
} else {
60+
parseField(field)
61+
}
62+
}
4563
}
64+
4665
Option(hostClass.getSuperclass).map(parseRecursive(_))
4766
}
4867
else {
@@ -78,6 +97,19 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
7897
}
7998
}
8099

100+
def parseIgnorePropertiesClassAnnotation(returnClass: Class[_]) : Array[String] = {
101+
var ignoredProperties = Array[String]()
102+
val ignore = returnClass.getAnnotation(classOf[JsonIgnoreProperties])
103+
104+
if (ignore != null) {
105+
ignoredProperties = ignore.value
106+
107+
LOGGER.debug("found @JsonIgnoreProperties on " + returnClass + " with value(s) " + ignoredProperties.mkString(","))
108+
}
109+
110+
ignoredProperties
111+
}
112+
81113
def parsePropertyAnnotations(returnClass: Class[_], propertyName: String, propertyAnnotations: Array[Annotation], genericReturnType: Type, returnType: Type, isField: Boolean): Any = {
82114
val e = isField match {
83115
case true => (propertyName, false)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package converter
2+
3+
import models._
4+
5+
import com.wordnik.swagger.converter._
6+
7+
import com.wordnik.swagger.core.util._
8+
9+
import java.util.Date
10+
11+
import org.junit.runner.RunWith
12+
import org.scalatest.junit.JUnitRunner
13+
import org.scalatest.FlatSpec
14+
import org.scalatest.matchers.ShouldMatchers
15+
16+
@RunWith(classOf[JUnitRunner])
17+
class JsonIgnorePropertiesModelTest extends FlatSpec with ShouldMatchers {
18+
val models = ModelConverters.readAll(classOf[ModelWithIgnorePropertiesAnnotation])
19+
JsonSerializer.asJson(models) should be ("""[{"id":"ModelWithIgnorePropertiesAnnotation","properties":{"name":{"type":"string"},"favoriteAnimal":{"type":"string"}}}]""")
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package converter.models;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
5+
@JsonIgnoreProperties({"ignoredString", "middleName", "favoriteColor"})
6+
public class ModelWithIgnorePropertiesAnnotation {
7+
private String name, ignoredString;
8+
9+
public String favoriteColor;
10+
public String favoriteAnimal;
11+
12+
public String getName() {
13+
return name;
14+
}
15+
16+
public void setName(String name) {
17+
this.name = name;
18+
}
19+
20+
public String getIgnoredString() {
21+
return ignoredString;
22+
}
23+
24+
public void setIgnoredString(String ignoredString) {
25+
this.ignoredString = ignoredString;
26+
}
27+
28+
public String getMiddleName() {
29+
return "ignore middle name";
30+
}
31+
32+
public void setMiddleName(String name) {}
33+
}

modules/swagger-oauth2-auth-server/src/main/scala/com/wordnik/swagger/auth/service/TokenScope.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ public static void setUsername(String username) {
77
userThreadLocal.set(username);
88
}
99

10-
public static Long getUsername() {
11-
return (Long)userThreadLocal.get();
10+
public static String getUsername() {
11+
return (String)userThreadLocal.get();
1212
}
1313

1414
public static void unsetUsername() {

0 commit comments

Comments
 (0)