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

List property called "status" has items with type "Statu" #695

Closed
sebastienvermeille opened this issue Mar 1, 2017 · 6 comments
Closed
Milestone

Comments

@sebastienvermeille
Copy link

sebastienvermeille commented Mar 1, 2017

Hi there :)

I am trying to generate some classes with the online generator and for obvious reasons my class called "Status" is transformed to "Statu" is there a workaround ?

Input:

{
  "id": "http://some.site.somewhere/entry-schema#",
  "$schema": "http://url-to-schema.com#",
  "description": "a simple schema",
  "type": "object",
  "properties": {
    "status": {
      "type": "array",
      "items": {
        "type": "string",
        "default": "EMPTY",
        "enum": [
          "FIRST_VALUE",
          "SECOND_VALUE"
        ]
      }
    }
  }
}

Output:

-----------------------------------com.example.Example.java-----------------------------------

package com.example;

import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;


/**
* a simple schema
* 
*/
public class Example {

@SerializedName("status")
@Expose
private List<Statu> status = null;

public List<Statu> getStatus() {
return status;
}

public void setStatus(List<Statu> status) {
this.status = status;
}

}
-----------------------------------com.example.Statu.java-----------------------------------

package com.example;

import java.util.HashMap;
import java.util.Map;
import com.google.gson.annotations.SerializedName;

public enum Statu {

@SerializedName("FIRST_VALUE")
FIRST_VALUE("FIRST_VALUE"),
@SerializedName("SECOND_VALUE")
SECOND_VALUE("SECOND_VALUE");
private final String value;
private final static Map<String, Statu> CONSTANTS = new HashMap<String, Statu>();

static {
for (Statu c: values()) {
CONSTANTS.put(c.value, c);
}
}

private Statu(String value) {
this.value = value;
}

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

public String value() {
return this.value;
}

public static Statu fromValue(String value) {
Statu constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
} else {
return constant;
}
}

}
@sebastienvermeille sebastienvermeille changed the title Online website preview works but not the generator [Bug] Property called "Status" is transformed to "Statu" Mar 1, 2017
@joelittlejohn
Copy link
Owner

There isn't really a workaround I'm afraid, other than renaming this field from status to statuses. Lists are expected to contain multiple items the type of a list item is named by creating a singular noun.

We'll need to add a special case to the inflector so that it does not attempt to singularize this word:

https://github.com/joelittlejohn/jsonschema2pojo/blob/master/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/Inflector.java

@sebastienvermeille
Copy link
Author

Hi @joelittlejohn thank you for the fast answer :)
Can I do a pull request for that case ? How many time will it takes till the new release ? We need it for a professional project.

BTW: Thank you for this great tool :)

@joelittlejohn
Copy link
Owner

Yes feel free to submit a PR. I think you can simply add the word to the 'irregular' list here:

https://github.com/joelittlejohn/jsonschema2pojo/blob/master/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/Inflector.java#L102

We don't need to ever pluralize anything so it doesn't matter that pluralizing 'status' would no longer become 'statuses'.

I'm happy to create a release whenever you're ready. Please do install and test your other project against a local snapshot of this plugin though, we want to be sure that your PR change solves the problem.

@sebastienvermeille
Copy link
Author

@joelittlejohn I've right know published a PR hope I did it the right way :)

@joelittlejohn
Copy link
Owner

joelittlejohn commented Mar 1, 2017

Thanks for reporting this Sebastien. I went a slightly different way with the fix in the end. There's now a specific singularization rule to fix this case, and this allows other similar cases to be unaffected.

I'll release this shortly.

@joelittlejohn joelittlejohn added this to the 0.4.31 milestone Mar 1, 2017
@joelittlejohn joelittlejohn changed the title [Bug] Property called "Status" is transformed to "Statu" List property called "status" has items with type "Statu" Mar 1, 2017
@sebastienvermeille
Copy link
Author

Perfect ! Thank you very much Joe :)

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

No branches or pull requests

2 participants