Skip to content

Commit

Permalink
refs #3904 - annotations support for @JsonValue types
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Apr 17, 2021
1 parent 3a8524c commit c1b16e6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
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

0 comments on commit c1b16e6

Please sign in to comment.