Search in sources :

Example 1 with Oas20Example

use of io.apicurio.datamodels.openapi.v2.models.Oas20Example in project apicurio-data-models by Apicurio.

the class Oas20DataModelWriter method visitExample.

/**
 * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitExample(io.apicurio.datamodels.core.models.common.IExample)
 */
@Override
public void visitExample(IExample node) {
    Oas20Example example20 = (Oas20Example) node;
    Object parent = this.lookupParentJson(example20);
    Object json = JsonCompat.objectNode();
    List<String> contentTypes = example20.getExampleContentTypes();
    contentTypes.forEach(ct -> {
        Object example = example20.getExample(ct);
        JsonCompat.setProperty(json, ct, example);
    });
    JsonCompat.setProperty(parent, Constants.PROP_EXAMPLES, json);
    this.updateIndex(example20, json);
}
Also used : Oas20Example(io.apicurio.datamodels.openapi.v2.models.Oas20Example)

Example 2 with Oas20Example

use of io.apicurio.datamodels.openapi.v2.models.Oas20Example in project apicurio-data-models by Apicurio.

the class OasUnmatchedExampleTypeRule method visitExample.

/**
 * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitExample(io.apicurio.datamodels.core.models.common.IExample)
 */
@Override
public void visitExample(IExample node) {
    Oas20Example example20 = (Oas20Example) node;
    Oas20Document doc = (Oas20Document) example20.ownerDocument();
    List<String> produces = doc.produces;
    Oas20Operation operation = (Oas20Operation) findParentOperation(example20);
    if (isDefined(operation)) {
        if (hasValue(operation.produces)) {
            produces = operation.produces;
        }
        if (!hasValue(produces)) {
            produces = new ArrayList<>();
        }
        List<String> ctypes = example20.getExampleContentTypes();
        for (String ct : ctypes) {
            this.reportIfInvalid(produces.indexOf(ct) != -1, example20, Constants.PROP_PRODUCES, map("contentType", ct));
        }
    }
}
Also used : Oas20Example(io.apicurio.datamodels.openapi.v2.models.Oas20Example) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20Operation(io.apicurio.datamodels.openapi.v2.models.Oas20Operation)

Aggregations

Oas20Example (io.apicurio.datamodels.openapi.v2.models.Oas20Example)2 Oas20Document (io.apicurio.datamodels.openapi.v2.models.Oas20Document)1 Oas20Operation (io.apicurio.datamodels.openapi.v2.models.Oas20Operation)1