phoenixnap / springmvc-raml-plugin

Spring MVC - RAML Spec Synchroniser Plugin. A Maven plugin designed to Generate Server & Client code in Spring from a RAML API descriptor and conversely, a RAML API document from the SpringMVC Server implementation.
Apache License 2.0
136 stars 84 forks source link

additionalProperties type restriction not supported #300

Open vsusaya opened 5 years ago

vsusaya commented 5 years ago

I have the following RAML, which defines a type where I want to restrict the type of any additional properties. This is valid RAML based on the 1.0 specification. It seems that the // field is treated as having an empty string value as a name which throws an index out of bounds exception during code generation (please also see the stack trace below).

Any chance there's a known workaround?

#%RAML 1.0
title: my-raml

types:
  Items:
    type: object
    properties:
      //:
        type: string

/items:
  get:
    responses:
      200:
        body:
          application/json:
            type: Items

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0 at java.lang.String.charAt(String.java:658) at org.jsonschema2pojo.util.NameHelper.normalizeName(NameHelper.java:46) at com.phoenixnap.oss.ramlplugin.raml2code.helpers.NamingHelper.cleanNameForJava(NamingHelper.java:362) at com.phoenixnap.oss.ramlplugin.raml2code.helpers.NamingHelper.cleanNameForJava(NamingHelper.java:354) at com.phoenixnap.oss.ramlplugin.raml2code.helpers.NamingHelper.getParameterName(NamingHelper.java:342) at com.phoenixnap.oss.ramlplugin.raml2code.interpreters.ObjectTypeInterpreter.interpret(ObjectTypeInterpreter.java:171) at com.phoenixnap.oss.ramlplugin.raml2code.helpers.RamlTypeHelper.mapTypeToPojo(RamlTypeHelper.java:100) at com.phoenixnap.oss.ramlplugin.raml2code.data.ApiActionMetadata.parseResponse(ApiActionMetadata.java:228) at com.phoenixnap.oss.ramlplugin.raml2code.data.ApiActionMetadata.(ApiActionMetadata.java:78) at com.phoenixnap.oss.ramlplugin.raml2code.data.ApiResourceMetadata.addApiCall(ApiResourceMetadata.java:55) at com.phoenixnap.oss.ramlplugin.raml2code.helpers.RamlParser.checkResource(RamlParser.java:167) at com.phoenixnap.oss.ramlplugin.raml2code.helpers.RamlParser.extractControllers(RamlParser.java:77) at com.phoenixnap.oss.ramlplugin.raml2code.plugin.SpringMvcEndpointGeneratorMojo.generateEndpoints(SpringMvcEndpointGeneratorMojo.java:284) at com.phoenixnap.oss.ramlplugin.raml2code.plugin.SpringMvcEndpointGeneratorMojo.execute(SpringMvcEndpointGeneratorMojo.java:527) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) ... 21 more

vsusaya commented 5 years ago

Reusing this issue for a related question - but how do I go about using additional properties? I'm noticing that when I have a RAML object type with additionalProperties set to true, it gets generated as its own class, but that class does not have a reference to a map or other structure that would allow for setting of fields that are not predefined. I have tried this with the config <includeAdditionalProperties> set to true.