Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AsyncAPI v3.0.0 support #1624

Merged
merged 149 commits into from
Sep 10, 2024
Merged

Add AsyncAPI v3.0.0 support #1624

merged 149 commits into from
Sep 10, 2024

Conversation

KrySeyt
Copy link
Contributor

@KrySeyt KrySeyt commented Jul 27, 2024

Description

Fixes #980

Now AsyncAPI 3.0.0 generation supported

Example:

from faststream import FastStream
from faststream.asyncapi.version import AsyncAPIVersion
from faststream.kafka import KafkaBroker

broker = KafkaBroker("localhost:9092")

@broker.publisher("test_2")
@broker.subscriber("test_1")
async def test_topic(msg: str) -> str: ...

app = FastStream(broker)
faststream docs gen main:app
{
  "info": {
    "title": "FastStream",
    "version": "0.1.0",
    "description": ""
  },
  "asyncapi": "3.0.0",
  "defaultContentType": "application/json",
  "servers": {
    "development": {
      "host": "localhost:9092",
      "pathname": "",
      "protocol": "kafka",
      "protocolVersion": "auto"
    }
  },
  "channels": {
    "test_1:TestTopic": {
      "address": "test_1:TestTopic",
      "servers": [
        {
          "$ref": "#/servers/development"
        }
      ],
      "messages": {
        "SubscribeMessage": {
          "$ref": "#/components/messages/test_1:TestTopic:SubscribeMessage"
        }
      },
      "bindings": {
        "kafka": {
          "topic": "test_1",
          "bindingVersion": "0.4.0"
        }
      }
    },
    "test_2:Publisher": {
      "address": "test_2:Publisher",
      "servers": [
        {
          "$ref": "#/servers/development"
        }
      ],
      "messages": {
        "Message": {
          "$ref": "#/components/messages/test_2:Publisher:Message"
        }
      },
      "bindings": {
        "kafka": {
          "topic": "test_2",
          "bindingVersion": "0.4.0"
        }
      }
    }
  },
  "operations": {
    "test_1:TestTopicSubscribe": {
      "action": "receive",
      "messages": [
        {
          "$ref": "#/channels/test_1:TestTopic/messages/SubscribeMessage"
        }
      ],
      "channel": {
        "$ref": "#/channels/test_1:TestTopic"
      }
    },
    "test_2:Publisher": {
      "action": "send",
      "messages": [
        {
          "$ref": "#/channels/test_2:Publisher/messages/Message"
        }
      ],
      "channel": {
        "$ref": "#/channels/test_2:Publisher"
      }
    }
  },
  "components": {
    "messages": {
      "test_1:TestTopic:Message": {
        "title": "test_1:TestTopic:Message",
        "correlationId": {
          "location": "$message.header#/correlation_id"
        },
        "payload": {
          "$ref": "#/components/schemas/TestTopic:Message:Payload"
        }
      },
      "test_2:Publisher:Message": {
        "title": "test_2:Publisher:Message",
        "correlationId": {
          "location": "$message.header#/correlation_id"
        },
        "payload": {
          "$ref": "#/components/schemas/test_2:Publisher:Message:Payload"
        }
      }
    },
    "schemas": {
      "TestTopic:Message:Payload": {
        "title": "TestTopic:Message:Payload",
        "type": "string"
      },
      "test_2:Publisher:Message:Payload": {
        "title": "test_2:Publisher:Message:Payload",
        "type": "string"
      }
    }
  }
}

Additional updates

CLI changes:

AsyncAPI generation --version flag

You can select AsyncAPI version for gen with --version flag.

Possible values:

  • 3.0.0 (default)
  • 2.6.0

Example:
faststream docs gen main:app --version=3.0.0

Docs serve supports AsyncAPI 3.0.0

faststream docs serve asyncapi.json supports AsyncAPI 3.0.0

FastAPI integration changes

/{schema_url} now returns AsyncAPI 3.0.0 instead of 2.6.0

Schema components structure changed:

Tag, License, etc moved to faststream.specification.schema

Example:

from faststream.specification.schema.license import License
from faststream.specification.schema.tag import Tag
from faststream.specification.schema.docs import ExternalDocs

Type of change

  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a fix or feature that would disrupt existing functionality)
  • This change requires a documentation update

Checklist

  • My code adheres to the style guidelines of this project (scripts/lint.sh shows no errors)
  • I have conducted a self-review of my own code
  • I have made the necessary changes to the documentation
  • My changes do not generate any new warnings
  • I have added tests to validate the effectiveness of my fix or the functionality of my new feature
  • Both new and existing unit tests pass successfully on my local environment by running scripts/test-cov.sh
  • I have ensured that static analysis tests are passing by running scripts/static-analysis.sh
  • I have included code examples to illustrate the modifications

@KrySeyt KrySeyt marked this pull request as draft July 27, 2024 08:23
@KrySeyt
Copy link
Contributor Author

KrySeyt commented Aug 16, 2024

100 commits 🎂

@KrySeyt KrySeyt marked this pull request as ready for review August 18, 2024 18:54
@Lancetnik Lancetnik added this to the 0.6.0 milestone Aug 23, 2024
@Lancetnik Lancetnik added the enhancement New feature or request label Aug 23, 2024
@Lancetnik Lancetnik changed the base branch from main to 0.6.0 September 8, 2024 11:33
@Lancetnik Lancetnik marked this pull request as draft September 8, 2024 11:33
@Lancetnik Lancetnik marked this pull request as ready for review September 8, 2024 11:33
@Lancetnik Lancetnik removed the request for review from kumaranvpl September 8, 2024 11:33
@Lancetnik
Copy link
Member

Can u please @KrySeyt fix pre-commit?

@Lancetnik Lancetnik merged commit 346a67a into airtai:0.6.0 Sep 10, 2024
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

AsyncAPI 3.0 support
3 participants