Search in sources :

Example 1 with Oas20SchemaDefinition

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

the class DeleteSchemaDefinitionCommand_20 method doRestoreSchemaDefinition.

/**
 * @see io.apicurio.datamodels.cmd.commands.DeleteSchemaDefinitionCommand#doRestoreSchemaDefinition(io.apicurio.datamodels.core.models.Document, java.lang.Object)
 */
@Override
protected void doRestoreSchemaDefinition(Document document, Object oldDefinition) {
    Oas20Document doc20 = (Oas20Document) document;
    Oas20Definitions definitions = doc20.definitions;
    if (this.isNullOrUndefined(definitions)) {
        return;
    }
    Oas20SchemaDefinition definition = doc20.definitions.createSchemaDefinition(this._definitionName);
    Library.readNode(oldDefinition, definition);
    definitions.addDefinition(this._definitionName, definition);
}
Also used : Oas20Definitions(io.apicurio.datamodels.openapi.v2.models.Oas20Definitions) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20SchemaDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition)

Example 2 with Oas20SchemaDefinition

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

the class NewSchemaDefinitionCommand_20 method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[NewDefinitionCommand] Executing.");
    Oas20Document doc20 = (Oas20Document) document;
    if (this.isNullOrUndefined(doc20.definitions)) {
        doc20.definitions = doc20.createDefinitions();
        this._nullDefinitions = true;
    }
    if (this.isNullOrUndefined(doc20.definitions.getDefinition(this._newDefinitionName))) {
        Oas20SchemaDefinition definition;
        if (!this.isNullOrUndefined(this._newDefinitionExample)) {
            definition = (Oas20SchemaDefinition) OasSchemaFactory.createSchemaDefinitionFromExample(doc20, this._newDefinitionName, this._newDefinitionExample);
            definition.example = this._newDefinitionExample;
        } else {
            definition = doc20.definitions.createSchemaDefinition(this._newDefinitionName);
            definition.type = "object";
        }
        if (ModelUtils.isDefined(this._newDefinitionDescription)) {
            definition.description = this._newDefinitionDescription;
        }
        doc20.definitions.addDefinition(this._newDefinitionName, definition);
        this._defExisted = false;
    } else {
        this._defExisted = true;
    }
}
Also used : Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20SchemaDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition)

Example 3 with Oas20SchemaDefinition

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

the class Oas20IReferenceManipulationStrategy method attachAsComponent.

@Override
public ReferenceAndNode attachAsComponent(Document document, String name, Node component) {
    if (!(document instanceof Oas20Document))
        throw new IllegalArgumentException("Oas20Document expected.");
    Oas20Document model = (Oas20Document) document;
    if (component instanceof Oas20Schema) {
        if (model.definitions == null)
            model.definitions = model.createDefinitions();
        if (model.definitions.getDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas20SchemaDefinition definition = wrap(component, new Oas20SchemaDefinition(name), model);
        definition.attachToParent(model.definitions);
        model.definitions.addDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "definitions/" + name, definition);
    }
    if (component instanceof Oas20Parameter) {
        if (model.parameters == null)
            model.parameters = model.createParameterDefinitions();
        if (model.parameters.getParameter(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas20ParameterDefinition definition = wrap(component, new Oas20ParameterDefinition(name), model);
        definition.attachToParent(model.parameters);
        model.parameters.addParameter(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "parameters/" + name, definition);
    }
    if (component instanceof Oas20Response) {
        if (model.responses == null)
            model.responses = model.createResponseDefinitions();
        if (model.responses.getResponse(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas20ResponseDefinition definition = wrap(component, new Oas20ResponseDefinition(name), model);
        definition.attachToParent(model.responses);
        model.responses.addResponse(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "responses/" + name, definition);
    }
    return null;
}
Also used : Oas20Schema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20ParameterDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition) Oas20Response(io.apicurio.datamodels.openapi.v2.models.Oas20Response) Oas20SchemaDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition) Oas20Parameter(io.apicurio.datamodels.openapi.v2.models.Oas20Parameter) Oas20ResponseDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20ResponseDefinition)

Example 4 with Oas20SchemaDefinition

use of io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition in project syndesis by syndesisio.

the class CyclicValidationCheckTest method shouldFindTwoStepCyclicReferencesInResponses.

@Test
public void shouldFindTwoStepCyclicReferencesInResponses() {
    final Oas20Document openApiDoc = new Oas20Document();
    final Oas20PathItem pathItem = new Oas20PathItem("/api");
    final Oas20Operation operation = new Oas20Operation("post");
    Oas20Response response = new Oas20Response("200");
    Oas20Schema responseSchema = new Oas20Schema();
    responseSchema.$ref = "#/definitions/A";
    response.schema = responseSchema;
    operation.responses = operation.createResponses();
    operation.responses.addResponse("200", response);
    pathItem.post = operation;
    openApiDoc.paths = openApiDoc.createPaths();
    openApiDoc.paths.addPathItem("/api", pathItem);
    Oas20SchemaDefinition schemaDefinitionA = new Oas20SchemaDefinition("A");
    schemaDefinitionA.type = "object";
    Oas20Schema propertySchemaA = new Oas20Schema();
    propertySchemaA.$ref = "#/definitions/B";
    schemaDefinitionA.properties = new HashMap<>();
    schemaDefinitionA.properties.put("b", propertySchemaA);
    openApiDoc.definitions = openApiDoc.createDefinitions();
    openApiDoc.definitions.addDefinition("A", schemaDefinitionA);
    Oas20SchemaDefinition schemaDefinitionB = new Oas20SchemaDefinition("B");
    schemaDefinitionB.type = "object";
    Oas20Schema propertySchemaB = new Oas20Schema();
    propertySchemaB.$ref = "#/definitions/A";
    schemaDefinitionB.properties = new HashMap<>();
    schemaDefinitionB.properties.put("a", propertySchemaB);
    openApiDoc.definitions.addDefinition("B", schemaDefinitionB);
    assertThat(CyclicValidationCheck.hasCyclicReferences(getSchemaDefinitions(openApiDoc))).isTrue();
}
Also used : Oas20Schema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20PathItem(io.apicurio.datamodels.openapi.v2.models.Oas20PathItem) Oas20Operation(io.apicurio.datamodels.openapi.v2.models.Oas20Operation) Oas20Response(io.apicurio.datamodels.openapi.v2.models.Oas20Response) Oas20SchemaDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition) Test(org.junit.Test)

