0

with swagger you can annotate your java beans as models. Ex:

@ApiModel(value="xyz")
public class object1 {
@ApiModelProperty(name = "property1")
private String abc;
}

I want to load the strings "property1" & "xyz" from an external file in spring. any recommendations on how to do that?

Bharath
  • 1,787
  • 1
  • 20
  • 37

1 Answers1

1

Is that external file a swagger spec? If so, you could turn this around, and generate code from your spec. - Contract first.

For example you can use https://github.com/swagger-api/swagger-codegen to generate your model and even API interfaces (the operations) classes and then use them in your code.

I am using the springboot templates the swagger-codegen comes with.

java -jar swagger-codegen-cli.jar generate \
  -i <input swagger spec> -l spring --library spring-boot

It also has options for specifying the package names of the generated code.

hagbard
  • 695
  • 3
  • 13
  • hey @hagbard. thanks for your response. http://stackoverflow.com/questions/39107413/spring-boot-externalize-config-properties-messages-on-java-annotations .. this is what i was referring to. can i do this using codegen? – Bharath Aug 24 '16 at 19:48
  • Not exactly. You would need to regenerate the files whenever the spec changes. Which is the approach I went with. It seems you are going a code-first approach here. If Springfox supports this, I unfortunately don't know. Just wanted to hint at a different solution. Not sure if that's helpful to you though. :) – hagbard Aug 30 '16 at 14:44