Spring Boot闆嗘垚smart-doc鐢熸垚api鏂囨。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring Boot闆嗘垚smart-doc鐢熸垚api鏂囨。相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/filters' title='filters'>filters   res   href   javabean   鍩轰簬鎺ュ彛   api   local   html   java   

smart-doc鏄竴涓猨ava restful api鏂囨。鐢熸垚宸ュ叿锛宻mart-doc棰犺浜嗕紶缁熺被浼約wagger杩欑澶ч噺閲囩敤娉ㄨВ渚靛叆鏉ョ敓鎴愭枃妗g殑瀹炵幇鏂规硶銆俿mart-doc瀹屽叏鍩轰簬鎺ュ彛婧愮爜鍒嗘瀽鏉ョ敓鎴愭帴鍙f枃妗o紝瀹屽叏鍋氬埌闆舵敞瑙d镜鍏ワ紝浣犲彧闇€瑕佹寜鐓ava鏍囧噯娉ㄩ噴鐨勫啓锛宻mart-doc灏辫兘甯綘鐢熸垚涓€涓畝鏄撴槑浜嗙殑markdown鎴栨槸涓€涓儚GitBook鏍峰紡鐨勯潤鎬乭tml鏂囨。銆?br/>涓嬮潰灏嗕粙缁嶅浣曞湪Spring Boot椤圭洰涓泦鎴恠mart-doc鐢熸垚涓€涓畝鏄庣殑api鏂囨。銆?/p>

娉ㄦ剰锛?/strong> smart-doc宸茬粡琚紑婧愪腑鍥芥敹褰曪紝骞朵笖寮€濮嬭鍥藉唴寰堝寮€鍙戣€呬娇鐢ㄥ埌鑷繁椤圭洰涓揩閫熺敓鎴愭帴鍙f枃妗c€?/p>

smart-doc鍔熻兘

  • 闆舵敞瑙c€侀浂瀛︿範鎴愭湰銆佸彧闇€瑕佸啓鏍囧噯java娉ㄩ噴銆?/li>
  • 鍩轰簬婧愪唬鐮佹帴鍙e畾涔夎嚜鍔ㄦ帹瀵硷紝寮哄ぇ鐨勮繑鍥炵粨鏋勬帹瀵笺€?/li>
  • 鏀寔Spring MVC,Spring Boot,Spring Boot Web Flux(controller涔﹀啓鏂瑰紡)銆?/li>
  • 鏀寔Callable,Future,CompletableFuture绛夊紓姝ユ帴鍙h繑鍥炵殑鎺ㄥ銆?/li>
  • 鏀寔JavaBean涓婄殑JSR303鍙傛暟鏍¢獙瑙勮寖銆?/li>
  • 瀵筳son璇锋眰鍙傛暟鐨勬帴鍙h兘澶熻嚜鍔ㄧ敓鎴愭ā鎷焜son鍙傛暟銆?/li>
  • 瀵逛竴浜涘父鐢ㄥ瓧娈靛畾涔夎兘澶熺敓鎴愭湁鏁堢殑妯℃嫙鍊笺€?/li>
  • 鏀寔鐢熸垚json杩斿洖鍊肩ず渚嬨€?/li>
  • 鏀寔浠庨」鐩閮ㄥ姞杞芥簮浠g爜鏉ョ敓鎴愬瓧娈垫敞閲?鍖呮嫭鏍囧噯瑙勮寖鍙戝竷鐨刯ar鍖?銆?/li>
  • 鏀寔鐢熸垚澶氱鏍煎紡鏂囨。锛歁arkdown銆丠TML5銆丄sciidoctor銆?/li>
  • 杞绘槗瀹炵幇鍦⊿pring Boot鏈嶅姟涓婂湪绾挎煡鐪嬮潤鎬丠TML5 api鏂囨。銆?/li>
  • 寮€鏀炬枃妗f暟鎹紝鍙嚜鐢卞疄鐜版帴鍏ユ枃妗g鐞嗙郴缁熴€?

    鍦⊿pring Boot椤圭洰涓泦鎴怱mart-doc

    娣诲姞smart-doc渚濊禆锛屾敞鎰忔墦鍖呭悗涓嶉渶瑕佸皢smart-doc鎵撳叆鏈€缁堢殑浜у搧鍖咃紝鍥犳鎴戞帹鑽愬彧鐢╰est绾у埆灏卞彲浠ヤ簡銆?/p>

