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

Document 'x-enum-descriptions' and 'x-enum-varnames' #2010

Merged
merged 2 commits into from
Jan 29, 2019

Conversation

jmini
Copy link
Member

@jmini jmini commented Jan 28, 2019

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

Fixes #1871

@jimschubert
Copy link
Member

@jmini this looks good. Are there any special cases to consider? For example, if enum values aren't in sorted order:

enum:
  - 7
  - 4
  - 1

Is the user to assume the names and descriptions follow the documented order?

@jmini
Copy link
Member Author

jmini commented Jan 29, 2019

@jimschubert:

enum, x-enum-descriptions and x-enum-varnames are each expected to be list of items. They are sorted. First items of each list are grouped together ("1", "Blue sky" and "Sunny" in the example), second items and so on... In the ideal case, the list have the same amount of items but we handle cases where it is not the case.

@jimschubert
Copy link
Member

@jmini Thanks for the update. I think this is very clear. I've approved the PR, but for some reason it shows the builds as red.

I'm traveling today, so I won't be able to keep an eye on the build after a merge. Feel free to merge.

@jmini jmini merged commit 02a8dad into OpenAPITools:master Jan 29, 2019
@jmini jmini added this to the 4.0.0 milestone Jan 29, 2019
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
@yosev
Copy link

yosev commented Mar 12, 2019

Looks like type: boolean is trying to instantiate an enum with a string as parameter instead of boolean when generating java spring

UserAccess:
      type: boolean
      enum:
        - true
        - false
        - true
      x-enum-descriptions:
        - "Blue sky"
        - "Slightly overcast"
        - "Take an umbrella with you"
      x-enum-varnames:
        - Sunny
        - Cloudy
        - Rainy
public enum UserAccess {
  
  Sunny("true"),
  
  Cloudy("false"),
  
  Rainy("true");

  private Boolean value;

  UserAccess(Boolean value) {
    this.value = value;
  }

  @Override
  @JsonValue
  public String toString() {
    return String.valueOf(value);
  }

  @JsonCreator
  public static UserAccess fromValue(String text) {
    for (UserAccess b : UserAccess.values()) {
      if (String.valueOf(b.value).equals(text)) {
        return b;
      }
    }
    throw new IllegalArgumentException("Unexpected value '" + text + "'");
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants