मैं springfox-swagger2
2.7.0
के साथ एक स्प्रिंग बूट परियोजना है पर ध्यान नहीं देता और मैं निम्नलिखित नियंत्रक है:अकड़ @ApiParam कुछ गुण
@Api(tags = { "Some" }, description = "CRUD for Some Stuff")
@RestController
@RequestMapping(path = "/some")
public class SomeController {
@ApiOperation(value = "Get some")
@GetMapping(value = "{someId}", produces = MediaType.APPLICATION_JSON_VALUE)
public Response getSomeById(@PathVariable("someId") Id someId) {
return ...;
}
...
}
मैं Id
वर्ग व्याख्या से क्या डॉक्स में प्रदर्शित किया जाता है को नियंत्रित करना चाहते हैं, और इस केवल एनोटेशन के कुछ हिस्सों के लिए काम कर रहा है, लेकिन सभी नहीं। Id
वर्ग (जो एक पंजीकृत कनवर्टर String
से Id
गया है):
public class Id {
@ApiParam(value = "This is the description", defaultValue = "1f1f1f",required = true, name = "someId", type = "string")
private final Long id;
public Id(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
}
अब Swagger JSON
लौटे दिखता है इस प्रकार है:
"parameters":[{
"name":"id",
"in":"query",
"description":"This is the description",
"required":true,
"type":"integer",
"default":"1f1f1f",
"format":"int64"
}]
मेरा प्रश्न (या संभवतः बग रिपोर्ट) है: क्यों कर रहे हैं @ApiParam
एनोटेशन के कुछ हिस्सों का उपयोग किया गया (जैसे value
, defaultValue
और required
), लेकिन अन्य name
और type
जैसे नहीं हैं? ऐसा क्यों लगता है कि मैं name
या type
को यहां नहीं बदल सकता? मेरे विशेष उपयोग के मामले के लिए, उत्तरार्द्ध वह है जिसे मैं string
में बदलना चाहता हूं।
अद्यतन
मैं skadya की मदद से निम्नलिखित घटक जोड़ने पर बसे है।
@Component
public class OverrideSwaggerApiParamBuilder implements
ExpandedParameterBuilderPlugin {
@Override
public boolean supports(DocumentationType type) {
return DocumentationType.SWAGGER_2 == type;
}
@Override
public void apply(ParameterExpansionContext context) {
Optional<ApiParam> apiParamOptional = findApiParamAnnotation(context.getField().getRawMember());
if (apiParamOptional.isPresent()) {
ApiParam param = apiParamOptional.get();
context.getParameterBuilder()
.name(param.name())
.modelRef(new ModelRef(param.type()))
.build();
}
}
}
springfox के लेखक लगता है कि यह एक बग हो सकता है: https://github.com/springfox/springfox/issues/2107
आखिरकार यह चाल चल गई, मैंने कोड को थोड़ा और सरल बनाने के लिए थोड़ा सा बदल दिया और प्रकार को सेट करने के लिए 'modelRef()' का उपयोग किया। मैंने अपने प्रश्न को प्रतिबिंबित करने के लिए अद्यतन किया है। –