Skip to content

Commit

Permalink
refs #4679 - fix @Schema#implementation resolving for OAS 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
micryc committed Aug 27, 2024
1 parent e6d3fa3 commit c37b72c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,9 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
!(a instanceof io.swagger.v3.oas.annotations.media.ArraySchema)) {
ctxAnnotations31List.add(a);
}
if ((ctxSchema != null) && (!ctxSchema.implementation().equals(Void.class) || StringUtils.isNotEmpty(ctxSchema.type()))) {
ctxAnnotations31List.add(a);
}
}
ctxAnnotation31 = ctxAnnotations31List.toArray(new Annotation[ctxAnnotations31List.size()]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.swagger.v3.core.resolving;

import io.swagger.v3.core.converter.ModelConverters;
import io.swagger.v3.core.matchers.SerializationMatchers;
import io.swagger.v3.core.util.Yaml;
import io.swagger.v3.core.util.Yaml31;
import io.swagger.v3.oas.annotations.media.Schema;
import org.testng.annotations.Test;

import java.util.Map;

public class Ticket4679Test extends SwaggerTestBase{

@Test(description = "Custom schema implementation in property overrides type value")
public void testCustomSchemaImplementation() {

String expectedYaml = "ModelWithCustomSchemaImplementationInProperty:\n" +
" properties:\n" +
" exampleField:\n" +
" type: integer\n" +
" format: int32\n" +
" secondExampleField:\n" +
" type: string\n";

Map<String, io.swagger.v3.oas.models.media.Schema> stringSchemaMap = ModelConverters.getInstance(true).readAll(ModelWithCustomSchemaImplementationInProperty.class);
SerializationMatchers.assertEqualsToYaml31(stringSchemaMap, expectedYaml);
}

static class ModelWithCustomSchemaImplementationInProperty {

@Schema(implementation = Integer.class)
private String exampleField;

@Schema(type = "string")
private Integer secondExampleField;

public String getExampleField() {
return exampleField;
}

public void setExampleField(String exampleField) {
this.exampleField = exampleField;
}

public Integer getSecondExampleField() {
return secondExampleField;
}

public void setSecondExampleField(Integer secondExampleField) {
this.secondExampleField = secondExampleField;
}


}
}

0 comments on commit c37b72c

Please sign in to comment.