Пример #1
0
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'
                        }
                    },
                }
            },
        ),
    )
Пример #2
0
def message_to_channel(
        message: asyncapi.Message,
        response: asyncapi.Message = None,
        publish_made_first=False,
        description: str = None) -> typing.Tuple[str, asyncapi.Channel]:
    if publish_made_first:
        first_action, second_action = 'publish', 'subscribe'
    else:
        first_action, second_action = 'subscribe', 'publish'

    channel_kwargs = {
        'description': description,
        first_action: asyncapi.Operation(message=message, )
    }
    if response:
        channel_kwargs[second_action] = asyncapi.Operation(message=response, )

    return message.name, asyncapi.Channel(**channel_kwargs)
Пример #3
0
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}),
)
Пример #4
0
    name: Optional[str] = None
    age: Optional[int] = None


dev_server = asyncapi.Server(
    url='asyncapi-local',
    protocol=asyncapi.ProtocolType.GCLOUD_PUBSUB,
    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',
    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}),
)
Пример #5
0
dev_server = asyncapi.Server(
    url='localhost',
    protocol=asyncapi.ProtocolType.REDIS,
    description='Development Broker Server',
)
message = asyncapi.Message(
    name='templateEvent',
    title='Template Event',
    summary='Template Event description',
    payload=TemplateEvent,
)
user_update_channel = asyncapi.Channel(
    description='Topic for template events',
    subscribe=asyncapi.Operation(
        operation_id='receive_template_event',
        message=message,
    ),
    publish=asyncapi.Operation(message=message),
)

api = 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}),
)