Skip to content

[REQ] Better collection serialization support #4039

@ackintosh

Description

@ackintosh

Is your feature request related to a problem? Please describe.

Since OAS 3.0, in order to support common ways of serializing simple parameters, style and explode are defined instead of collectionFormat.

On the other hand, we still using collectionFormat: style and explode parameters are mapped to collectionFormat.

// TDOO revise collectionFormat
String collectionFormat = null;
if (ModelUtils.isArraySchema(parameterSchema)) { // for array parameter
final ArraySchema arraySchema = (ArraySchema) parameterSchema;
Schema inner = getSchemaItems(arraySchema);
if (arraySchema.getItems() == null) {
arraySchema.setItems(inner);
}
collectionFormat = getCollectionFormat(parameter);
// default to csv:
collectionFormat = StringUtils.isEmpty(collectionFormat) ? "csv" : collectionFormat;

protected String getCollectionFormat(Parameter parameter) {
if (Parameter.StyleEnum.FORM.equals(parameter.getStyle())) {
// Ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#style-values
if (Boolean.TRUE.equals(parameter.getExplode())) { // explode is true (default)
return "multi";
} else {
return "csv";
}
} else if (Parameter.StyleEnum.SIMPLE.equals(parameter.getStyle())) {
return "csv";
} else if (Parameter.StyleEnum.PIPEDELIMITED.equals(parameter.getStyle())) {
return "pipe";
} else if (Parameter.StyleEnum.SPACEDELIMITED.equals(parameter.getStyle())) {
return "space";
} else {
return null;
}
}

This can not representate serialization format required in OAS3.

Describe the solution you'd like

In order to make available the serialization format, explode and style parameter values should be assigned to mustache templates, and handle the parameters in each generator.

We need to keep collectionFormat until generators support style and explode.

Additional context

Related PR: #3984

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions