swagger-inflector icon indicating copy to clipboard operation
swagger-inflector copied to clipboard

Load ExceptionMapper from config placed in resources

Open donduni opened this issue 8 years ago • 0 comments

Hi,

If I understand the source code correctly, it should be possible to specify custom ExceptionMappers from the config file inflector.yaml. I am referring to the Configuration.java class and the following code, where the ExceptionMappers would be loaded iside the read(configLocation) method call.

      ...
        String configLocation = System.getProperty("config", "inflector.yaml");
        System.out.println("loading inflector config from " + configLocation);
        if(configLocation != null) {
          try {
            return read(configLocation);
          }
          catch (Exception e) {
            // continue
            LOGGER.warn("couldn't read inflector config from system property");
          }
        }
      ...

If the config couldn't load from from system property, but instead from resources in the next block, it seems the ExceptionMappers are not loaded at all (as this would happen inside the read(configLocation) method).

      ...
        try {
            // try to load from resources
            URL url = Configuration.class.getClassLoader().getResource("inflector.yaml");
            if(url != null) {
                try {
                    Configuration config = Yaml.mapper().readValue(new File(url.getFile()), Configuration.class);
                    return config;
                } catch (Exception e) {
                  LOGGER.warn("couldn't read inflector config from resource stream");
                  // continue
                }
            }
        } catch (Exception e) {
          LOGGER.warn("Returning default configuration!");
        }
      ...

I am correct here? Would be glad for a comment.

donduni avatar Feb 21 '17 08:02 donduni