Search in sources :

Example 1 with Oas30Example

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

the class AddExampleCommand_30 method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[AddExampleCommand_30] Executing.");
    this._exampleAdded = false;
    IExamplesParent examplesParent = (IExamplesParent) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(examplesParent)) {
        return;
    }
    if (!this.isNullOrUndefined(examplesParent.getExample(this._newExampleName))) {
        return;
    }
    Oas30Example example = (Oas30Example) examplesParent.createExample(this._newExampleName);
    example.summary = this._newExampleSummary;
    example.description = this._newExampleDescription;
    example.value = this._newExampleValue;
    examplesParent.addExample(example);
    this._exampleAdded = true;
}
Also used : Oas30Example(io.apicurio.datamodels.openapi.v3.models.Oas30Example) IExamplesParent(io.apicurio.datamodels.core.models.common.IExamplesParent)

Example 2 with Oas30Example

use of io.apicurio.datamodels.openapi.v3.models.Oas30Example 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)

Example 3 with Oas30Example

use of io.apicurio.datamodels.openapi.v3.models.Oas30Example 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 4 with Oas30Example

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

the class OasExampleValueMutualExclusivityRule method visitExample.

/**
 * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitExample(io.apicurio.datamodels.core.models.common.IExample)
 */
@Override
public void visitExample(IExample node) {
    Oas30Example example30 = (Oas30Example) node;
    this.reportIf(hasValue(example30.value) && hasValue(example30.externalValue), example30, Constants.PROP_VALUE, map());
}
Also used : Oas30Example(io.apicurio.datamodels.openapi.v3.models.Oas30Example)

Example 5 with Oas30Example

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

the class Oas30IReferenceManipulationStrategy method attachAsComponent.

@Override
public ReferenceAndNode attachAsComponent(Document document, String name, Node component) {
    // TODO visitor?
    if (// TODO get documenttype
    !(document instanceof Oas30Document))
        throw new IllegalArgumentException("Oas30Document expected.");
    Oas30Document model = (Oas30Document) document;
    if (component instanceof Oas30Schema) {
        if (model.components.getSchemaDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30SchemaDefinition definition = wrap(component, new Oas30SchemaDefinition(name), model);
        // TODO this should be done by vvv
        definition.attachToParent(model.components);
        model.components.addSchemaDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "schemas/" + name, definition);
    }
    if (component instanceof Oas30Response) {
        if (model.components.getResponseDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30ResponseDefinition definition = wrap(component, new Oas30ResponseDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addResponseDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "responses/" + name, definition);
    }
    if (component instanceof Oas30Parameter) {
        if (model.components.getParameterDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30ParameterDefinition definition = wrap(component, new Oas30ParameterDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addParameterDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "parameters/" + name, definition);
    }
    if (component instanceof Oas30Example) {
        if (model.components.getExampleDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30ExampleDefinition definition = wrap(component, new Oas30ExampleDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addExampleDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "examples/" + name, definition);
    }
    if (component instanceof Oas30RequestBody) {
        if (model.components.getRequestBodyDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30RequestBodyDefinition definition = wrap(component, new Oas30RequestBodyDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addRequestBodyDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "requestBodies/" + name, definition);
    }
    if (component instanceof Oas30Header) {
        if (model.components.getHeaderDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30HeaderDefinition definition = wrap(component, new Oas30HeaderDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addHeaderDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "headers/" + name, definition);
    }
    if (component instanceof ModernSecurityScheme) {
        if (model.components.getSecurityScheme(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30SecurityScheme definition = wrap(component, new Oas30SecurityScheme(name), model);
        definition.attachToParent(model.components);
        model.components.addSecurityScheme(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "securitySchemes/" + name, definition);
    }
    if (component instanceof Oas30Link) {
        if (model.components.getLinkDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30LinkDefinition definition = wrap(component, new Oas30LinkDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addLinkDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "links/" + name, definition);
    }
    if (component instanceof Oas30Callback) {
        if (model.components.getCallbackDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30CallbackDefinition definition = wrap(component, new Oas30CallbackDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addCallbackDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "callbacks/" + name, definition);
    }
    return null;
}
Also used : ModernSecurityScheme(io.apicurio.datamodels.core.models.common.ModernSecurityScheme) Oas30CallbackDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30CallbackDefinition) Oas30SchemaDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30SchemaDefinition) Oas30Parameter(io.apicurio.datamodels.openapi.v3.models.Oas30Parameter) Oas30Example(io.apicurio.datamodels.openapi.v3.models.Oas30Example) Oas30Callback(io.apicurio.datamodels.openapi.v3.models.Oas30Callback) Oas30RequestBodyDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30RequestBodyDefinition) Oas30ResponseDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ResponseDefinition) Oas30Schema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema) Oas30Header(io.apicurio.datamodels.openapi.v3.models.Oas30Header) Oas30HeaderDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30HeaderDefinition) Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) Oas30ExampleDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ExampleDefinition) Oas30LinkDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30LinkDefinition) Oas30ParameterDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition) Oas30RequestBody(io.apicurio.datamodels.openapi.v3.models.Oas30RequestBody) Oas30Link(io.apicurio.datamodels.openapi.v3.models.Oas30Link) Oas30SecurityScheme(io.apicurio.datamodels.openapi.v3.models.Oas30SecurityScheme) Oas30Response(io.apicurio.datamodels.openapi.v3.models.Oas30Response)

Aggregations

Oas30Example (io.apicurio.datamodels.openapi.v3.models.Oas30Example)12 Oas30Parameter (io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)5 Oas30Header (io.apicurio.datamodels.openapi.v3.models.Oas30Header)2 Oas30MediaType (io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)2 IExamplesParent (io.apicurio.datamodels.core.models.common.IExamplesParent)1 ModernSecurityScheme (io.apicurio.datamodels.core.models.common.ModernSecurityScheme)1 Oas30Callback (io.apicurio.datamodels.openapi.v3.models.Oas30Callback)1 Oas30CallbackDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30CallbackDefinition)1 Oas30Document (io.apicurio.datamodels.openapi.v3.models.Oas30Document)1 Oas30Encoding (io.apicurio.datamodels.openapi.v3.models.Oas30Encoding)1 Oas30ExampleDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ExampleDefinition)1 Oas30HeaderDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30HeaderDefinition)1 Oas30Link (io.apicurio.datamodels.openapi.v3.models.Oas30Link)1 Oas30LinkDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30LinkDefinition)1 Oas30ParameterDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition)1 Oas30RequestBody (io.apicurio.datamodels.openapi.v3.models.Oas30RequestBody)1 Oas30RequestBodyDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30RequestBodyDefinition)1 Oas30Response (io.apicurio.datamodels.openapi.v3.models.Oas30Response)1 Oas30ResponseDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ResponseDefinition)1 Oas30Schema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema)1