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;
}
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);
}
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);
}
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());
}
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;
}
Aggregations