Fix issue with Ruby client where strings from example properties are not wrapped with quotes#987
Conversation
…not wrapped with quotes
|
I'm working on a Python client now, and it has the same issue with unquoted example strings. I was also able to fix this by overriding the /**
* Return the example value of the parameter. - Fixes issue with unquoted
* strings from x-example
*
* @param codegenParameter Codegen parameter
* @param parameter Parameter
*/
public void setParameterExampleValue(CodegenParameter codegenParameter, Parameter parameter) {
if (parameter.getExample() != null) {
codegenParameter.example = parameter.getExample().toString();
} else if (parameter.getExamples() != null && !parameter.getExamples().isEmpty()) {
Example example = parameter.getExamples().values().iterator().next();
if (example.getValue() != null) {
codegenParameter.example = example.getValue().toString();
}
} else {
Schema schema = parameter.getSchema();
if (schema != null && schema.getExample() != null) {
codegenParameter.example = schema.getExample().toString();
}
}
setParameterExampleValue(codegenParameter);
}Maybe this should go into |
It looks good to me. 👀 cc: @OpenAPITools/generator-core-team |
I would prefer keeping the existing implementation in DefaultCodegen and let generator override it to meet its requirement. |
|
@ndbroadbent thanks for the PR, which has been included in the v3.3.3 release: https://twitter.com/oas_generator/status/1062929948191510528 |
…not wrapped with quotes (OpenAPITools#987)
This fixes an issue with examples for the Ruby client, where example strings are not properly quoted.
Before, it would generate code like this:
After this change, the example string is wrapped with single quotes:
This change might be useful for some other languages too, but not sure. Maybe I should update the code in
DefaultCodegen.