Skip to content

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

Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom
DocSpring:ruby-example-string-quotes
Nov 4, 2018
Merged

Fix issue with Ruby client where strings from example properties are not wrapped with quotes#987
wing328 merged 1 commit intoOpenAPITools:masterfrom
DocSpring:ruby-example-string-quotes

Conversation

@ndbroadbent
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Maybe this should go into DefaultCodegen?

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

@wing328
Copy link
Copy Markdown
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
Copy Markdown
Member

wing328 commented Nov 15, 2018

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.

3 participants