Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with Ruby client where strings from example properties are not wrapped with quotes #987

Merged
merged 1 commit into from
Nov 4, 2018

Conversation

ndbroadbent
Copy link
Contributor

@ndbroadbent ndbroadbent commented Sep 6, 2018

This fixes an issue with examples for the Ruby client, where example strings are not properly quoted.

Before, it would generate code like this:

order_id = order_id123 # String | 

After this change, the example string is wrapped with single quotes:

order_id = 'order_id123' # String | 

This change might be useful for some other languages too, but not sure. Maybe I should update the code in DefaultCodegen.

@ndbroadbent
Copy link
Contributor Author

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 setParameterExampleValue method. I have a class that extends PythonClientCodegen, and dropped this code at the bottom:

  /**
   * 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 DefaultCodegen?

@ackintosh
Copy link
Contributor

Maybe this should go into DefaultCodegen?

It looks good to me. 👀 cc: @OpenAPITools/generator-core-team

@wing328
Copy link
Member

wing328 commented Nov 4, 2018

Maybe this should go into DefaultCodegen?

I would prefer keeping the existing implementation in DefaultCodegen and let generator override it to meet its requirement.

@wing328 wing328 merged commit 63b1c23 into OpenAPITools:master Nov 4, 2018
@wing328 wing328 added this to the 3.3.3 milestone Nov 4, 2018
@wing328
Copy link
Member

wing328 commented Nov 15, 2018

@ndbroadbent thanks for the PR, which has been included in the v3.3.3 release: https://twitter.com/oas_generator/status/1062929948191510528

A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants