Skip to content
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 @@ -552,16 +552,33 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
}

}
String propSchemaName = null;
io.swagger.v3.oas.annotations.media.Schema ctxSchema = AnnotationsUtils.getSchemaAnnotation(annotations);
if (AnnotationsUtils.hasSchemaAnnotation(ctxSchema)) {
if (!StringUtils.isBlank(ctxSchema.name())) {
propSchemaName = ctxSchema.name();
}
}
if (propSchemaName == null) {
io.swagger.v3.oas.annotations.media.ArraySchema ctxArraySchema = AnnotationsUtils.getArraySchemaAnnotation(annotations);
if (AnnotationsUtils.hasArrayAnnotation(ctxArraySchema)) {
if (AnnotationsUtils.hasSchemaAnnotation(ctxArraySchema.schema())) {
if (!StringUtils.isBlank(ctxArraySchema.schema().name())) {
propSchemaName = ctxArraySchema.schema().name();
}
}
}
}
if (StringUtils.isNotBlank(propSchemaName)) {
propName = propSchemaName;
}
Annotation propSchemaOrArray = AnnotationsUtils.mergeSchemaAnnotations(annotations, propType);
final io.swagger.v3.oas.annotations.media.Schema propResolvedSchemaAnnotation =
propSchemaOrArray == null ?
null :
propSchemaOrArray instanceof io.swagger.v3.oas.annotations.media.ArraySchema ?
((io.swagger.v3.oas.annotations.media.ArraySchema) propSchemaOrArray).schema() :
(io.swagger.v3.oas.annotations.media.Schema) propSchemaOrArray;
if (propResolvedSchemaAnnotation != null && !propResolvedSchemaAnnotation.name().isEmpty()) {
propName = propResolvedSchemaAnnotation.name();
}

io.swagger.v3.oas.annotations.media.Schema.AccessMode accessMode = resolveAccessMode(propDef, type, propResolvedSchemaAnnotation);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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.TestObject2915;
import io.swagger.v3.core.resolving.resources.Ticket2862Model;
import io.swagger.v3.oas.models.media.Schema;
import org.testng.annotations.Test;

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

final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);

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

SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "QuantitativeValue:\n" +
" required:\n" +
" - value\n" +
" type: object\n" +
" properties:\n" +
" value:\n" +
" type: number\n" +
" format: double\n" +
" unitText:\n" +
" type: string\n" +
" unitCode:\n" +
" type: string\n" +
" description: A combination of a value and associated unit\n" +
"TestObject2616:\n" +
" type: object\n" +
" properties:\n" +
" name:\n" +
" type: string\n" +
" perServing:\n" +
" $ref: '#/components/schemas/QuantitativeValue'\n" +
" per100Gram:\n" +
" $ref: '#/components/schemas/QuantitativeValue'\n" +
" description: Nutritional value specification");
}

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

import io.swagger.v3.oas.annotations.media.Schema;

import javax.validation.constraints.NotNull;
import java.io.Serializable;

@Schema(name = "TestObject2616", description = "Nutritional value specification")
public class TestObject2915 implements Serializable {
private final static long serialVersionUID = 1L;
private String name;

private QuantitativeValueDTO perServing;
private QuantitativeValueDTO per100Gram;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public QuantitativeValueDTO getPerServing() {
return perServing;
}

public void setPerServing(QuantitativeValueDTO perServing) {
this.perServing = perServing;
}

public QuantitativeValueDTO getPer100Gram() {
return per100Gram;
}

public void setPer100Gram(QuantitativeValueDTO per100Gram) {
this.per100Gram = per100Gram;
}

@Schema(name = "QuantitativeValue", description = "A combination of a value and associated unit")
public class QuantitativeValueDTO implements Serializable {

private final static long serialVersionUID = 1L;

@NotNull
private double value;

private String unitText;
private String unitCode;

public double getValue() {
return value;
}

public void setValue(double value) {
this.value = value;
}

public String getUnitText() {
return unitText;
}

public void setUnitText(String unitText) {
this.unitText = unitText;
}

public String getUnitCode() {
return unitCode;
}

public void setUnitCode(String unitCode) {
this.unitCode = unitCode;
}
}
}