use of org.eclipse.microprofile.openapi.models.examples.Example in project wildfly-swarm by wildfly-swarm.
the class OpenApiParser method readExamples.
/**
* Reads the {@link Example} OpenAPI nodes.
* @param node
*/
private Map<String, Example> readExamples(JsonNode node) {
if (node == null || !node.isObject()) {
return null;
}
Map<String, Example> models = new LinkedHashMap<>();
for (Iterator<String> fieldNames = node.fieldNames(); fieldNames.hasNext(); ) {
String fieldName = fieldNames.next();
JsonNode childNode = node.get(fieldName);
models.put(fieldName, readExample(childNode));
}
return models;
}
use of org.eclipse.microprofile.openapi.models.examples.Example in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method readExample.
/**
* Reads a Example annotation into a model.
* @param annotation
*/
private Example readExample(AnnotationInstance annotation) {
if (annotation == null) {
return null;
}
LOG.debug("Processing a single @ExampleObject annotation.");
Example example = new ExampleImpl();
example.setSummary(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_SUMMARY));
example.setDescription(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_DESCRIPTION));
example.setValue(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_VALUE));
example.setExternalValue(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_EXTERNAL_VALUE));
example.setRef(JandexUtil.refValue(annotation, RefType.Example));
return example;
}
use of org.eclipse.microprofile.openapi.models.examples.Example in project wildfly-swarm by wildfly-swarm.
the class FilterUtil method filterExamples.
/**
* Filters the given models.
* @param filter
* @param models
*/
private static void filterExamples(OASFilter filter, Map<String, Example> models) {
if (models == null) {
return;
}
Collection<String> keys = new ArrayList<>(models.keySet());
for (String key : keys) {
Example model = models.get(key);
filterExample(filter, model);
}
}
use of org.eclipse.microprofile.openapi.models.examples.Example in project Payara by payara.
the class ParameterImpl method merge.
public static void merge(Parameter from, Parameter to, boolean override, ApiContext context) {
if (from == null) {
return;
}
if (from.getRef() != null && !from.getRef().isEmpty()) {
applyReference(to, from.getRef());
return;
}
to.setName(mergeProperty(to.getName(), from.getName(), override));
to.setDescription(mergeProperty(to.getDescription(), from.getDescription(), override));
if (from.getIn() != null) {
to.setIn(mergeProperty(to.getIn(), from.getIn(), override));
}
to.setRequired(mergeProperty(to.getRequired(), from.getRequired(), override));
to.setDeprecated(mergeProperty(to.getDeprecated(), from.getDeprecated(), override));
to.setAllowEmptyValue(mergeProperty(to.getAllowEmptyValue(), from.getAllowEmptyValue(), override));
if (from.getStyle() != null) {
to.setStyle(mergeProperty(to.getStyle(), from.getStyle(), override));
}
if (from.getExplode() != null) {
to.setExplode(mergeProperty(to.getExplode(), false, override));
}
to.setAllowReserved(mergeProperty(to.getAllowReserved(), from.getAllowReserved(), override));
if (from.getSchema() != null) {
if (to.getSchema() == null) {
to.setSchema(new SchemaImpl());
}
SchemaImpl.merge(from.getSchema(), to.getSchema(), override, context);
}
to.setExample(mergeProperty(to.getExample(), from.getExample(), override));
if (from.getExamples() != null) {
for (String exampleName : from.getExamples().keySet()) {
if (exampleName != null) {
Example example = new ExampleImpl();
ExampleImpl.merge(from.getExamples().get(exampleName), example, override);
to.addExample(exampleName, example);
}
}
}
if (from instanceof ParameterImpl) {
ParameterImpl fromImpl = (ParameterImpl) from;
if (fromImpl.getContents() != null) {
if (to.getContent() == null) {
to.setContent(new ContentImpl());
}
for (ContentImpl content : fromImpl.getContents()) {
ContentImpl.merge(content, to.getContent(), override, context);
}
}
}
if (from.getContent() != null) {
if (to.getContent() == null) {
to.setContent(new ContentImpl());
}
ContentImpl.merge((ContentImpl) from.getContent(), to.getContent(), override, context);
}
}
use of org.eclipse.microprofile.openapi.models.examples.Example in project Payara by payara.
the class ExampleImpl method createInstance.
public static Example createInstance(AnnotationModel annotation, ApiContext context) {
Example from = new ExampleImpl();
from.setSummary(annotation.getValue("summary", String.class));
from.setDescription(annotation.getValue("description", String.class));
from.setValue(annotation.getValue("value", Object.class));
from.setExternalValue(annotation.getValue("externalValue", String.class));
String ref = annotation.getValue("ref", String.class);
if (ref != null && !ref.isEmpty()) {
from.setRef(ref);
}
return from;
}
Aggregations