Git Product home page Git Product logo

asyncapigo's Introduction

AsyncAPI spec generator from Golang code

Go Reference

Installation

go install github.com/asyncapi-go/asyncapigo@latest

Example

Following Go code (full example)

package amqp

import "time"

// @title System controller
// @version Mark 1
// @description System management service

type EmergencyCommand struct {
	// Confirmation code, written on a piece of paper under the main boss's keyboard
	ConfirmationCode string `json:"confirmation_code" example:"endgame"`

	Timeout int `json:"timeout" description:"Time in seconds until execution" example:"3" validate:"min=3"`
}

// EmergencyButton asyncApi
// @summary complete data destruction
// @description Deleting all existing data and resetting the system
// @payload amqp.EmergencyCommand
// @queue emergency
// @tags emergency
// @contentType application/json
func EmergencyButton(payload EmergencyCommand) {
	if payload.ConfirmationCode != "1234" {
		panic("incorrect confirmation code")
		return
	}
	time.Sleep(time.Duration(payload.Timeout) * time.Second)
	
	// todo `sudo rm -rf /`
}

After executing

asyncapigo -d ./example/basic --out ./example/basic/asyncapi.yaml

transform to...

asyncapi: 2.4.0
info:
    title: System controller
    version: Mark 1
    description: System management service
channels:
    emergency:
        publish:
            message:
                oneOf:
                    - $ref: '#/components/messages/emergency.publish.EmergencyButton'
components:
    messages:
        emergency.publish.EmergencyButton:
            tags:
                - name: emergency
            payload:
                $ref: '#/components/schemas/amqp.EmergencyCommand'
            summary: complete data destruction
            description: Deleting all existing data and resetting the system
    schemas:
        amqp.EmergencyCommand:
            type: object
            properties:
                confirmation_code:
                    description: |
                        Confirmation code, written on a piece of paper under the main boss's keyboard
                    example: endgame
                    type: string
                timeout:
                    description: Time in seconds until execution
                    example: 3
                    type: integer
                    minimum: 3

Documentation

Info

Support following tags

  • title
  • version
  • description
  • termsOfService
  • contact.name
  • contact.url
  • contact.email
  • license.name
  • license.url

Handlers

Support following tags

  • summary
  • description
  • header multiple tag
  • tag,tags
  • operation subscribe / publish (default)
  • queue
  • payload type name with package (pkg.Type)
  • contentType

Struct field tags

  • validate - min,max,gt,ls,required,oneOf
  • format
  • example
  • description allowed in field comment too
  • required

Header parameters

  • required
  • type
  • description
  • example
  • format

asyncapigo's People

Contributors

cptidea avatar disinterpreter avatar

Stargazers

 avatar  avatar  avatar

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.