Search in sources :

Example 1 with Oas30ParameterDefinition

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

the class Oas30DataModelReader method readComponents.

/**
 * Reads a Components model.
 * @param json
 * @param node
 */
public void readComponents(Object json, Oas30Components node) {
    Object schemas = JsonCompat.consumeProperty(json, Constants.PROP_SCHEMAS);
    Object responses = JsonCompat.consumeProperty(json, Constants.PROP_RESPONSES);
    Object parameters = JsonCompat.consumeProperty(json, Constants.PROP_PARAMETERS);
    Object examples = JsonCompat.consumeProperty(json, Constants.PROP_EXAMPLES);
    Object requestBodies = JsonCompat.consumeProperty(json, Constants.PROP_REQUEST_BODIES);
    Object headers = JsonCompat.consumeProperty(json, Constants.PROP_HEADERS);
    Object securitySchemes = JsonCompat.consumeProperty(json, Constants.PROP_SECURITY_SCHEMES);
    Object links = JsonCompat.consumeProperty(json, Constants.PROP_LINKS);
    Object callbacks = JsonCompat.consumeProperty(json, Constants.PROP_CALLBACKS);
    if (schemas != null) {
        JsonCompat.keys(schemas).forEach(name -> {
            Object schema = JsonCompat.consumeProperty(schemas, name);
            Oas30SchemaDefinition schemaModel = node.createSchemaDefinition(name);
            this.readSchema(schema, schemaModel);
            node.addSchemaDefinition(name, schemaModel);
        });
    }
    if (responses != null) {
        JsonCompat.keys(responses).forEach(name -> {
            Object response = JsonCompat.consumeProperty(responses, name);
            Oas30ResponseDefinition responseModel = node.createResponseDefinition(name);
            this.readResponse(response, responseModel);
            node.addResponseDefinition(name, responseModel);
        });
    }
    if (parameters != null) {
        JsonCompat.keys(parameters).forEach(name -> {
            Object parameter = JsonCompat.consumeProperty(parameters, name);
            Oas30ParameterDefinition parameterModel = node.createParameterDefinition(name);
            this.readParameter(parameter, parameterModel);
            node.addParameterDefinition(name, parameterModel);
        });
    }
    if (examples != null) {
        JsonCompat.keys(examples).forEach(name -> {
            Object example = JsonCompat.consumeProperty(examples, name);
            Oas30ExampleDefinition exampleModel = node.createExampleDefinition(name);
            this.readExample(example, exampleModel);
            node.addExampleDefinition(name, exampleModel);
        });
    }
    if (requestBodies != null) {
        JsonCompat.keys(requestBodies).forEach(name -> {
            Object requestBody = JsonCompat.consumeProperty(requestBodies, name);
            Oas30RequestBodyDefinition requestBodyModel = node.createRequestBodyDefinition(name);
            this.readRequestBody(requestBody, requestBodyModel);
            node.addRequestBodyDefinition(name, requestBodyModel);
        });
    }
    if (headers != null) {
        JsonCompat.keys(headers).forEach(name -> {
            Object header = JsonCompat.consumeProperty(headers, name);
            Oas30HeaderDefinition headerModel = node.createHeaderDefinition(name);
            this.readHeader(header, headerModel);
            node.addHeaderDefinition(name, headerModel);
        });
    }
    if (securitySchemes != null) {
        JsonCompat.keys(securitySchemes).forEach(name -> {
            Object securityScheme = JsonCompat.consumeProperty(securitySchemes, name);
            Oas30SecurityScheme securitySchemeModel = node.createSecurityScheme(name);
            this.readSecurityScheme(securityScheme, securitySchemeModel);
            node.addSecurityScheme(name, securitySchemeModel);
        });
    }
    if (links != null) {
        JsonCompat.keys(links).forEach(name -> {
            Object link = JsonCompat.consumeProperty(links, name);
            Oas30LinkDefinition linkModel = node.createLinkDefinition(name);
            this.readLink(link, linkModel);
            node.addLinkDefinition(name, linkModel);
        });
    }
    if (callbacks != null) {
        JsonCompat.keys(callbacks).forEach(name -> {
            Object callback = JsonCompat.consumeProperty(callbacks, name);
            Oas30CallbackDefinition callbackModel = node.createCallbackDefinition(name);
            this.readCallback(callback, callbackModel);
            node.addCallbackDefinition(name, callbackModel);
        });
    }
}
Also used : Oas30CallbackDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30CallbackDefinition) Oas30SchemaDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30SchemaDefinition) Oas30ExampleDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ExampleDefinition) Oas30LinkDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30LinkDefinition) Oas30ParameterDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition) Oas30SecurityScheme(io.apicurio.datamodels.openapi.v3.models.Oas30SecurityScheme) Oas30RequestBodyDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30RequestBodyDefinition) Oas30ResponseDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ResponseDefinition) Oas30HeaderDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30HeaderDefinition)

