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 5440c97
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 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;
}
}
}

0 comments on commit 5440c97

Please sign in to comment.