Example 5 with Oas20SchemaDefinition

use of io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition in project syndesis by syndesisio.

the class CyclicValidationCheckTest method shouldFindThreeStepCyclicReferencesInParameters.

@Test
public void shouldFindThreeStepCyclicReferencesInParameters() {
    final Oas20Document openApiDoc = new Oas20Document();
    final Oas20PathItem pathItem = new Oas20PathItem("/api");
    final Oas20Operation operation = new Oas20Operation("post");
    final Oas20Parameter parameter = new Oas20Parameter();
    parameter.$ref = "#/definitions/A";
    operation.parameters = new ArrayList<>();
    operation.parameters.add(parameter);
    pathItem.post = operation;
    openApiDoc.paths = openApiDoc.createPaths();
    openApiDoc.paths.addPathItem("/api", pathItem);
    Oas20SchemaDefinition schemaDefinitionA = new Oas20SchemaDefinition("A");
    schemaDefinitionA.type = "object";
    Oas20Schema propertySchemaA = new Oas20Schema();
    propertySchemaA.$ref = "#/definitions/B";
    schemaDefinitionA.properties = new HashMap<>();
    schemaDefinitionA.properties.put("b", propertySchemaA);
    openApiDoc.definitions = openApiDoc.createDefinitions();
    openApiDoc.definitions.addDefinition("A", schemaDefinitionA);
    Oas20SchemaDefinition schemaDefinitionB = new Oas20SchemaDefinition("B");
    schemaDefinitionB.type = "object";
    Oas20Schema propertySchemaB = new Oas20Schema();
    propertySchemaB.$ref = "#/definitions/C";
    schemaDefinitionB.properties = new HashMap<>();
    schemaDefinitionB.properties.put("c", propertySchemaB);
    openApiDoc.definitions.addDefinition("B", schemaDefinitionB);
    Oas20SchemaDefinition schemaDefinitionC = new Oas20SchemaDefinition("C");
    schemaDefinitionC.type = "object";
    Oas20Schema propertySchemaC = new Oas20Schema();
    propertySchemaC.$ref = "#/definitions/A";
    schemaDefinitionC.properties = new HashMap<>();
    schemaDefinitionC.properties.put("a", propertySchemaC);
    openApiDoc.definitions.addDefinition("C", schemaDefinitionC);
    assertThat(CyclicValidationCheck.hasCyclicReferences(getSchemaDefinitions(openApiDoc))).isTrue();
}
Also used : Oas20Schema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20PathItem(io.apicurio.datamodels.openapi.v2.models.Oas20PathItem) Oas20Operation(io.apicurio.datamodels.openapi.v2.models.Oas20Operation) Oas20SchemaDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition) Oas20Parameter(io.apicurio.datamodels.openapi.v2.models.Oas20Parameter) Test(org.junit.Test)

Aggregations

Oas20Document (io.apicurio.datamodels.openapi.v2.models.Oas20Document)21 Oas20SchemaDefinition (io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition)21 Test (org.junit.Test)11 Oas20Schema (io.apicurio.datamodels.openapi.v2.models.Oas20Schema)10 Oas20Operation (io.apicurio.datamodels.openapi.v2.models.Oas20Operation)9 Oas20PathItem (io.apicurio.datamodels.openapi.v2.models.Oas20PathItem)9 Oas20Parameter (io.apicurio.datamodels.openapi.v2.models.Oas20Parameter)7 Oas20Response (io.apicurio.datamodels.openapi.v2.models.Oas20Response)5 ArrayList (java.util.ArrayList)3 Oas20Definitions (io.apicurio.datamodels.openapi.v2.models.Oas20Definitions)2 ExtensibleNode (io.apicurio.datamodels.core.models.ExtensibleNode)1 IReferenceNode (io.apicurio.datamodels.core.models.IReferenceNode)1 Node (io.apicurio.datamodels.core.models.Node)1 IPropertySchema (io.apicurio.datamodels.core.models.common.IPropertySchema)1 OasSchema (io.apicurio.datamodels.openapi.models.OasSchema)1 Oas20ParameterDefinition (io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition)1 Oas20ResponseDefinition (io.apicurio.datamodels.openapi.v2.models.Oas20ResponseDefinition)1 Oas30Components (io.apicurio.datamodels.openapi.v3.models.Oas30Components)1 Oas30SchemaDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30SchemaDefinition)1 OpenApiModelInfo (io.syndesis.server.api.generator.openapi.OpenApiModelInfo)1