Skip to content

ApiTool raml gives error "invalid media type" with mediaType "x-www-form-urlencoded" #1050

@spensk8

Description

@spensk8

When accessing http://localhost:8080/raml this error is shown:
image

This is my App.java

package com.mycompany;

import org.jooby.Jooby;
import org.jooby.apitool.ApiTool;

public class App extends Jooby {
  {
    get("/", () -> "Hello World!");
    use("/controller", Controller.class);
    use(new ApiTool()
      .raml("/raml")
    );
  }
  public static void main(final String[] args) {
    run(App::new, args);
  }
}

And this my Controller.java

package com.mycompany;

import org.jooby.mvc.Consumes;
import org.jooby.mvc.GET;
import org.jooby.mvc.Path;
import org.jooby.mvc.Produces;

@Path("/controller")
@Consumes("application/x-www-form-urlencoded")
@Produces("application/json")
public class Controller {

    @GET
    public String salute() {
        return "hey jooby";
    }
}

The error is caused by the @Consumes("application/x-www-form-urlencoded")
I think the problem is that the generated api.raml (http://localhost:8080/raml/api.raml) is missing the mediaType property:

#%RAML 1.0
---
title: mycompany API
version: 1.0-SNAPSHOT
baseUri: http://localhost:8080/
protocols:
- HTTP
types: {}
/:
  get:
    responses:
      200:
        body:
          type: string
/controller:
  /controller:
    get:
      responses:
        200: {}

If I change the code to @Consumes("application/json") it works correctly and the api.raml contains the mediaType property:

#%RAML 1.0
---
title: mycompany API
version: 1.0-SNAPSHOT
baseUri: http://localhost:8080/
mediaType:
- application/json
protocols:
- HTTP
types: {}
/:
  get:
    responses:
      200:
        body:
          type: string
/controller:
  /controller:
    get:
      responses:
        200: {}

This also happens if the @Consumes("application/x-www-form-urlencoded") is at the method level.

Best regards

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions