Giter VIP home page Giter VIP logo

lerenn / asyncapi-codegen Goto Github PK

View Code? Open in Web Editor NEW
81.0 2.0 22.0 974 KB

An AsyncAPI Golang Code generator that generates all Go code from the broker to the application/user. Just plug your application to your favorite message broker!

License: Apache License 2.0

Makefile 0.65% Go 99.02% Dockerfile 0.19% Shell 0.13%
asyncapi asyncapi-generator asyncapi-tooling asyncapi-tools go golang nats nats-messaging code-generation generator

asyncapi-codegen's People

Contributors

derfenix avatar leejuyuu avatar lerenn avatar lo00l avatar magraef avatar matoous avatar mymdz avatar obouchet avatar stefanmeschke avatar thesadlig avatar wizzardich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

asyncapi-codegen's Issues

Update Makefiles

what the Readme says and what the makefiles do is a bit confusing.

Hello world generates 2 apps.

But the root README.md only shows generating one.

Perhaps just alter the hello world Makefile to also do the code gen. The sub Makefile does the docker compose running as it does now.

Add a asyncapi checker before generation

As there is no check, when there is a problem with the AsyncAPI specification, then it is not always detected.
Adding a checking before should resolve this problem.

Support queue groups in NATS implementation

For now, every listener on the NATS implementation will receive every message. In case of duplicated services, it would be necessary for just one of them to process a message, thus using the queue groups functionnality.

expose channels in generated code as constants

It would be nice to have to be able to perform compile-time/initialization time checks in the application when implementing brokers that expect some known channels for configuration and would error out on an unknown channel, becase currently broker accepts channel as a simple stream

type BrokerController interface {
	// Publish a message to the broker
	Publish(ctx context.Context, channel string, mw BrokerMessage) error

nats slog

This is just. suggestion that you may find useful ?

https://github.com/samber/slog-nats is a golang slog adapter to log into NATS

Been using it as it makes it easy as DEV and OPS time to see what's going on for a local or remote system.

Generate conversion function for schemas

Sometimes, we have a reference to a schema which is a string or an array of string (or anything else), and it would be great to be able to convert them easily.

Support AsyncAPI v3

Hi,

Thanks for this project!

I wanted to give it a try but it doesn't seem to support AsyncAPI v3.

$ asyncapi-codegen -i ./asyncapi-v3.yaml -p asyncapi -o ./asyncapi.gen.go
 --- Anomalies detected in specification ---
version "3.0.0" is not supported

Any plan to support it?

Thanks!

Bug: ClientSubscriber not generated for some document

System Info

Arch Linux
go version go1.20.6 linux/amd64
asyncapi-codegen version v0.13.1

Steps to reproduce

  1. Get this AsyncAPI spec https://github.com/derberg/shrekapp-asyncapi-designed/blob/36d42d6c08c0feca49b19fc3d02b2b20bf7f96f1/asyncapi.yaml.
  2. Convert it to 2.6.0 with AsyncAPI studio.
  3. Run asyncapi-codegen on it.
  4. ClientSubscriber contains Chat and TravelStatus methods in api.gen.go.
  5. Now, modify the subscribe operation under /travel/status channel to publish.
  6. Then the ClientSubscriber is completely missing from the generated file.

Expected result

I expected to see the ClientSubscriber contain only Chat in the end.

Override snake case for JSON struct tags

Hi.

Thanks for a great package! I was wondering if it is possible to specify a different case for the json struct tags in the generated models? I.e. have camelCase instead?

Support multi-line descriptions

For now, when generating a spec with a multi-line description, there is an error as the generated description is commented only on the first line.

This following description:

      description: |
        Status event is happening when there is no more expected event.
        An 'advance' message can be sent after this one.

Will generate this code:

// Description: Status event is happening when there is no more expected event.
An 'advance' message can be sent after this one.

And should generated this instead:

// Description: Status event is happening when there is no more expected event.
// An 'advance' message can be sent after this one.

Schema Evolution

Do you have a game plan of how your going to support Schema Evolution ?

We have things in 2 places ..
There is a schema description in the yaml and the data living inside nats that conforms to a version of the types described by the yaml schema.

this is not at all unique to your project but in fact an issue with nats itself in my opinion.

The problem is reduced if protobufs are used instead of json . It async-api wants to use json . So then a work around is if we can store the data inside nats as protobuf and convert it to json on the way in and out …
So then you won’t need to go back and adjust the pending data inside nats.

just an idea..

anyways it’s a cool project @lerenn

AsyncAPI v3: support default values

For now, when a default value is specified in the specification, it is not used.

The entity having a default value should be optionally settable, with the default value by default.

CTL, CLI, GUI

Was playing around and we could gen a lot more here if we wanted.

CTL is a pretty obvious one I think

For a GUI, we could use HTMX, which is nicely designed to work with async using SSE or Web Sockets which NATS naturally supports already.

Here is a simple golang htmx generator.
https://github.com/gowebly/gowebly is a generator that uses htmx and golang.

Add a NACK mechanism to compatible brokers

For now, when the business logic that receives a message fails, then there is no way to tell the broker.

We should be able to do this following this schema:

flowchart TB

Emitter-->Broker;
Broker-->Reception;
Reception-->BusinessLogic;
BusinessLogic-->Success;
Success--ACK-->Broker;
BusinessLogic-->Failure
Failure--NACK with or without delay-->Broker;

Json Schema question

I was wondering if async api Standard supports json Schema ?

Cause then we can use that to describe the types but also to do validation.

I am not that familiar with async-api btw.

nats uses json Schema Inside to validations its own types btw. It’s inside the packages called jsm but is not really designed for external access.

You know there is nothing preventing the json Schema or even the async-api being deployed inside nats kv. Then nats Server has the Schema inside itself to do the validations . Just an interesting way to have it all inside nats like a database has the data and schema inside itself.

Change loggers to add infos not in context but as arguments.

For now, the loggers uses additional information from context, but doing a custom logger makes it hard to get those info as each one should be unwrapped from the context.

So we should make it explicitly passed by argument in the generated code and remove the context embedding in loggers (not in the generated code though).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.