Search in sources :

Example 1 with Oas30MediaType

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

the class DeleteExampleCommand_30 method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[DeleteExampleCommand] Reverting.");
    if (this.isNullOrUndefined(this._oldExample)) {
        return;
    }
    Oas30MediaType mediaType = (Oas30MediaType) this._mediaTypePath.resolve(document);
    if (this.isNullOrUndefined(mediaType)) {
        LoggerCompat.info("[DeleteExampleCommand] No media type found.");
        return;
    }
    IExample example = mediaType.createExample(this._exampleName);
    Library.readNode(this._oldExample, (Node) example);
    mediaType.addExample(example);
}
Also used : IExample(io.apicurio.datamodels.core.models.common.IExample) Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Example 2 with Oas30MediaType

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

the class DeleteMediaTypeCommand method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[DeleteMediaTypeCommand] Reverting.");
    if (this.isNullOrUndefined(this._oldMediaType)) {
        return;
    }
    IOas30MediaTypeParent parent = (IOas30MediaTypeParent) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(parent)) {
        return;
    }
    Oas30MediaType mediaType = parent.createMediaType(this._mediaTypeName);
    Library.readNode(this._oldMediaType, mediaType);
    parent.addMediaType(this._mediaTypeName, mediaType);
}
Also used : IOas30MediaTypeParent(io.apicurio.datamodels.openapi.v3.models.IOas30MediaTypeParent) Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Example 3 with Oas30MediaType

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

the class ChangeMediaTypeTypeCommand method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[ChangeMediaTypeTypeCommand] Executing.");
    this._changed = false;
    Oas30MediaType mediaType = (Oas30MediaType) this._mediaTypePath.resolve(document);
    if (this.isNullOrUndefined(mediaType)) {
        return;
    }
    // Save the old info (for later undo operation)
    if (this.isNullOrUndefined(mediaType.schema)) {
        this._oldMediaTypeSchema = null;
        mediaType.schema = mediaType.createSchema();
    } else {
        this._oldMediaTypeSchema = Library.writeNode(mediaType.schema);
    }
    // Update the media type schema's type
    SimplifiedTypeUtil.setSimplifiedType(mediaType.schema, this._newType);
    this._changed = true;
}
Also used : Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Example 4 with Oas30MediaType

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

the class AddExampleCommand_30 method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[AddExampleCommand_30] Reverting.");
    if (!this._exampleAdded) {
        return;
    }
    Oas30MediaType mediaType = (Oas30MediaType) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(mediaType) || this.isNullOrUndefined(mediaType.examples)) {
        return;
    }
    mediaType.removeExample(this._newExampleName);
}
Also used : Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Example 5 with Oas30MediaType

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

the class Oas30DataModelReader method readParameter.

/**
 * @see io.apicurio.datamodels.openapi.io.OasDataModelReader#readParameter(java.lang.Object, io.apicurio.datamodels.core.models.common.Parameter)
 */
@Override
public void readParameter(Object json, Parameter node) {
    Oas30Parameter param = (Oas30Parameter) node;
    Boolean deprecated = JsonCompat.consumePropertyBoolean(json, Constants.PROP_DEPRECATED);
    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);
    Object example = JsonCompat.consumeProperty(json, Constants.PROP_EXAMPLE);
    Object examples = JsonCompat.consumeProperty(json, Constants.PROP_EXAMPLES);
    Object content = JsonCompat.consumeProperty(json, Constants.PROP_CONTENT);
    param.deprecated = deprecated;
    param.style = style;
    param.explode = explode;
    param.allowReserved = allowReserved;
    param.example = example;
    if (examples != null) {
        JsonCompat.keys(examples).forEach(name -> {
            Object exx = JsonCompat.consumeProperty(examples, name);
            Oas30Example exampleModel = param.createExample(name);
            this.readExample(exx, exampleModel);
            param.addExample(exampleModel);
        });
    }
    if (content != null) {
        JsonCompat.keys(content).forEach(name -> {
            Object mediaType = JsonCompat.consumeProperty(content, name);
            Oas30MediaType mediaTypeModel = param.createMediaType(name);
            this.readMediaType(mediaType, mediaTypeModel);
            param.addMediaType(name, mediaTypeModel);
        });
    }
    super.readParameter(json, node);
}
Also used : Oas30Parameter(io.apicurio.datamodels.openapi.v3.models.Oas30Parameter) Oas30Example(io.apicurio.datamodels.openapi.v3.models.Oas30Example) Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Aggregations

Oas30MediaType (io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)27 Oas30Parameter (io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)8 Oas30Document (io.apicurio.datamodels.openapi.v3.models.Oas30Document)7 Oas30Operation (io.apicurio.datamodels.openapi.v3.models.Oas30Operation)7 Oas30PathItem (io.apicurio.datamodels.openapi.v3.models.Oas30PathItem)6 Oas30Schema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema)6 Test (org.junit.Test)5 Oas30Response (io.apicurio.datamodels.openapi.v3.models.Oas30Response)4 OpenApiModelInfo (io.syndesis.server.api.generator.openapi.OpenApiModelInfo)4 IOas30MediaTypeParent (io.apicurio.datamodels.openapi.v3.models.IOas30MediaTypeParent)3 Oas30Header (io.apicurio.datamodels.openapi.v3.models.Oas30Header)3 IExample (io.apicurio.datamodels.core.models.common.IExample)2 OasSchema (io.apicurio.datamodels.openapi.models.OasSchema)2 Oas20Schema (io.apicurio.datamodels.openapi.v2.models.Oas20Schema)2 Oas30Example (io.apicurio.datamodels.openapi.v3.models.Oas30Example)2 Oas30RequestBody (io.apicurio.datamodels.openapi.v3.models.Oas30RequestBody)2 DataShapeGenerator (io.syndesis.server.api.generator.openapi.DataShapeGenerator)2 Library (io.apicurio.datamodels.Library)1 JsonCompat (io.apicurio.datamodels.compat.JsonCompat)1 NodeCompat (io.apicurio.datamodels.compat.NodeCompat)1