use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class XmlModelTest method deserializeModel.
@Test(description = "it should deserialize a model")
public void deserializeModel() throws IOException {
final String yaml = "---\n" + "type: \"object\"\n" + "properties:\n" + " id:\n" + " type: \"string\"\n" + " xml:\n" + " attribute: true\n" + " name:\n" + " type: \"string\"\n" + " xml:\n" + " name: \"renamed\"\n" + " list:\n" + " type: \"array\"\n" + " items:\n" + " type: \"string\"\n" + " wrappedList:\n" + " type: \"array\"\n" + " xml:\n" + " name: \"wrappedListItems\"\n" + " wrapped: true\n" + " items:\n" + " type: \"string\"\n" + " forcedElement:\n" + " type: \"array\"\n" + " items:\n" + " type: \"string\"\n" + "xml:\n" + " name: \"rootName\"";
final Schema model = Yaml.mapper().readValue(yaml, Schema.class);
final Schema wrappedList = (Schema) model.getProperties().get("wrappedList");
assertNotNull(wrappedList);
assertNotNull(wrappedList.getXml());
assertEquals(wrappedList.getXml().getName(), "wrappedListItems");
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class XMLInfoTest method testReadingXmlAccessorTypeNone.
@Test
public void testReadingXmlAccessorTypeNone() throws Exception {
final ModelConverter mr = modelResolver();
final Schema model = mr.resolve(new AnnotatedType(XmlDecoratedBeanXmlAccessorNone.class), new ModelConverterContextImpl(mr), null);
final XML xml = model.getXml();
assertNotNull(xml);
assertEquals(xml.getName(), "xmlDecoratedBean");
final Schema property = (Schema) model.getProperties().get("a");
assertNotNull(property);
assertNull(model.getProperties().get("b"));
assertNotNull(model.getProperties().get("c"));
assertNotNull(model.getProperties().get("d"));
assertNotNull(model.getProperties().get("e"));
assertNotNull(model.getProperties().get("f"));
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class ComplexPropertyTest method testOuterBean.
@Test
public void testOuterBean() throws Exception {
final ModelResolver modelResolver = modelResolver();
final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
final Schema model = context.resolve(new AnnotatedType(OuterBean.class));
assertNotNull(model);
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class ModelResolver method _addEnumProps.
protected void _addEnumProps(Class<?> propClass, Schema property) {
final boolean useIndex = _mapper.isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX);
final boolean useToString = _mapper.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
Optional<Method> jsonValueMethod = Arrays.stream(propClass.getMethods()).filter(m -> m.isAnnotationPresent(JsonValue.class)).filter(m -> m.getAnnotation(JsonValue.class).value()).findFirst();
@SuppressWarnings("unchecked") Class<Enum<?>> enumClass = (Class<Enum<?>>) propClass;
Enum<?>[] enumConstants = enumClass.getEnumConstants();
if (enumConstants != null) {
String[] enumValues = _intr.findEnumValues(propClass, enumConstants, new String[enumConstants.length]);
for (Enum<?> en : enumConstants) {
String n;
String enumValue = enumValues[en.ordinal()];
String s = jsonValueMethod.flatMap(m -> ReflectionUtils.safeInvoke(m, en)).map(Object::toString).orElse(null);
if (s != null) {
n = s;
} else if (enumValue != null) {
n = enumValue;
} else if (useIndex) {
n = String.valueOf(en.ordinal());
} else if (useToString) {
n = en.toString();
} else {
n = _intr.findEnumValue(en);
}
if (property instanceof StringSchema) {
StringSchema sp = (StringSchema) property;
sp.addEnumItem(n);
}
}
}
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class ModelResolver method resolveExternalDocumentation.
protected ExternalDocumentation resolveExternalDocumentation(Annotated a, Annotation[] annotations, io.swagger.v3.oas.annotations.media.Schema schema) {
ExternalDocumentation external = null;
if (a != null) {
io.swagger.v3.oas.annotations.ExternalDocumentation externalDocumentation = a.getAnnotation(io.swagger.v3.oas.annotations.ExternalDocumentation.class);
external = resolveExternalDocumentation(externalDocumentation);
}
if (external == null) {
if (schema != null) {
external = resolveExternalDocumentation(schema.externalDocs());
}
}
return external;
}
Aggregations