Search in sources :

Example 11 with RefParameter

use of io.swagger.models.parameters.RefParameter in project swagger-parser by swagger-api.

the class SwaggerConverter method convertFormDataToRequestBody.

private RequestBody convertFormDataToRequestBody(List<io.swagger.models.parameters.Parameter> formParams, List<String> consumes) {
    RequestBody body = new RequestBody();
    Schema formSchema = new Schema();
    for (io.swagger.models.parameters.Parameter param : formParams) {
        SerializableParameter sp;
        Schema schema;
        String name;
        if (param instanceof RefParameter) {
            RefParameter refParameter = (RefParameter) param;
            String simpleRef = refParameter.getSimpleRef();
            sp = (SerializableParameter) globalV2Parameters.get(simpleRef);
            name = components.getSchemas().get("formData_" + simpleRef).getName();
            schema = new Schema().$ref("#/components/schemas/formData_" + simpleRef);
        } else {
            sp = (SerializableParameter) param;
            schema = convert(sp);
            name = schema.getName();
        }
        if (sp.getRequired()) {
            formSchema.addRequiredItem(sp.getName());
        }
        formSchema.addProperties(name, schema);
    }
    List<String> mediaTypes = new ArrayList<>(globalConsumes);
    if (consumes != null && consumes.size() > 0) {
        mediaTypes.clear();
        mediaTypes.addAll(consumes);
    }
    // Assume multipart/form-data if nothing is specified
    if (mediaTypes.size() == 0) {
        mediaTypes.add("multipart/form-data");
    }
    Content content = new Content();
    for (String type : mediaTypes) {
        content.addMediaType(type, new MediaType().schema(formSchema));
    }
    body.content(content);
    return body;
}
Also used : SerializableParameter(io.swagger.models.parameters.SerializableParameter) AbstractSerializableParameter(io.swagger.models.parameters.AbstractSerializableParameter) RefParameter(io.swagger.models.parameters.RefParameter) Content(io.swagger.v3.oas.models.media.Content) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) FileSchema(io.swagger.v3.oas.models.media.FileSchema) ArrayList(java.util.ArrayList) MediaType(io.swagger.v3.oas.models.media.MediaType) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody)

Aggregations

RefParameter (io.swagger.models.parameters.RefParameter)11 BodyParameter (io.swagger.models.parameters.BodyParameter)5 Test (org.testng.annotations.Test)5 QueryParameter (io.swagger.models.parameters.QueryParameter)4 Parameter (io.swagger.models.parameters.Parameter)3 Model (io.swagger.models.Model)2 AbstractSerializableParameter (io.swagger.models.parameters.AbstractSerializableParameter)2 PathParameter (io.swagger.models.parameters.PathParameter)2 SerializableParameter (io.swagger.models.parameters.SerializableParameter)2 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)2 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)2 FileSchema (io.swagger.v3.oas.models.media.FileSchema)2 Schema (io.swagger.v3.oas.models.media.Schema)2 ArrayList (java.util.ArrayList)2 Contact (io.swagger.models.Contact)1 Info (io.swagger.models.Info)1 Operation (io.swagger.models.Operation)1 Path (io.swagger.models.Path)1 Person (io.swagger.models.Person)1 RefModel (io.swagger.models.RefModel)1