use of org.eclipse.microprofile.openapi.models.examples.Example in project empoa by OpenAPITools.
the class AbstractElementSerializerTest method testExampleWithReferenceToJson.
@Test
public void testExampleWithReferenceToJson() throws Exception {
Example example = OASElement.createExample().ref("#/components/examples/SomeExample").description("Some description");
String json = convertToJson(example);
assertThatJson(json).isEqualTo("" + "{" + " \"$ref\": \"#/components/examples/SomeExample\"" + "}");
}
use of org.eclipse.microprofile.openapi.models.examples.Example in project empoa by OpenAPITools.
the class AbstractElementSerializerTest method testEmptyExampleToJson.
@Test
public void testEmptyExampleToJson() throws Exception {
Example example = OASFactory.createExample();
String json = convertToJson(example);
assertThatJson(json).isEqualTo("{}");
}
use of org.eclipse.microprofile.openapi.models.examples.Example in project smallrye-open-api by smallrye.
the class ExampleReader method readExample.
/**
* Reads a Example annotation into a model.
*
* @param context the scanning context
* @param annotationInstance {@literal @}ExampleObject annotation
* @return Example model
*/
private static Example readExample(final AnnotationScannerContext context, final AnnotationInstance annotationInstance) {
if (annotationInstance == null) {
return null;
}
IoLogging.logger.singleAnnotation("@ExampleObject");
Example example = new ExampleImpl();
example.setRef(JandexUtil.refValue(annotationInstance, JandexUtil.RefType.EXAMPLE));
example.setSummary(JandexUtil.stringValue(annotationInstance, ExampleConstant.PROP_SUMMARY));
example.setDescription(JandexUtil.stringValue(annotationInstance, ExampleConstant.PROP_DESCRIPTION));
example.setValue(parseValue(context, JandexUtil.stringValue(annotationInstance, ExampleConstant.PROP_VALUE)));
example.setExternalValue(JandexUtil.stringValue(annotationInstance, ExampleConstant.PROP_EXTERNAL_VALUE));
return example;
}
use of org.eclipse.microprofile.openapi.models.examples.Example in project smallrye-open-api by smallrye.
the class ExampleReader method readExample.
/**
* Reads a {@link Example} OpenAPI node.
*
* @param node the example json node
* @return Example model
*/
private static Example readExample(final JsonNode node) {
if (node == null || !node.isObject()) {
return null;
}
IoLogging.logger.singleJsonNode("ExampleObject");
Example example = new ExampleImpl();
example.setRef(JsonUtil.stringProperty(node, Referenceable.PROP_$REF));
example.setSummary(JsonUtil.stringProperty(node, ExampleConstant.PROP_SUMMARY));
example.setDescription(JsonUtil.stringProperty(node, ExampleConstant.PROP_DESCRIPTION));
example.setValue(readObject(node.get(ExampleConstant.PROP_VALUE)));
example.setExternalValue(JsonUtil.stringProperty(node, ExampleConstant.PROP_EXTERNAL_VALUE));
ExtensionReader.readExtensions(node, example);
return example;
}
use of org.eclipse.microprofile.openapi.models.examples.Example in project smallrye-open-api by smallrye.
the class ExampleReader method readExamples.
/**
* Reads a map of Example annotations.
*
* @param context the scanning context
* @param annotationValue map of {@literal @}ExampleObject annotations
* @return Map of Example model
*/
public static Map<String, Example> readExamples(final AnnotationScannerContext context, final AnnotationValue annotationValue) {
if (annotationValue == null) {
return null;
}
IoLogging.logger.annotationsMap("@ExampleObject");
Map<String, Example> examples = new LinkedHashMap<>();
AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
for (AnnotationInstance nested : nestedArray) {
String name = JandexUtil.stringValue(nested, ExampleConstant.PROP_NAME);
if (name == null && JandexUtil.isRef(nested)) {
name = JandexUtil.nameFromRef(nested);
}
if (name != null) {
examples.put(name, readExample(context, nested));
}
}
return examples;
}
Aggregations