-
Notifications
You must be signed in to change notification settings - Fork 181
unable to create type array item of type object #434
Comments
Not exaclty sure what version you were using. versions:
type: array
items:
properties:
key:
type: string
required: false This is handled by the raml-java-tools project. There are examples that seem to work with your case. specifically inlineStuff:
type: array
items:
type: object
properties:
last: string The difference may be the "type: object" line. The underlying parser that was used in 3.x.x is very finicky about inline types (sometimes having them behave differently...). |
Which version are you using ? |
|
Strange issue: As you suggested i used this plugin,
compile successful, generated stubs only for 'uses' section(refer below), but skipped for the entire body of RAML, didn't generate any stubs for my endpoints.
With the same raml, i used raml-to-jaxrs-maven-plugin, it successfully generated stubs, but only trick is i need to use (ramltopojo.types) annotation as mentioned in my original post, which i would like to avoid. |
Ok, cool. The raml to pojo plugin only generates types defined in the raml files. It handles the types, whether they be inline or straight up standalone types. The raml-to-jaxrs plugin generates the endpoints and calls the raml-to-pojo code when it finds an inline type defined in its endpoints (except for jsonschema types and xmlschema types, which you are not using). So errors when generating types (like the one you were (are) getting with arrays) are the responsibility of raml-to-pojo. The thing I'm not understanding is why in my examples (in the raml-to-pojo project) the generation works (without the annotation) There is another piece of software that I'm relying on called the raml-java-parser. This parser is being deprecated and has many issues (relative to inline types): one of them is it handles inline arrays in unpredictable ways (sometimes it calls the items objects, sometimes their proper type...). It's very annoying. It's what is happening around your type. However, from trying to understand what you are trying to do, I seem to have examples that work at generating the code properly. It's just that your raml has issues that trigger the parser problem. So this is a bit of a shot in the dark, but change: versions:
type: array
items:
properties:
key:
type: string
required: false to: ```yaml
versions:
type: array
items:
type: object # <------- this
properties:
key:
type: string
required: false And run the raml-for-jaxrs stuff again (and remove the annotation). |
Sorry for the delay in response. same error:
Not Working:
with annotation, it's working:
pom.xml:
|
Please rename the attached file extension to .raml This is the file i am facing issue with type: object. If i use annotation it's working like charm. As soon as i remove annotation i get error. For your reference i created a shorter raml file attached. |
I've tried your raml and I can't get it to work. Inline types for array item types have a bug in the parser that should I make your case work would break simpler examples like "something[]" and such. Ok, here's where we are (considering the limitations in the parser). The good news is that the next versions (of raml-for-jaxrs and raml-java-tool) is based on the AMF parser, which is much more rugged. I've checked and it would parse your type perfectly. But they aren't done yet. |
Just for fun, next version generates: public interface AAAAAAAAAA {
String getMyname();
void setMyname(String myname);
VersionsType getVersions();
void setVersions(VersionsType versions);
Map<String, Object> getAdditionalProperties();
void setAdditionalProperties(String key, Object value);
class VersionsType extends ArrayList<VersionsType.ItemsType> {
public interface ItemsType {
String getKey();
void setKey(String key);
String getValue();
void setValue(String value);
Map<String, Object> getAdditionalProperties();
void setAdditionalProperties(String key, Object value);
}
public static class ItemsTypeImpl implements ItemsType {
private String key;
private String value;
private Map<String, Object> additionalProperties = new ExcludingMap();
public String getKey() {
return this.key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
public Map<String, Object> getAdditionalProperties() {
return additionalProperties;
}
public void setAdditionalProperties(String key, Object value) {
this.additionalProperties.put(key, value);
}
}
}
} |
Thanks for the update. With this annotation i get similar output.
|
Hi,
Upon running below command, i see array related exception.
java -jar ./target/raml-to-jaxrs-cli-<version>-jar-with-dependencies.jar -d /tmp -r foo.bar ../examples/maven-examples/raml-defined-example/src/main/resources/types_user_defined.raml
Sample from raml, can you please help, i have many type: array in my raml. I see similar kind of issues raised multiple times, but most of them suggested me to remove type: array. But in my case it would be too much of manual work.
Exception:
It resolved my issue after adding this annotation as below:
But I am not willing to change the original RAML file, is there any other solution.
The text was updated successfully, but these errors were encountered: