Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump jetty version, exclude json-smart (#3918, #3919, #3920). Partial JsonTypeInfo.As.WRAPPER_OBJECT support (#2884, #2862) #3921

Merged
merged 2 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
}

resolveDiscriminatorProperty(type, context, model);
model = resolveWrapping(type, context, model);

return model;
}
Expand Down Expand Up @@ -1770,6 +1771,32 @@ protected void resolveDiscriminatorProperty(JavaType type, ModelConverterContext
}
}

/*
TODO partial implementation supporting WRAPPER_OBJECT with JsonTypeInfo.Id.CLASS and JsonTypeInfo.Id.NAME

Also note that JsonTypeInfo on interfaces are not considered as multiple interfaces might have conflicting
annotations, although Jackson seems to apply them if present on an interface
*/
protected Schema resolveWrapping(JavaType type, ModelConverterContext context, Schema model) {
// add JsonTypeInfo.property if not member of bean
JsonTypeInfo typeInfo = type.getRawClass().getDeclaredAnnotation(JsonTypeInfo.class);
if (typeInfo != null) {
JsonTypeInfo.Id id = typeInfo.use();
JsonTypeInfo.As as = typeInfo.include();
if (JsonTypeInfo.As.WRAPPER_OBJECT.equals(as)) {
String name = model.getName();
if (JsonTypeInfo.Id.CLASS.equals(id)) {
name = type.getRawClass().getName();
}
Schema wrapperSchema = new ObjectSchema();
wrapperSchema.name(model.getName());
wrapperSchema.addProperties(name, model);
return wrapperSchema;
}
}
return model;
}