<dependency>
    <groupId>com.github.shalousun</groupId>
    <artifactId>smart-doc</artifactId>
    <version>1.7.0</version>
    <scope>test</scope>
</dependency>

鏂板缓涓€涓璞★細

public class User {

    /**
     * 鐢ㄦ埛鍚?     */
    private String userName;

    /**
     * 鏄电О
     */
    private String nickName;

    /**
     * 鐢ㄦ埛鍦板潃
     */
    private String userAddress;

    /**
     * 鐢ㄦ埛骞撮緞
     */
    private int userAge;

    /**
     * 鎵嬫満鍙?     */
    private String phone;

    /**
     * 鍒涘缓鏃堕棿
     */
    private Long createTime;

    /**
     * ipv6
     */
    private String ipv6;

    /**
     * 鍥哄畾鐢佃瘽
     */
    private String telephone;
    //鐪佺暐get set
}

涓嬮潰鏉ユ柊寤轰竴涓猆serController锛岀劧鍚庡皢User浣滀负Controller鐨勮姹傚弬鏁板拰鍝嶅簲瀹炰綋娴嬭瘯涓媠mart-doc鏄浣曡交鏉惧畬鎴愭枃妗g敓鎴愮殑銆?/p>

@RestController
@RequestMapping("/user")
public class UserController {

    /**
     * 娣诲姞鐢ㄦ埛
     * @param user
     * @return
     */
    @PostMapping("/add")
    public User addUser(@RequestBody User user){
        return null;
    }
}

娣诲姞瀹屾垚controller鍚庯紝鎴戜滑鍦ㄩ」鐩腑鏂板缓涓€涓崟鍏冩祴璇曠被鐢ㄤ簬璺戞枃妗c€?/p>

public class ApiDocTest {

    /**
     * 鍖呮嫭璁剧疆璇锋眰澶达紝缂哄け娉ㄩ噴鐨勫瓧娈垫壒閲忓湪鏂囨。鐢熸垚鏈熶娇鐢ㄥ畾涔夊ソ鐨勬敞閲?     */
    @Test
    public void testBuilderControllersApi() {
        ApiConfig config = new ApiConfig();
        config.setServerUrl("http://localhost:8080");
        //true浼氫弗鏍艰姹傛敞閲婏紝鎺ㄨ崘璁剧疆true
        config.setStrict(true);
        //true浼氬皢鏂囨。鍚堝苟瀵煎嚭鍒颁竴涓猰arkdown
        //config.setAllInOne(true);
        //鐢熸垚html鏃跺姞瀵嗘枃妗e悕涓嶆毚闇瞔ontroller鐨勫悕绉?        config.setMd5EncryptedHtmlName(true);

        //鎸囧畾鏂囨。杈撳嚭璺緞
        //@since 1.7 鐗堟湰寮€濮嬶紝閫夋嫨鐢熸垚闈欐€乭tml doc鏂囨。鍙娇鐢ㄨ璺緞锛欴ocGlobalConstants.HTML_DOC_OUT_PATH;
        config.setOutPath("d:\md");
        // @since 1.2,濡傛灉涓嶉厤缃閫夐」锛屽垯榛樿鍖归厤鍏ㄩ儴鐨刢ontroller,
        // 濡傛灉闇€瑕侀厤缃湁澶氫釜controller鍙互浣跨敤閫楀彿闅斿紑
        config.setPackageFilters("com.power.doc.controller");

        long start = System.currentTimeMillis();
        //鑾峰彇鎺ュ彛鏁版嵁鍚庤嚜琛屽鐞?        ApiDocBuilder.builderControllersApi(config);
        long end = System.currentTimeMillis();
        DateTimeUtil.printRunTime(end, start);
    }
}

