GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge branch 'master' into bump-reflections-version · JavaFramesSource/swagger-core@eef121d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • modules
    • swagger-annotations
      • pom.xml
    • swagger-core
      • pom.xml
      • src
        • main/java/io/swagger/jackson
          • ModelResolver.java
        • test/java/io/swagger
          • NumericFormatTest.java
          • jackson
            • ImmutablesGenerationTest.java
            • ModelResolverTest.java
            • SimpleGenerationTest.java
            • package-info.java
    • swagger-hibernate-validations
      • pom.xml
    • swagger-jaxrs
      • pom.xml
      • src
        • main/java/io/swagger/jaxrs/config
          • BeanConfig.java
        • test/java
          • io/swagger
            • BeanConfigTest.java
          • org/myles/project/resources
            • ResourceInPackageC.java
    • swagger-jersey-jaxrs
      • pom.xml
    • swagger-jersey2-jaxrs
      • pom.xml
    • swagger-models
      • pom.xml
      • src
        • main/java/io/swagger/models
          • ComposedModel.java
          • License.java
          • ModelImpl.java
          • Swagger.java
          • Tag.java
        • test/java/io/swagger
          • PojosTest.java
    • swagger-mule
      • pom.xml
    • swagger-servlet
      • pom.xml
      • src
        • main/java/io/swagger/servlet/extensions
          • ServletReaderExtension.java
        • test/java/io/swagger/servlet
          • ReaderTest.java
          • extensions
            • PathGetterTest.java
  • pom.xml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎modules/swagger-annotations/pom.xml‎

Copy file name to clipboardExpand all lines: modules/swagger-annotations/pom.xml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<parent>
44
<groupId>io.swagger</groupId>
55
<artifactId>swagger-project</artifactId>
6-
<version>1.5.13</version>
6+
<version>1.5.14-SNAPSHOT</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<groupId>io.swagger</groupId>
1111
<artifactId>swagger-annotations</artifactId>
12-
<version>1.5.13</version>
12+
<version>1.5.14-SNAPSHOT</version>
1313
<packaging>bundle</packaging>
1414
<name>swagger-annotations</name>
1515
<build>
Collapse file

‎modules/swagger-core/pom.xml‎

Copy file name to clipboardExpand all lines: modules/swagger-core/pom.xml
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>io.swagger</groupId>
55
<artifactId>swagger-project</artifactId>
6-
<version>1.5.13</version>
6+
<version>1.5.14-SNAPSHOT</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
@@ -129,6 +129,12 @@
129129
<artifactId>validation-api</artifactId>
130130
<version>${validation-api-version}</version>
131131
</dependency>
132+
<dependency>
133+
<groupId>org.immutables</groupId>
134+
<artifactId>value</artifactId>
135+
<version>2.4.4</version>
136+
<scope>test</scope>
137+
</dependency>
132138
<dependency>
133139
<groupId>org.testng</groupId>
134140
<artifactId>testng</artifactId>
Collapse file

‎modules/swagger-core/src/main/java/io/swagger/jackson/ModelResolver.java‎

Copy file name to clipboardExpand all lines: modules/swagger-core/src/main/java/io/swagger/jackson/ModelResolver.java
+32-8Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.fasterxml.jackson.databind.ObjectMapper;
1414
import com.fasterxml.jackson.databind.PropertyMetadata;
1515
import com.fasterxml.jackson.databind.SerializationFeature;
16+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
1617
import com.fasterxml.jackson.databind.introspect.Annotated;
1718
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
1819
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
@@ -55,6 +56,7 @@
5556
import javax.xml.bind.annotation.XmlAccessorType;
5657
import javax.xml.bind.annotation.XmlElement;
5758
import javax.xml.bind.annotation.XmlRootElement;
59+
import javax.xml.bind.annotation.XmlSchema;
5860
import java.lang.annotation.Annotation;
5961
import java.lang.reflect.Type;
6062
import java.math.BigDecimal;
@@ -211,7 +213,7 @@ public Model resolve(JavaType type, ModelConverterContext context, Iterator<Mode
211213
return null;
212214
}
213215