protected Discriminator resolveDiscriminator(JavaType type, ModelConverterContext context) {

io.swagger.v3.oas.annotations.media.Schema declaredSchemaAnnotation = AnnotationsUtils.getSchemaDeclaredAnnotation(type.getRawClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void maintainPropertyNames() {
public void serializeParameterizedType() {
final Map<String, Schema> schemas = readAll(Employee.class);

final Schema employee = (Schema) schemas.get("employee");
final Schema employee = (Schema) schemas.get("employee").getProperties().get("employee");
final Map<String, Schema> props = employee.getProperties();
final Iterator<String> et = props.keySet().iterator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ public void testSubType() throws Exception {

SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "Ticket2862Model:\n" +
" type: object\n" +
" properties:\n" +
" Ticket2862Model:\n" +
" type: object\n" +
"Ticket2862ModelImpl:\n" +
" type: string\n" +
" allOf:\n" +
" - $ref: '#/components/schemas/Ticket2862Model'\n" +
" enum:\n" +
" - VALUE1\n" +
" - VALUE2");
" - VALUE2\n");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.swagger.v3.core.resolving;

import io.swagger.v3.core.converter.AnnotatedType;
import io.swagger.v3.core.converter.ModelConverterContextImpl;
import io.swagger.v3.core.jackson.ModelResolver;
import io.swagger.v3.core.matchers.SerializationMatchers;
import io.swagger.v3.core.resolving.resources.Ticket2884Model;
import io.swagger.v3.core.resolving.resources.Ticket2884ModelClass;
import io.swagger.v3.oas.models.media.Schema;
import org.testng.annotations.Test;

public class Ticket2884Test extends SwaggerTestBase {
@Test
public void test2884() throws Exception {
final ModelResolver modelResolver = new ModelResolver(mapper());

ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);

Ticket2884ModelClass a = new Ticket2884ModelClass();

Schema model = context
.resolve(new AnnotatedType(Ticket2884Model.class));

SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "Ticket2884Model:\n" +
" type: object\n" +
" properties:\n" +
" Ticket2884Model:\n" +
" type: object");

context = new ModelConverterContextImpl(modelResolver);
model = context
.resolve(new AnnotatedType(Ticket2884ModelClass.class));

SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "Ticket2884ModelClass:\n" +
" type: object\n" +
" properties:\n" +
" Ticket2884ModelClass:\n" +
" type: object\n" +
" properties:\n" +
" bar:\n" +
" type: string\n" +
" foo:\n" +
" type: array\n" +
" items:\n" +
" type: string\n");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.swagger.v3.core.jackson.ModelResolver;
import io.swagger.v3.core.matchers.SerializationMatchers;
import io.swagger.v3.core.resolving.resources.TestObject2915;
import io.swagger.v3.core.resolving.resources.Ticket2862Model;
import io.swagger.v3.oas.models.media.Schema;
import org.testng.annotations.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.swagger.v3.core.resolving.resources;

@com.fasterxml.jackson.annotation.JsonTypeInfo(
use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME,
include = com.fasterxml.jackson.annotation.JsonTypeInfo.As.WRAPPER_OBJECT)
public interface Ticket2884Model {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.swagger.v3.core.resolving.resources;

import java.util.List;

@com.fasterxml.jackson.annotation.JsonTypeInfo(
use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME,
include = com.fasterxml.jackson.annotation.JsonTypeInfo.As.WRAPPER_OBJECT)
public class Ticket2884ModelClass {

public String bar;
public List<String> foo;

}
19 changes: 9 additions & 10 deletions modules/swagger-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ dependencies {
implementation 'org.apache.commons:commons-lang3:3.7'

testImplementation gradleTestKit()
testImplementation 'com.github.tomakehurst:wiremock:2.27.2'
testImplementation('com.github.tomakehurst:wiremock:2.27.2') {
exclude group: 'com.jayway.jsonpath', module: 'json-path'
exclude group: 'org.eclipse.jetty', module: 'jetty-server'
exclude group: 'org.eclipse.jetty', module: 'jetty-servlet'
exclude group: 'org.eclipse.jetty', module: 'jetty-servlets'
exclude group: 'org.eclipse.jetty', module: 'jetty-webapp'
exclude group: 'org.eclipse.jetty', module: 'jetty-proxy'
exclude group: 'commons-codec', module: 'commons-codec'
}
testImplementation 'javax.servlet:javax.servlet-api:3.1.0'
testImplementation 'com.google.guava:guava:30.1-jre'
testImplementation 'javax.ws.rs:javax.ws.rs-api:2.1'
Expand All @@ -39,15 +47,6 @@ dependencies {
testImplementation "org.apache.httpcomponents:httpclient:4.5.13"
testImplementation "commons-codec:commons-codec:1.15"
testImplementation "org.apache.commons:commons-compress:1.20"

testImplementation('com.github.tomakehurst:wiremock:2.27.2') {
exclude group: 'org.eclipse.jetty', module: 'jetty-server'
exclude group: 'org.eclipse.jetty', module: 'jetty-servlet'
exclude group: 'org.eclipse.jetty', module: 'jetty-servlets'
exclude group: 'org.eclipse.jetty', module: 'jetty-webapp'
exclude group: 'org.eclipse.jetty', module: 'jetty-proxy'
exclude group: 'commons-codec', module: 'commons-codec'
}
}

// * * * * * * * * * * * *
Expand Down
2 changes: 1 addition & 1 deletion modules/swagger-gradle-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=2.1.8-SNAPSHOT
jettyVersion=9.4.35.v20201120
jettyVersion=9.4.39.v20210325
39 changes: 21 additions & 18 deletions modules/swagger-jaxrs2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe-plugin-version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<jetty.port>${jetty.port}</jetty.port>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
Expand All @@ -83,6 +65,9 @@
<httpConnector><port>${jetty.port}</port></httpConnector>
<stopKey>a</stopKey>
<stopPort>${jetty.port.stop}</stopPort>
<supportedPackagings>
<supportedPackaging>jar</supportedPackaging>
</supportedPackagings>
<useTestScope>true</useTestScope>
<webAppSourceDirectory>${project.basedir}/src/test/webapp</webAppSourceDirectory>
</configuration>
Expand All @@ -106,6 +91,24 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe-plugin-version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<jetty.port>${jetty.port}</jetty.port>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-eclipse-transformer-maven-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion modules/swagger-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.version>3.6.3</maven.version>
<junit.version>4.13.1</junit.version>
<wiremock-jetty-version>9.4.35.v20201120</wiremock-jetty-version>
<wiremock-jetty-version>9.4.39.v20210325</wiremock-jetty-version>
<commons-compress-version>1.20</commons-compress-version>
</properties>
</project>
2 changes: 1 addition & 1 deletion modules/swagger-project-jakarta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@
<commons-lang-version>3.7</commons-lang-version>
<commons-io-version>2.6</commons-io-version>
<slf4j-version>1.7.25</slf4j-version>
<jetty-version>9.4.9.v20180320</jetty-version>
<jetty-version>9.4.39.v20210325</jetty-version>
<testng-version>7.3.0</testng-version>
<mockito-version>2.28.2</mockito-version>
<rest-assured-version>4.3.2</rest-assured-version>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@
<commons-lang-version>3.7</commons-lang-version>
<commons-io-version>2.6</commons-io-version>
<slf4j-version>1.7.25</slf4j-version>
<jetty-version>9.4.9.v20180320</jetty-version>
<jetty-version>9.4.39.v20210325</jetty-version>
<testng-version>7.3.0</testng-version>
<mockito-version>2.28.2</mockito-version>
<rest-assured-version>4.3.2</rest-assured-version>
Expand Down