Search in sources :

Example 1 with Sample

use of org.apache.knox.gateway.service.definition.Sample in project knox by apache.

the class ServiceModel method getSamples.

@XmlElement(name = "sample")
@XmlElementWrapper(name = "samples")
public List<Sample> getSamples() {
    final List<Sample> samples = new ArrayList<>();
    if (serviceMetadata != null && serviceMetadata.getSamples() != null) {
        serviceMetadata.getSamples().forEach(sample -> {
            final Sample resolvedSample = new Sample();
            resolvedSample.setDescription(sample.getDescription());
            if (StringUtils.isNotBlank(sample.getValue())) {
                resolvedSample.setValue(sample.getValue());
            } else {
                final String method = StringUtils.isBlank(sample.getMethod()) ? "GET" : sample.getMethod();
                resolvedSample.setValue(String.format(Locale.ROOT, CURL_SAMPLE_TEMPLATE, method, getServiceUrl(), sample.getPath()));
            }
            samples.add(resolvedSample);
        });
    }
    return samples;
}
Also used : Sample(org.apache.knox.gateway.service.definition.Sample) ArrayList(java.util.ArrayList) XmlElement(javax.xml.bind.annotation.XmlElement) XmlElementWrapper(javax.xml.bind.annotation.XmlElementWrapper)

Aggregations

ArrayList (java.util.ArrayList)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 XmlElementWrapper (javax.xml.bind.annotation.XmlElementWrapper)1 Sample (org.apache.knox.gateway.service.definition.Sample)1