DEV Community

loading...

Discussion on: Are there any API specification formats for WebSockets?

Collapse
idanarye profile image
Idan Arye Author

Still seems thin in the language support department - only thing added since I posted this almost a year ago is node.js templates.

I did find this ticket though - github.com/asyncapi/generator/issu... - which suggests using something like quicktype.io/. So maybe I should just use quicktype?

Collapse
derberg profile image
Lukasz Gornicki

Last year was fully focused on releasing AsyncAPI 2.0, so getting the spec more mature.
This year we focus on tooling. Come and join us.

Quicktype will generate just types for you, this is why we want to integrate it in generator for code templates. But it cannot really replace generator.

What is that you exactly need except of the spec? What do you want to get out of the spec?

Thread Thread
idanarye profile image
Idan Arye Author

I need the specs to describe the methods that can be sent. Each method needs to describe:

  1. Its name.
  2. Its fields (and their possibly deep types)
  3. What it returns.
  4. Free text to describe what it does.

Ideally I'd like something that can generate the full API. For example, if I have

- name: foo
  parameters:
    - name: bar
      type: integer
    - name: baz
      type: text
  returns:
    - name: x
      type: float
    - name: y
      type: float
  doc: bla bla bla

It would generate, say for Java:

public class FooResult {
    private float x;
    private float y;

    public FooResult(float x, float y) {
        this.x = x;
        this.y = y;
    }

    public float getX() {
        return x;
    }

    public float getY() {
        return y;
    }
}

public abstract class AbstractAPI {
    protected abstract Value call(String method, Value parameters);

    /**
     * bla bla bla
     */
    public FooResult foo(int bar, String baz) {
        Value request = new Value();
        request.setInt("bar", bar);
        request.setString("baz", baz);

        Value result = call("foo", request);

        return FooResult(result.getFloat("x"), result.getFloat("y"));
    }
}

And then you'll just have to subclass AbstractAPI (yes, I know) and implement call and you'll get fully typed access to the entire API.