Example 2 with Oas30ParameterDefinition

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

the class Oas20to30TransformationVisitor method visitParameterDefinition.

/**
 * @see io.apicurio.datamodels.core.visitors.IVisitor#visitParameterDefinition(io.apicurio.datamodels.core.models.common.IDefinition)
 */
@Override
public void visitParameterDefinition(IDefinition node) {
    Oas20ParameterDefinition pd20 = (Oas20ParameterDefinition) node;
    if (NodeCompat.equals(pd20.in, "body")) {
        Oas30Components parent30 = this.getOrCreateComponents();
        Oas30RequestBodyDefinition bodyDef30 = parent30.createRequestBodyDefinition(pd20.getName());
        parent30.addRequestBodyDefinition(pd20.getName(), bodyDef30);
        bodyDef30.description = pd20.description;
        bodyDef30.required = pd20.required;
        if (!NodeCompat.isNullOrUndefined(pd20.schema)) {
            List<String> consumes = this.findConsumes(pd20);
            Oas20Schema schema = (Oas20Schema) pd20.schema;
            consumes.forEach(ct -> {
                Oas30MediaType mediaType30 = bodyDef30.createMediaType(ct);
                bodyDef30.addMediaType(ct, mediaType30);
                Oas30Schema schema30 = mediaType30.createSchema();
                mediaType30.schema = this.toSchema(schema, schema30, true);
                this.mapNode(schema, schema30);
            });
        }
    } else if (NodeCompat.equals(pd20.in, "formData")) {
    // Exclude any re-usable formData parameters - they are currently being inlined elsewhere.  I'm not sure
    // what we would do with them anyway.
    } else {
        Oas30Components components30 = this.getOrCreateComponents();
        Oas30ParameterDefinition paramDef30 = components30.createParameterDefinition(pd20.getName());
        components30.addParameterDefinition(pd20.getName(), paramDef30);
        this.transformParam(pd20, paramDef30);
        this.mapNode(pd20, paramDef30);
    }
}
Also used : Oas20Schema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema) Oas30Components(io.apicurio.datamodels.openapi.v3.models.Oas30Components) Oas30ParameterDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition) Oas20ParameterDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition) Oas30RequestBodyDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30RequestBodyDefinition) Oas30Schema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema) Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Example 3 with Oas30ParameterDefinition

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

Example 4 with Oas30ParameterDefinition

use of io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition in project syndesis by syndesisio.

the class Oas30DataShapeGeneratorHelperTest method shouldGetOperationParametersJoinedWithPathItemParametersAndReferences.

@Test
public void shouldGetOperationParametersJoinedWithPathItemParametersAndReferences() {
    Oas30Document openApiDoc = new Oas30Document();
    openApiDoc.components = openApiDoc.createComponents();
    Oas30ParameterDefinition globalParameter = openApiDoc.components.createParameterDefinition("version");
    openApiDoc.components.addParameterDefinition("Version", globalParameter);
    openApiDoc.components.addParameterDefinition("Unused", openApiDoc.components.createParameterDefinition("unused"));
    openApiDoc.paths = openApiDoc.createPaths();
    Oas30PathItem pathItem = (Oas30PathItem) openApiDoc.paths.createPathItem("/test/{id}");
    openApiDoc.paths.addPathItem("test", pathItem);
    Oas30Parameter pathParameter = (Oas30Parameter) pathItem.createParameter();
    pathParameter.$ref = "#components/parameters/Version";
    pathItem.addParameter(pathParameter);
    Oas30Operation operation = (Oas30Operation) pathItem.createOperation("get");
    pathItem.get = operation;
    Oas30Parameter operationParameter = (Oas30Parameter) operation.createParameter();
    operationParameter.in = "path";
    operationParameter.name = "id";
    operation.addParameter(operationParameter);
    List<Oas30Parameter> operationParameters = Oas30DataShapeGeneratorHelper.getOperationParameters(openApiDoc, operation);
    Assertions.assertThat(operationParameters).hasSize(2);
    Assertions.assertThat(operationParameters).contains(globalParameter, operationParameter);
}
Also used : Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) Oas30Parameter(io.apicurio.datamodels.openapi.v3.models.Oas30Parameter) Oas30ParameterDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition) Oas30PathItem(io.apicurio.datamodels.openapi.v3.models.Oas30PathItem) Oas30Operation(io.apicurio.datamodels.openapi.v3.models.Oas30Operation) Test(org.junit.Test)

