Skip to content

io.github.manusant.spark-swagger 2.0.2

Install 1/2: Add this to pom.xml:
Learn more about Maven or Gradle
<dependency>
  <groupId>io.github.manusant</groupId>
  <artifactId>spark-swagger</artifactId>
  <version>2.0.2</version>
</dependency>
Install 2/2: Run via command line
$ mvn install

About this package

Changeset

  1. Add Spark-Swagger Options configuration object as a builder.
Service spark = Service.ignite()
        .ipAddress("localhost")
        .port(8081);

Options.builder()
      .confPath(SparkSwagger.CONF_FILE_NAME)
      .version("1.0.0")
      .enableCors(true)
      .enableStaticMapping(true)
      .build();

SparkSwagger.of(spark, options)
        .endpoints(() -> Arrays.asList(new HammerEndpoint(), new ShieldEndpoint()))
        .generateDoc();
  1. Adapt Route interface to have Route and TypedRoute components
.get(path()
            .withDescription("Gets the available shields")
            .withResponseAsCollection(Shield.class), new Route() {
              @Override
              public Object onRequest(Request request, Response response) {
        
                  Shield shield = Shield.builder()
                          .id("sh_123456")
                          .name("Thor Main Shield")
                          .owner("Manuel Santos")
                          .defense(10)
                          .build();
        
                  return ok(response, Arrays.asList(shield));
              }
    })

or 

.post(path("/:id")
              .withDescription("Get Shield by ID")
              .withRequestType(BackupRequest.class)
              .withResponseType(Shield.class), new TypedRoute<BackupRequest>() {

                  @Override
                  public Object onRequest(BackupRequest body, Request request, Response response) {
                      return badRequest(response, "Invalid shield ID");
                  }
      })
  1. Fix issue with path definitions and conflict between swagger spec and actual route path
  2. Include @content annotation as a way to specify content type, marshaling and unmarshaling
.post(path("/backup")
                .withDescription("Trigger Network Backup")
                .withRequestType(BackupRequest.class)
                .withGenericResponse(),
                new TypedRoute<BackupRequest>() {
        
                    @Content(ContentType.APPLICATION_JSON)
                    public Object onRequest(BackupRequest body, Request request, Response response) {
                        return badRequest(response, "Backup Name required in order to backup Network Data");
                    }
        })
  1. Fix swagger specification for responseAsCollection
  2. Add option for responseAsMap
.get(path("/options")
            .withDescription("Gets all shield options")
            .withResponseAsMap(Shield.class), new Route() {
              @Override
              public Object onRequest(Request request, Response response) {
      
                  Map<String, Shield> shields = new HashMap<>();
      
                  Shield thor = Shield.builder()
                          .id("sh_123456")
                          .name("Thor Shield")
                          .owner("Manuel Santos")
                          .defense(50)
                          .build();
                  shields.put("thor",thor);
      
                  Shield loki = Shield.builder()
                          .id("sh_255678")
                          .name("Loki Shield")
                          .owner("Manuel Santos")
                          .defense(20)
                          .build();
                  shields.put("loki",loki);
      
                  return ok(response, shields);
              }
    })
  1. Fix issue supplying version config
  2. Include static mapping enable config
  3. Add option to load UI resources from project resources besides from artifact jar, locally (for testing purpose)

Details

  • @manusant manusant
  • December 10, 2021
  • 10 dependencies
  • Apache License 2.0

Download activity

  • Total downloads 143
  • Last 30 days 3
  • Last week 2
  • Today 0


Recent versions

View all