Search in sources :

Example 1 with Oas20Response

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

the class DeleteExampleCommand_20 method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[DeleteExampleCommand] Executing.");
    this._oldExample = null;
    Oas20Response response = (Oas20Response) this._responsePath.resolve(document);
    if (this.isNullOrUndefined(response) || this.isNullOrUndefined(response.examples) || this.isNullOrUndefined(response.examples.getExample(this._exampleContentType))) {
        LoggerCompat.debug("[DeleteExampleCommand] No example with content-type: " + this._exampleContentType);
        return;
    }
    this._oldExample = response.examples.removeExample(this._exampleContentType);
}
Also used : Oas20Response(io.apicurio.datamodels.openapi.v2.models.Oas20Response)

Example 2 with Oas20Response

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

the class Oas20Traverser method traverseResponse.

/**
 * @see io.apicurio.datamodels.openapi.visitors.OasTraverser#traverseResponse(io.apicurio.datamodels.openapi.models.OasResponse)
 */
@Override
protected void traverseResponse(OasResponse node) {
    Oas20Response response = (Oas20Response) node;
    this.traverseIfNotNull(response.headers);
    this.traverseIfNotNull(response.schema);
    this.traverseIfNotNull(response.examples);
    super.traverseResponse(node);
}
Also used : Oas20Response(io.apicurio.datamodels.openapi.v2.models.Oas20Response)

Example 3 with Oas20Response

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

the class Oas20to30TransformationVisitor method transformResponse.

private void transformResponse(Oas20Response node, Oas30Response response30) {
    response30.description = node.description;
    if (!NodeCompat.isNullOrUndefined(node.schema)) {
        List<String> produces = this.findProduces(node);
        Oas20Schema schema = node.schema;
        produces.forEach(ct -> {
            Oas30MediaType mediaType30 = response30.createMediaType(ct);
            response30.addMediaType(ct, mediaType30);
            Oas30Schema schema30 = mediaType30.createSchema();
            mediaType30.schema = this.toSchema(schema, schema30, true);
            if (!NodeCompat.isNullOrUndefined(node.examples)) {
                Object ctexample = node.examples.getExample(ct);
                if (!NodeCompat.isNullOrUndefined(ctexample)) {
                    mediaType30.example = ctexample;
                }
            }
            this.mapNode(schema, schema30);
        });
        // mark the Response as needing Content post-processing
        if (produces.size() > 1) {
            this._postProcessResponses.add(response30);
        }
    }
}
Also used : Oas20Schema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema) Oas30Schema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema) Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Example 4 with Oas20Response

use of io.apicurio.datamodels.openapi.v2.models.Oas20Response 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 5 with Oas20Response

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

Aggregations

Oas20Response (io.apicurio.datamodels.openapi.v2.models.Oas20Response)16 Oas20Schema (io.apicurio.datamodels.openapi.v2.models.Oas20Schema)9 Oas20Document (io.apicurio.datamodels.openapi.v2.models.Oas20Document)7 Oas20Operation (io.apicurio.datamodels.openapi.v2.models.Oas20Operation)6 Oas20PathItem (io.apicurio.datamodels.openapi.v2.models.Oas20PathItem)6 Test (org.junit.Test)6 Oas20SchemaDefinition (io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition)5 Oas20Parameter (io.apicurio.datamodels.openapi.v2.models.Oas20Parameter)4 OpenApiModelInfo (io.syndesis.server.api.generator.openapi.OpenApiModelInfo)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Oas20ParameterDefinition (io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition)1 Oas20ResponseDefinition (io.apicurio.datamodels.openapi.v2.models.Oas20ResponseDefinition)1 Oas30MediaType (io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)1 Oas30Schema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema)1