Example 5 with Oas30ParameterDefinition

use of io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition in project syndesis by syndesisio.

the class Oas30DataShapeGeneratorHelperTest method shouldGetOperationParametersAndReferences.

@Test
public void shouldGetOperationParametersAndReferences() {
    Oas30Document openApiDoc = new Oas30Document();
    openApiDoc.components = openApiDoc.createComponents();
    Oas30ParameterDefinition globalParameter = openApiDoc.components.createParameterDefinition("version");
    openApiDoc.components.addParameterDefinition("Version", globalParameter);
    openApiDoc.components.addParameterDefinition("Unused", openApiDoc.components.createParameterDefinition("unused"));
    openApiDoc.paths = openApiDoc.createPaths();
    Oas30PathItem pathItem = (Oas30PathItem) openApiDoc.paths.createPathItem("/test/{id}");
    openApiDoc.paths.addPathItem("test", pathItem);
    Oas30Operation operation = (Oas30Operation) pathItem.createOperation("get");
    pathItem.get = operation;
    Oas30Parameter versionParameter = (Oas30Parameter) operation.createParameter();
    versionParameter.$ref = "#components/parameters/Version";
    versionParameter.in = "header";
    operation.addParameter(versionParameter);
    Oas30Parameter idParameter = (Oas30Parameter) operation.createParameter();
    idParameter.in = "path";
    idParameter.name = "id";
    operation.addParameter(idParameter);
    List<Oas30Parameter> operationParameters = Oas30DataShapeGeneratorHelper.getOperationParameters(openApiDoc, operation);
    Assertions.assertThat(operationParameters).hasSize(2);
    Assertions.assertThat(operationParameters).contains(globalParameter, idParameter);
}
Also used : Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) Oas30Parameter(io.apicurio.datamodels.openapi.v3.models.Oas30Parameter) Oas30ParameterDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition) Oas30PathItem(io.apicurio.datamodels.openapi.v3.models.Oas30PathItem) Oas30Operation(io.apicurio.datamodels.openapi.v3.models.Oas30Operation) Test(org.junit.Test)

Aggregations

Oas30ParameterDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition)7 Oas30Document (io.apicurio.datamodels.openapi.v3.models.Oas30Document)5 Oas30Parameter (io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)4 Oas30Operation (io.apicurio.datamodels.openapi.v3.models.Oas30Operation)3 Oas30PathItem (io.apicurio.datamodels.openapi.v3.models.Oas30PathItem)3 Oas30RequestBodyDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30RequestBodyDefinition)3 Test (org.junit.Test)3 Oas30CallbackDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30CallbackDefinition)2 Oas30ExampleDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ExampleDefinition)2 Oas30HeaderDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30HeaderDefinition)2 Oas30LinkDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30LinkDefinition)2 Oas30ResponseDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ResponseDefinition)2 Oas30Schema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema)2 Oas30SchemaDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30SchemaDefinition)2 Oas30SecurityScheme (io.apicurio.datamodels.openapi.v3.models.Oas30SecurityScheme)2 ModernSecurityScheme (io.apicurio.datamodels.core.models.common.ModernSecurityScheme)1 Oas20ParameterDefinition (io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition)1 Oas20Schema (io.apicurio.datamodels.openapi.v2.models.Oas20Schema)1 Oas30Callback (io.apicurio.datamodels.openapi.v3.models.Oas30Callback)1 Oas30Components (io.apicurio.datamodels.openapi.v3.models.Oas30Components)1