forked from loafle/openapi-generator-original
Merge pull request #2108 from swagger-api/issue-2107
added example value
This commit is contained in:
commit
fe2715c1e6
@ -593,6 +593,9 @@ public class DefaultCodegen {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("static-method")
|
@SuppressWarnings("static-method")
|
||||||
public String toExampleValue(Property p) {
|
public String toExampleValue(Property p) {
|
||||||
|
if(p.getExample() != null) {
|
||||||
|
return p.getExample().toString();
|
||||||
|
}
|
||||||
if (p instanceof StringProperty) {
|
if (p instanceof StringProperty) {
|
||||||
return "null";
|
return "null";
|
||||||
} else if (p instanceof BooleanProperty) {
|
} else if (p instanceof BooleanProperty) {
|
||||||
|
@ -63,8 +63,15 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processOpts()
|
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||||
{
|
super.postProcessModelProperty(model, property);
|
||||||
|
if("null".equals(property.example)) {
|
||||||
|
property.example = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processOpts() {
|
||||||
super.processOpts();
|
super.processOpts();
|
||||||
|
|
||||||
if ( additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER) ) {
|
if ( additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER) ) {
|
||||||
|
@ -14,8 +14,13 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
|
|||||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||||
* maximum: {{maximum}}{{/maximum}}
|
* maximum: {{maximum}}{{/maximum}}
|
||||||
**/
|
**/
|
||||||
|
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||||
|
this.{{name}} = {{name}};
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
{{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}}
|
{{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}}
|
||||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
@ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||||
@JsonProperty("{{baseName}}")
|
@JsonProperty("{{baseName}}")
|
||||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||||
return {{name}};
|
return {{name}};
|
||||||
|
@ -14,8 +14,13 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
|
|||||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||||
* maximum: {{maximum}}{{/maximum}}
|
* maximum: {{maximum}}{{/maximum}}
|
||||||
**/
|
**/
|
||||||
|
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||||
|
this.{{name}} = {{name}};
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
{{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}}
|
{{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}}
|
||||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
@ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||||
@JsonProperty("{{baseName}}")
|
@JsonProperty("{{baseName}}")
|
||||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||||
return {{name}};
|
return {{name}};
|
||||||
|
@ -24,7 +24,7 @@ import javax.ws.rs.core.SecurityContext;
|
|||||||
public class {{classname}}ServiceImpl extends {{classname}}Service {
|
public class {{classname}}ServiceImpl extends {{classname}}Service {
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
@Override
|
@Override
|
||||||
public Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}},{{/allParams}}SecurityContext securityContext)
|
public Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}}, {{/allParams}}SecurityContext securityContext)
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
// do some magic!
|
// do some magic!
|
||||||
return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
|
return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
|
||||||
|
@ -14,8 +14,13 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
|
|||||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||||
* maximum: {{maximum}}{{/maximum}}
|
* maximum: {{maximum}}{{/maximum}}
|
||||||
**/
|
**/
|
||||||
|
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||||
|
this.{{name}} = {{name}};
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
{{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}}
|
{{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}}
|
||||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
@ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||||
@JsonProperty("{{baseName}}")
|
@JsonProperty("{{baseName}}")
|
||||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||||
return {{name}};
|
return {{name}};
|
||||||
|
@ -32,7 +32,8 @@ public class JavaModelTest {
|
|||||||
final Model model = new ModelImpl()
|
final Model model = new ModelImpl()
|
||||||
.description("a sample model")
|
.description("a sample model")
|
||||||
.property("id", new LongProperty())
|
.property("id", new LongProperty())
|
||||||
.property("name", new StringProperty())
|
.property("name", new StringProperty()
|
||||||
|
.example("Tony"))
|
||||||
.property("createdAt", new DateTimeProperty())
|
.property("createdAt", new DateTimeProperty())
|
||||||
.required("id")
|
.required("id")
|
||||||
.required("name");
|
.required("name");
|
||||||
@ -66,6 +67,7 @@ public class JavaModelTest {
|
|||||||
Assert.assertEquals(property2.name, "name");
|
Assert.assertEquals(property2.name, "name");
|
||||||
Assert.assertEquals(property2.defaultValue, "null");
|
Assert.assertEquals(property2.defaultValue, "null");
|
||||||
Assert.assertEquals(property2.baseType, "String");
|
Assert.assertEquals(property2.baseType, "String");
|
||||||
|
Assert.assertEquals(property2.example, "Tony");
|
||||||
Assert.assertTrue(property2.hasMore);
|
Assert.assertTrue(property2.hasMore);
|
||||||
Assert.assertTrue(property2.required);
|
Assert.assertTrue(property2.required);
|
||||||
Assert.assertTrue(property2.isNotContainer);
|
Assert.assertTrue(property2.isNotContainer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user