214-
final BeanDescription beanDesc = _mapper.getSerializationConfig().introspect(type);
216+
BeanDescription beanDesc = _mapper.getSerializationConfig().introspect(type);
215217
// Couple of possibilities for defining
216218
String name = _typeName(type, beanDesc);
217219

@@ -258,6 +260,12 @@ public Model resolve(JavaType type, ModelConverterContext context, Iterator<Mode
258260
context.resolve(type.getContentType());
259261
return null;
260262
}
263+
264+
final ApiModel apiModel = beanDesc.getClassAnnotations().get(ApiModel.class);
265+
if (apiModel != null && StringUtils.isNotEmpty(apiModel.reference())) {
266+
model.setReference(apiModel.reference());
267+
}
268+
261269
// if XmlRootElement annotation, construct an Xml object and attach it to the model
262270
XmlRootElement rootAnnotation = beanDesc.getClassAnnotations().get(XmlRootElement.class);
263271
if (rootAnnotation != null && !"".equals(rootAnnotation.name()) && !"##default".equals(rootAnnotation.name())) {
@@ -266,24 +274,37 @@ public Model resolve(JavaType type, ModelConverterContext context, Iterator<Mode
266274
if (rootAnnotation.namespace() != null && !"".equals(rootAnnotation.namespace()) && !"##default".equals(rootAnnotation.namespace())) {
267275
xml.namespace(rootAnnotation.namespace());
268276
}
277+
else {
278+
// If namespace was not given in the annotation, look for it in package-info
279+
Package pkg = type.getRawClass().getPackage();
280+
if(pkg != null) {
281+
XmlSchema xmlSchma = pkg.getAnnotation(XmlSchema.class);
282+
if(xmlSchma != null) {
283+
xml.namespace(xmlSchma.namespace());
284+
}
285+
}
286+
}
269287
model.xml(xml);
270288
}
271289
final XmlAccessorType xmlAccessorTypeAnnotation = beanDesc.getClassAnnotations().get(XmlAccessorType.class);
272290

291+
//If JsonSerialize(as=...) is specified then use that bean to figure out all the json-like bits
292+
JsonSerialize jasonSerialize = beanDesc.getClassAnnotations().get(JsonSerialize.class);
293+
if (jasonSerialize != null) {
294+
if (jasonSerialize.as() != null) {
295+
JavaType asType = _mapper.constructType(jasonSerialize.as());
296+
beanDesc = _mapper.getSerializationConfig().introspect(asType);
297+
}
298+
}
299+
273300
// see if @JsonIgnoreProperties exist
274301
Set<String> propertiesToIgnore = new HashSet<String>();
275302
JsonIgnoreProperties ignoreProperties = beanDesc.getClassAnnotations().get(JsonIgnoreProperties.class);
276303
if (ignoreProperties != null) {
277304
propertiesToIgnore.addAll(Arrays.asList(ignoreProperties.value()));
278305
}
279306

280-
final ApiModel apiModel = beanDesc.getClassAnnotations().get(ApiModel.class);
281307
String disc = (apiModel == null) ? "" : apiModel.discriminator();
282-
283-
if (apiModel != null && StringUtils.isNotEmpty(apiModel.reference())) {
284-
model.setReference(apiModel.reference());
285-
}
286-
287308
if (disc.isEmpty()) {
288309
// longer method would involve AnnotationIntrospector.findTypeResolver(...) but:
289310
JsonTypeInfo typeInfo = beanDesc.getClassAnnotations().get(JsonTypeInfo.class);
@@ -605,7 +626,10 @@ protected boolean ignore(final Annotated member, final XmlAccessorType xmlAccess
605626

606627
private void handleUnwrapped(List<Property> props, Model innerModel, String prefix, String suffix) {
607628
if (StringUtils.isBlank(suffix) && StringUtils.isBlank(prefix)) {
608-
props.addAll(innerModel.getProperties().values());
629+
Map<String, Property> innerProps = innerModel.getProperties();
630+
if (innerProps != null) {
631+
props.addAll(innerProps.values());
632+
}
609633
} else {
610634
if (prefix == null) {
611635
prefix = "";
Collapse file

‎modules/swagger-core/src/test/java/io/swagger/NumericFormatTest.java‎

Copy file name to clipboardExpand all lines: modules/swagger-core/src/test/java/io/swagger/NumericFormatTest.java
+39-36Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,27 @@
1515
import static org.testng.Assert.assertEquals;
1616

1717
public class NumericFormatTest {
18+
19+
private static final String NEWLINE = System.getProperty("line.separator");
20+
1821
@Test
1922
public void testFormatOfInteger() {
2023
final Map<String, Model> models = ModelConverters.getInstance().readAll(ModelWithIntegerFields.class);
2124
assertEquals(models.size(), 1);
2225

2326
String json = Json.pretty(models);
2427
assertEquals(json,
25-
"{\n" +
26-
" \"ModelWithIntegerFields\" : {\n" +
27-
" \"type\" : \"object\",\n" +
28-
" \"properties\" : {\n" +
29-
" \"id\" : {\n" +
30-
" \"type\" : \"integer\",\n" +
31-
" \"format\" : \"int32\",\n" +
32-
" \"minimum\" : 3\n" +
33-
" }\n" +
34-
" }\n" +
35-
" }\n" +
28+
"{" + NEWLINE +
29+
" \"ModelWithIntegerFields\" : {" + NEWLINE +
30+
" \"type\" : \"object\"," + NEWLINE +
31+
" \"properties\" : {" + NEWLINE +
32+
" \"id\" : {" + NEWLINE +
33+
" \"type\" : \"integer\"," + NEWLINE +
34+
" \"format\" : \"int32\"," + NEWLINE +
35+
" \"minimum\" : 3" + NEWLINE +
36+
" }" + NEWLINE +
37+
" }" + NEWLINE +
38+
" }" + NEWLINE +
3639
"}");
3740
}
3841

@@ -43,18 +46,18 @@ public void testFormatOfDecimal() {
4346

4447
String json = Json.pretty(models);
4548
assertEquals(json,
46-
"{\n" +
47-
" \"ModelWithDecimalFields\" : {\n" +
48-
" \"type\" : \"object\",\n" +
49-
" \"properties\" : {\n" +
50-
" \"id\" : {\n" +
51-
" \"type\" : \"number\",\n" +
52-
" \"format\" : \"double\",\n" +
53-
" \"minimum\" : 3.3,\n" +
54-
" \"exclusiveMinimum\" : false\n" +
55-
" }\n" +
56-
" }\n" +
57-
" }\n" +
49+
"{" + NEWLINE +
50+
" \"ModelWithDecimalFields\" : {" + NEWLINE +
51+
" \"type\" : \"object\"," + NEWLINE +
52+
" \"properties\" : {" + NEWLINE +
53+
" \"id\" : {" + NEWLINE +
54+
" \"type\" : \"number\"," + NEWLINE +
55+
" \"format\" : \"double\"," + NEWLINE +
56+
" \"minimum\" : 3.3," + NEWLINE +
57+
" \"exclusiveMinimum\" : false" + NEWLINE +
58+
" }" + NEWLINE +
59+
" }" + NEWLINE +
60+
" }" + NEWLINE +
5861
"}");
5962
}
6063

@@ -66,19 +69,19 @@ public void testFormatOfBigDecimal() {
6669
String json = Json.pretty(models);
6770

6871
assertEquals(json,
69-
"{\n" +
70-
" \"ModelWithoutScientificFields\" : {\n" +
71-
" \"type\" : \"object\",\n" +
72-
" \"properties\" : {\n" +
73-
" \"id\" : {\n" +
74-
" \"type\" : \"number\",\n" +
75-
" \"minimum\" : -9999999999999999.99,\n" +
76-
" \"maximum\" : 9999999999999999.99,\n" +
77-
" \"exclusiveMinimum\" : false,\n" +
78-
" \"exclusiveMaximum\" : false\n" +
79-
" }\n" +
80-
" }\n" +
81-
" }\n" +
72+
"{" + NEWLINE +
73+
" \"ModelWithoutScientificFields\" : {" + NEWLINE +
74+
" \"type\" : \"object\"," + NEWLINE +
75+
" \"properties\" : {" + NEWLINE +
76+
" \"id\" : {" + NEWLINE +
77+
" \"type\" : \"number\"," + NEWLINE +
78+
" \"minimum\" : -9999999999999999.99," + NEWLINE +
79+
" \"maximum\" : 9999999999999999.99," + NEWLINE +
80+
" \"exclusiveMinimum\" : false," + NEWLINE +
81+
" \"exclusiveMaximum\" : false" + NEWLINE +
82+
" }" + NEWLINE +
83+
" }" + NEWLINE +
84+
" }" + NEWLINE +
8285
"}");
8386

8487
}
Collapse file

‎modules/swagger-core/src/test/java/io/swagger/jackson/ImmutablesGenerationTest.java‎

Copy file name to clipboard
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package io.swagger.jackson;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
5+
import io.swagger.converter.ModelConverterContextImpl;
6+
import io.swagger.models.Model;
7+
import io.swagger.models.properties.Property;
8+
import org.immutables.value.Value;
9+
import org.testng.annotations.Test;
10+
11+
import java.util.Iterator;
12+
import java.util.Map;
13+
14+
import static org.testng.Assert.assertEquals;
15+
16+
public class ImmutablesGenerationTest extends SwaggerTestBase {
17+
private final ModelResolver modelResolver = new ModelResolver(new ObjectMapper());
18+
private final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
19+
20+
@Test
21+
public void testImmutables() {
22+
final Model model = context.resolve(TestWidget.class);
23+
final Map<String, Property> props = model.getProperties();
24+
assertEquals(props.size(), 2);
25+
26+
Iterator<Property> it = props.values().iterator();
27+
Property prop;
28+
29+
prop = it.next();
30+
assertEquals(prop.getName(), "wibble");
31+
prop = it.next();
32+
assertEquals(prop.getName(), "wobble");
33+
}
34+
35+
@Value.Immutable
36+
@JsonSerialize(as=ImmutableTestWidget.class)
37+
public interface TestWidget {
38+
public String wibble();
39+
public String wobble();
40+
}
41+
}
Collapse file

‎modules/swagger-core/src/test/java/io/swagger/jackson/ModelResolverTest.java‎

Copy file name to clipboard
+54Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package io.swagger.jackson;
2+
3+
import com.fasterxml.jackson.databind.JavaType;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import io.swagger.converter.ModelConverterContextImpl;
6+
import io.swagger.models.Link;
7+
import io.swagger.models.Model;
8+
import io.swagger.models.ModelImpl;
9+
import io.swagger.models.Xml;
10+
import org.testng.annotations.DataProvider;
11+
import org.testng.annotations.Test;
12+
13+
import javax.xml.bind.annotation.XmlRootElement;
14+
15+
import static org.testng.Assert.*;
16+
17+
public class ModelResolverTest extends SwaggerTestBase {
18+
19+
@Test(dataProvider = "testXmlNamespaceData")
20+
public void testXmlNamespace(Class clazz, String name, String namespace) throws Exception {
21+
final ObjectMapper mapper = mapper();
22+
final ModelResolver modelResolver = new ModelResolver(mapper);
23+
final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
24+
25+
final JavaType javaType = mapper.constructType(clazz);
26+
27+
final Model model = modelResolver.resolve(javaType, context, null);
28+
29+
assertTrue(model instanceof ModelImpl);
30+
31+
final Xml xml = ((ModelImpl) model).getXml();
32+
assertNotNull(xml);
33+
assertEquals(xml.getName(), name);
34+
assertEquals(xml.getNamespace(), namespace);
35+
}
36+
37+
@DataProvider
38+
private Object[][] testXmlNamespaceData() {
39+
return new Object[][]{
40+
{Link.class, "link", null},
41+
{TypeWithNamespace.class, "TypeWithNamespace", "http://io.swagger/jackson"},
42+
{TypeWithoutNamespace.class, "TypeWithOutNamespace", "http://io.swagger/jackson/package"}
43+
};
44+
}
45+
46+
@XmlRootElement(name = "TypeWithNamespace", namespace = "http://io.swagger/jackson")
47+
public static class TypeWithNamespace {
48+
}
49+
50+
@XmlRootElement(name = "TypeWithOutNamespace")
51+
public static class TypeWithoutNamespace {
52+
}
53+
54+
}
Collapse file

‎modules/swagger-core/src/test/java/io/swagger/jackson/SimpleGenerationTest.java‎

Copy file name to clipboardExpand all lines: modules/swagger-core/src/test/java/io/swagger/jackson/SimpleGenerationTest.java
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
1111
import com.fasterxml.jackson.databind.ObjectMapper;
1212

13+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
14+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
1315
import io.swagger.annotations.ApiModel;
1416
import io.swagger.annotations.ApiModelProperty;
1517
import io.swagger.converter.ModelConverterContextImpl;
@@ -117,6 +119,38 @@ public void testComplex() throws Exception {
117119
assertEquals(props.size(), 6);
118120
}
119121

122+
@Test
123+
public void testNotBeanlike() throws Exception {
124+
final Model model = context.resolve(NotBeanlike.class);
125+
final Map<String, Property> props = model.getProperties();
126+
assertEquals(props.size(), 1);
127+
128+
final Property prop = props.values().iterator().next();
129+
assertEquals(prop.getName(), "notGetter");
130+
}
131+
132+
static class NotBeanlike {
133+
@JsonProperty("notGetter")
134+
public String notGetter() {return "Not a getter";}
135+
}
136+
137+
@Test
138+
public void testEvenLessBeanlike() throws Exception {
139+
final Model model = context.resolve(EvenLessBeanlike.class);
140+
final Map<String, Property> props = model.getProperties();
141+
assertEquals(props.size(), 1);
142+
143+
final Property prop = props.values().iterator().next();
144+
assertEquals(prop.getName(), "notGetter");
145+
}
146+
147+
@JsonSerialize(as = NotBeanlike.class)
148+
@JsonDeserialize(as = NotBeanlike.class)
149+
static interface EvenLessBeanlike {
150+
public String notGetter();
151+
}
152+
153+
120154
/*
121155
/**********************************************************
122156
/* Test methods
Collapse file

‎modules/swagger-core/src/test/java/io/swagger/jackson/package-info.java‎

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@javax.xml.bind.annotation.XmlSchema(namespace = "http://io.swagger/jackson/package")
2+
package io.swagger.jackson;
Collapse file

‎modules/swagger-hibernate-validations/pom.xml‎

Copy file name to clipboardExpand all lines: modules/swagger-hibernate-validations/pom.xml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<parent>
55
<groupId>io.swagger</groupId>
66
<artifactId>swagger-project</artifactId>
7-
<version>1.5.13</version>
7+
<version>1.5.14-SNAPSHOT</version>
88
<relativePath>../..</relativePath>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<groupId>io.swagger</groupId>
1212
<artifactId>swagger-hibernate-validations</artifactId>
1313
<packaging>jar</packaging>
14-
<version>1.5.13</version>
14+
<version>1.5.14-SNAPSHOT</version>
1515
<name>swagger-hibernate-validations</name>
1616
<build>
1717
<sourceDirectory>src/main/java</sourceDirectory>

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.