Skip to content

haz4j/swagger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swagger 4 JSON-RPC

About

This project is implementation of Swagger for JSON-RPC with usage of jsonrpc4j

Demo project

Find sources of demo project here: https://github.com/haz4j/swagger4jsonrpc-demo

Usage

How to add swagger magic to your typical jsonrpc4j application?

pom.xml: add swagger annotations and swagger4jsonrpc

    <dependencies>
        <!--spring boot, jsonrpc4j, etc-->
        ...

        <!--add this to generate swagger-ui.html page-->
        <dependency>
            <groupId>com.github.haz4j</groupId>
            <artifactId>swagger4jsonrpc</artifactId>
            <version>0.0.3</version>
        </dependency>
    </dependencies>

Configuration: add @EnableSwagger4JsonRpc and bean Docket

@SpringBootApplication
@Configuration
@EnableSwagger4JsonRpc //add this to enable swagger
public class Config {

    //add this to customize swagger 
    @Bean
    public Docket docket(){
        return Docket.builder().build();
    }

    public static void main(String[] args) {
        SpringApplication.run(Config.class, args);
    }

    @Bean
    @Autowired
    public static AutoJsonRpcServiceImplExporter autoJsonRpcServiceImplExporter() {
        return new AutoJsonRpcServiceImplExporter();
    }
}

Interface: add @Api

@JsonRpcService("/v1/api")
@Api(tags = "api", value = "api") //add this to let swagger know that you want to see it
//on swagger-ui page
public interface ApiInterface {
    Integer save(@JsonRpcParam(value = "value") Integer value);
}

Implementation: do nothing :)

@Service
@AutoJsonRpcServiceImpl
public class Impl implements ApiInterface {
    @Override
    public Integer save(Integer value){
        return value;
    }
}

Launch your spring boot app and check out http://app-path/swagger-ui.html

swagger-ui.html

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published