def expected_spec(fake_jsonschema_asdataclass): message = asyncapi.Message( name='Fake Message', title='Faked', summary='Faked message', content_type='application/json', payload=fake_jsonschema_asdataclass.return_value, ) return asyncapi.Specification( info=asyncapi.Info( title='Fake API', version='0.0.1', description='Faked API', ), servers={ 'development': asyncapi.Server( name='development', url='fake.fake', protocol=asyncapi.ProtocolType.KAFKA, description='Fake Server', ) }, channels={ 'fake': asyncapi.Channel( name='fake', description='Fake Channel', subscribe=asyncapi.Operation( operation_id='fake_operation', message=message, ), publish=asyncapi.Operation(message=message), ) }, components=asyncapi.Components( messages={'FakeMessage': message}, schemas={ 'FakePayload': { 'type': 'object', 'properties': { 'faked': { 'type': 'integer' } }, } }, ), )
def asyncapi_components_from_asyncapi_channels( channels: typing.Iterable[asyncapi.Channel]): """ Allows to more easy generate AsyncApi docs (components sections) :param channels: :return: """ messages = list() for channel in channels: if channel.publish and channel.publish.message: messages.append(channel.publish.message) if channel.subscribe and channel.subscribe.message: messages.append(channel.subscribe.message) components = [message_to_component(message) for message in messages] return asyncapi.Components(messages=dict(components))
dev_server = asyncapi.Server( url='localhost', protocol=asyncapi.ProtocolType.REDIS, description='Development Broker Server', ) message = asyncapi.Message( name='userUpdate', title='User Update', summary='Inform about users updates', payload=UserUpdatePayload, ) user_update_channel = asyncapi.Channel( description='Topic for user updates', subscribe=asyncapi.Operation( operation_id='receive_user_update', message=message, ), publish=asyncapi.Operation(message=message), ) spec = asyncapi.Specification( info=asyncapi.Info( title='User API', version='1.0.0', description='API to manage users', ), servers={'development': dev_server}, channels={'user/update': user_update_channel}, components=asyncapi.Components(messages={'UserUpdate': message}), )