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

refs #3904 - annotations support for @JsonValue types #3930

Merged
merged 1 commit into from
Apr 17, 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 @@ -376,6 +376,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
.resolveAsRef(annotatedType.isResolveAsRef())
.jsonViewAnnotation(annotatedType.getJsonViewAnnotation())
.propertyName(annotatedType.getPropertyName())
.ctxAnnotations(annotatedType.getCtxAnnotations())
.skipOverride(true);
return context.resolve(aType);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.swagger.v3.core.resolving;

import com.fasterxml.jackson.annotation.JsonValue;
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.oas.models.media.Schema;
import org.testng.annotations.Test;

public class Ticket3904Test extends SwaggerTestBase {

@Test
public void testJsonValueSchemaAnnotation() throws Exception {

final ModelResolver modelResolver = new ModelResolver(mapper());

ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);

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

SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "Request:\n" +
" type: object\n" +
" properties:\n" +
" id:\n" +
" type: string\n" +
" description: Description of ID.");

}

static class Request {
@io.swagger.v3.oas.annotations.media.Schema(description = "Description of ID.")
private Id id;

public Id getId() {
return id;
}

public void setId(Id id) {
this.id = id;
}
}
static class Id {
private String value;

@JsonValue
public String getValue() {
return value;
}
}
}
1 change: 1 addition & 0 deletions modules/swagger-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
testImplementation "org.eclipse.jetty:jetty-proxy:${project.jettyVersion}"
testImplementation "org.apache.httpcomponents:httpclient:4.5.13"
testImplementation "commons-codec:commons-codec:1.15"
testImplementation "commons-io:commons-io:2.7"
testImplementation "org.apache.commons:commons-compress:1.20"
}

Expand Down
2 changes: 1 addition & 1 deletion modules/swagger-project-jakarta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@
<guava-version>30.1-jre</guava-version>
<ant-version>1.10.9</ant-version>
<commons-lang-version>3.7</commons-lang-version>
<commons-io-version>2.6</commons-io-version>
<commons-io-version>2.7</commons-io-version>
<slf4j-version>1.7.25</slf4j-version>
<jetty-version>9.4.39.v20210325</jetty-version>
<testng-version>7.3.0</testng-version>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@
<guava-version>30.1-jre</guava-version>
<ant-version>1.10.9</ant-version>
<commons-lang-version>3.7</commons-lang-version>
<commons-io-version>2.6</commons-io-version>
<commons-io-version>2.7</commons-io-version>
<slf4j-version>1.7.25</slf4j-version>
<jetty-version>9.4.39.v20210325</jetty-version>
<testng-version>7.3.0</testng-version>
Expand Down