鏈€鍚庤繍琛屼竴涓嬪崟鍏冩祴璇晄mart-doc鍗冲彲鐢熸垚markdown鎺ュ彛鏂囨。鍒版寚瀹氱殑鐩綍銆?/p>

鏂囨。鐢熸垚鏁堟灉

鐢ㄦ埛淇℃伅鎿嶄綔鎺ュ彛

娣诲姞鐢ㄦ埛

URL: http://localhost:8080/user/add

Type: POST

Content-Type: application/json; charset=utf-8

Request-parameters:

Parameter Type Description Required Since
userName string 鐢ㄦ埛鍚?/td> false -
nickName string 鏄电О false -
userAddress string 鐢ㄦ埛鍦板潃 false -
userAge int 鐢ㄦ埛骞撮緞 false -
phone string 鎵嬫満鍙?/td> false -
createTime number 鍒涘缓鏃堕棿 false -
ipv6 string ipv6 false -
telephone string 鍥哄畾鐢佃瘽 false -

Request-example:

{
    "userName":"楣忛.璐?,
    "nickName":"raymond.gutkowski",
    "userAddress":"Apt. 819 钀ф梺7699鍙凤紝 绔犱笜锛?婊?852063",
    "userAge":41,
    "phone":"15018373016",
    "createTime":1569934393095,
    "ipv6":"9eb3:fada:ffd2:912e:6225:1062:a2d7:718f",
    "telephone":"15018373016"
}

Response-fields:

Field Type Description Since
userName string 鐢ㄦ埛鍚?/td> -
nickName string 鏄电О -
userAddress string 鐢ㄦ埛鍦板潃 -
userAge int 鐢ㄦ埛骞撮緞 -
phone string 鎵嬫満鍙?/td> -
createTime number 鍒涘缓鏃堕棿 -
ipv6 string ipv6 -
telephone string 鍥哄畾鐢佃瘽 -

Response-example:

{
    "userName":"楣忛.璐?,
    "nickName":"raymond.gutkowski",
    "userAddress":"Apt. 819 钀ф梺7699鍙凤紝 绔犱笜锛?婊?852063",
    "userAge":41,
    "phone":"15018373016",
    "createTime":1569934393095,
    "ipv6":"9eb3:fada:ffd2:912e:6225:1062:a2d7:718f",
    "telephone":"15018373016"
}

鏄笉鏄瘮swagger绠€鍗曞緢澶氬憿锛岃€屼笖杩樺畬鍏ㄤ笉渚靛叆浠g爜锛屽彧闇€瑕佸啓涓婃爣鍑嗙殑java doc娉ㄩ噴銆傞渶瑕佷簡瑙f洿澶氬鎯呭喌璇锋煡鐪媠mart-doc椤圭洰锛屽ソ鐢ㄨ璁板緱鐐箂tar鍝︺€?a href="https://gitee.com/sunyurepository/smart-doc" rel="nofollow">鏌ョ湅smart-doc椤圭洰

娉ㄦ剰: 鏈枃鏉ヨ嚜smart-doc鍘熶綔鑰咃紝鎮ㄥ彲浠ヨ浆杞戒絾璇峰嬁copy鍏呭綋鍘熷垱銆?/p>

以上是关于Spring Boot闆嗘垚smart-doc鐢熸垚api鏂囨。的主要内容,如果未能解决你的问题,请参考以下文章

Flume涓巏afka闆嗘垚

Kiwi Syslog Web Access涓嶢ctive Directory闆嗘垚璁よ瘉

鎸佺画闆嗘垚楂樼骇绡囦箣Jenkins cli涓嶫enkins ssh

铻嶄簯鍗虫椂閫氳SDK闆嗘垚 -- FCM鎺ㄩ€侀泦鎴愭寚鍗?Android骞冲彴)

铻嶄簯鍗虫椂閫氳SDK闆嗘垚 -- 鍥藉唴鍘傚晢鎺ㄩ€侀泦鎴愯俯鍧戠瘒(Android骞冲彴)

澶氱畻娉曠患鍚堢殑鏂囨湰鎸栨帢绯荤粺