Search in sources :

Example 1 with Oas30Encoding

use of io.apicurio.datamodels.openapi.v3.models.Oas30Encoding in project apicurio-data-models by Apicurio.

the class Oas30DataModelReader method readEncoding.

/**
 * Reads an OAS 3.0 Encoding from the given js data.
 * @param json
 * @param node
 */
public void readEncoding(Object json, Oas30Encoding node) {
    String contentType = JsonCompat.consumePropertyString(json, Constants.PROP_CONTENT_TYPE);
    Object headers = JsonCompat.consumeProperty(json, Constants.PROP_HEADERS);
    String style = JsonCompat.consumePropertyString(json, Constants.PROP_STYLE);
    Boolean explode = JsonCompat.consumePropertyBoolean(json, Constants.PROP_EXPLODE);
    Boolean allowReserved = JsonCompat.consumePropertyBoolean(json, Constants.PROP_ALLOW_RESERVED);
    node.contentType = contentType;
    node.style = style;
    node.explode = explode;
    node.allowReserved = allowReserved;
    if (headers != null) {
        JsonCompat.keys(headers).forEach(name -> {
            Object header = JsonCompat.consumeProperty(headers, name);
            Oas30Header headerModel = node.createHeader(name);
            this.readHeader(header, headerModel);
            node.addHeader(name, headerModel);
        });
    }
    this.readExtensions(json, node);
    this.readExtraProperties(json, node);
}
Also used : Oas30Header(io.apicurio.datamodels.openapi.v3.models.Oas30Header)

Example 2 with Oas30Encoding

use of io.apicurio.datamodels.openapi.v3.models.Oas30Encoding in project apicurio-data-models by Apicurio.

the class Oas30DataModelReader method readMediaType.

/**
 * Reads an OAS 3.0 Media Type from the given js data.
 * @param json
 * @param node
 */
public void readMediaType(Object json, Oas30MediaType node) {
    Object schema = JsonCompat.consumeProperty(json, Constants.PROP_SCHEMA);
    Object example = JsonCompat.consumePropertyObject(json, Constants.PROP_EXAMPLE);
    Object examples = JsonCompat.consumeProperty(json, Constants.PROP_EXAMPLES);
    Object encodings = JsonCompat.consumeProperty(json, Constants.PROP_ENCODING);
    node.example = example;
    if (schema != null) {
        node.schema = node.createSchema();
        this.readSchema(schema, node.schema);
    }
    if (examples != null) {
        JsonCompat.keys(examples).forEach(name -> {
            Object exx = JsonCompat.consumeProperty(examples, name);
            Oas30Example exampleModel = (Oas30Example) node.createExample(name);
            this.readExample(exx, exampleModel);
            node.addExample(exampleModel);
        });
    }
    if (encodings != null) {
        JsonCompat.keys(encodings).forEach(name -> {
            Object encoding = JsonCompat.consumeProperty(encodings, name);
            Oas30Encoding encodingModel = node.createEncoding(name);
            this.readEncoding(encoding, encodingModel);
            node.addEncoding(name, encodingModel);
        });
    }
    this.readExtensions(json, node);
    this.readExtraProperties(json, node);
}
Also used : Oas30Example(io.apicurio.datamodels.openapi.v3.models.Oas30Example) Oas30Encoding(io.apicurio.datamodels.openapi.v3.models.Oas30Encoding)

Example 3 with Oas30Encoding

use of io.apicurio.datamodels.openapi.v3.models.Oas30Encoding in project apicurio-data-models by Apicurio.

the class OasAllowReservedNotAllowedRule method visitEncoding.

/**
 * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitEncoding(io.apicurio.datamodels.openapi.v3.models.Oas30Encoding)
 */
@Override
public void visitEncoding(Oas30Encoding node) {
    if (hasValue(node.allowReserved)) {
        Oas30MediaType mediaType = (Oas30MediaType) node.parent();
        this.reportIf(!equals(mediaType.getName(), "application/x-www-form-urlencoded"), node, Constants.PROP_ALLOW_RESERVED, map("name", mediaType.getName()));
    }
}
Also used : Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Example 4 with Oas30Encoding

use of io.apicurio.datamodels.openapi.v3.models.Oas30Encoding in project apicurio-data-models by Apicurio.

the class OasEncodingStyleNotAllowedRule method visitEncoding.

/**
 * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitEncoding(io.apicurio.datamodels.openapi.v3.models.Oas30Encoding)
 */
@Override
public void visitEncoding(Oas30Encoding node) {
    if (hasValue(node.style)) {
        Oas30MediaType mediaType = (Oas30MediaType) node.parent();
        this.reportIfInvalid(mediaType.getName().indexOf("application/x-www-form-urlencoded") == 0, node, Constants.PROP_STYLE, map("name", mediaType.getName()));
    }
}
Also used : Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Example 5 with Oas30Encoding

use of io.apicurio.datamodels.openapi.v3.models.Oas30Encoding in project apicurio-data-models by Apicurio.

the class OasUnmatchedEncodingPropertyRule method visitEncoding.

/**
 * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitEncoding(io.apicurio.datamodels.openapi.v3.models.Oas30Encoding)
 */
@Override
public void visitEncoding(Oas30Encoding node) {
    String name = node.getName();
    OasSchema schema = ((Oas30MediaType) (node.parent())).schema;
    this.reportIfInvalid(isValidSchemaProperty(schema, name), node, name, map("name", name));
}
Also used : OasSchema(io.apicurio.datamodels.openapi.models.OasSchema) Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Aggregations

Oas30MediaType (io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)5 OasSchema (io.apicurio.datamodels.openapi.models.OasSchema)1 Oas30Encoding (io.apicurio.datamodels.openapi.v3.models.Oas30Encoding)1 Oas30Example (io.apicurio.datamodels.openapi.v3.models.Oas30Example)1 Oas30Header (io.apicurio.datamodels.openapi.v3.models.Oas30Header)1