Forum Discussion
Hi Humashankar
I am using Swagger openapi: 3.0.0 version and specified "jaxrs-jersey" as language for code generation as below in swagger-codegen-maven-plugin entry:
:
<executions>
<execution>
<id>java-api-v1</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${swagger-gen-api-v1-file}</inputSpec>
<language>jaxrs-jersey</language>
<addCompileSourceRoot>false</addCompileSourceRoot>
<configOptions>
<sourceFolder>src/gen/java</sourceFolder>
<serializableModel>true</serializableModel>
</configOptions>
</configuration>
</execution>
</executions>
Actually, now I am trying with String (instead of enum) to make it simple. So I changed parameter definition as below:
parameters:
status:
in: query
style: form
explode: false
schema:
type: array
items:
type: string
So, in the generated code I see the query parameter as below:
@Parameter(in = ParameterIn.QUERY, description = "") @QueryParam("status") List<String> status
With this when I send the query param like "?status=abc,xyz,test", I am receiving it as:
satus = ["abc,xyz,test"]
But I am expecting it as:
satus = ["abc","xyz","test"]
Thanks for the inputs ravik51378
Looks Swagger code generator treats as a single string value instead of an array of individual strings
Can you try doing this by adding a custom validation method to the query parameter, like below,
@Parameter(in = ParameterIn.QUERY, description = "")
@QueryParam("status")
List<String> status;
@Validation
public void validateStatus(List<String> status) {
String[] statusArray = status.get(0).split(",");
this.status = Arrays.asList(statusArray);
}
Out of it, this will split the incoming string into an array of individual strings using the "," delimiter, and then set the "status" field to a list of those strings.
Regards
- ravik513789 months agoNew Contributor
Hi Humashankar I cannot add @Validation to parameter, because this class is auto generated by Swagger codegen plugin. This class is not inside my "src" folder. It is inside "/target/generated-sources/swagger/src/gen" folder. Thanks for looking into it.
Related Content
Recent Discussions
- 21 hours ago
- 12 days ago