I'm using swagger to auto-generate JAX-RS server side code. It works great. Regarding to the codegen behavior, I'd like to ask you a question.
Say, I have next yaml definition (this is the example to explain my question).
---
swagger: '2.0'
info:
version: 0.0.0
title: Simple API
paths:
/message:
get:
responses:
200:
description: OK
schema:
$ref: '#/definitions/message'
/secureMessage:
get:
responses:
200:
description: OK
schema:
$ref: '#/definitions/secretMessage'
definitions:
message:
type: string
secretMessage:
type: string
The generated server side java code has data model class Message.java and SecretMessage.java. Both have next toString() and toIndentString() methods by default (I'm using the default template).
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Message {\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
Basically, I'd like to leave these methods, but I don't want to print the value for SecretMessage.java.
How can we achieve this in generic way?
One solution is, providing a custom template and determines the definition of toString() and toIndentedString() based on the data model class name. This works fine, but we need to know the data model class names that we don't want to print the value in advance. It is not smart.
It may be a shallow brained idea, but I'm feeling that it's smart if we could direct this kind of things in yaml definition. Can we customize yaml definition for swagger?
definitions:
message:
type: string
secretMessage:
type: string
option: doNotPrintItsValueInLog
Probably, there should be smarter way. Please provide me some suggestion.
thanks in advance.