├── .gitattributes ├── asyncapi-cli └── src │ ├── test │ ├── resources │ │ ├── specs │ │ │ ├── spec-without-identifier-path.yml │ │ │ ├── spec-with-identifier-path-missing-path.yml │ │ │ ├── spec-with-identifier-path-missing-type.yml │ │ │ ├── spec-with-event-identifier-missing-header-name.yml │ │ │ ├── spec-with-identifier-path.yml │ │ │ ├── spec-with-event-identifier-invalid-type.yml │ │ │ ├── spec-with-event-identifier-valid-header-type.yml │ │ │ ├── spec-single-schema-with-enum.yml │ │ │ ├── spec-single-schema-with-unrecognized-type.yml │ │ │ ├── spec-single-schema-with-invalid-number-format.yml │ │ │ ├── spec-single-channel-missing-x-event-type-without-oneof.yml │ │ │ ├── spec-single-channel-missing-reference.yml │ │ │ ├── spec-single-channel-missing-x-event-type-with-oneof.yml │ │ │ ├── spec-single-channel-missing-payload.yml │ │ │ └── spec-single-channel-with-inline-schema.yml │ │ ├── websockets │ │ │ ├── out │ │ │ │ ├── .gitignore │ │ │ │ └── placeholder.txt │ │ │ ├── asyncapi-to-ballerina │ │ │ │ ├── client │ │ │ │ │ ├── baloutputs │ │ │ │ │ │ ├── Real │ │ │ │ │ │ │ └── gemini_websocket.bal │ │ │ │ │ │ ├── PathParam │ │ │ │ │ │ │ └── path_param_with_ref_schema.bal │ │ │ │ │ │ ├── HeaderParam │ │ │ │ │ │ │ ├── header_parameter_types.bal │ │ │ │ │ │ │ └── header_param_with_default_value.bal │ │ │ │ │ │ ├── QueryParam │ │ │ │ │ │ │ ├── query_param_without_default_value.bal │ │ │ │ │ │ │ ├── query_param_with_default_value.bal │ │ │ │ │ │ │ └── query_param_with_ref_schema.bal │ │ │ │ │ │ └── Util │ │ │ │ │ │ │ └── default_util.bal │ │ │ │ │ ├── InvalidResponse │ │ │ │ │ │ ├── int_type_response.yaml │ │ │ │ │ │ ├── boolean_type_response.yaml │ │ │ │ │ │ ├── float_type_response.yaml │ │ │ │ │ │ ├── string_type_response.yaml │ │ │ │ │ │ └── map_type_response.yaml │ │ │ │ │ ├── CloseFrame │ │ │ │ │ │ └── license.txt │ │ │ │ │ └── diagnostic_files │ │ │ │ │ │ ├── json_payload.yaml │ │ │ │ │ │ ├── xml_payload.yaml │ │ │ │ │ │ ├── duplicated_response.yaml │ │ │ │ │ │ └── xml_payload_with_ref.yaml │ │ │ │ ├── schema │ │ │ │ │ ├── baloutputs │ │ │ │ │ │ ├── OneOf │ │ │ │ │ │ │ ├── oneOfAsProperties.bal │ │ │ │ │ │ │ ├── twoOneOf.bal │ │ │ │ │ │ │ ├── twoOneOfWithObjectType.bal │ │ │ │ │ │ │ ├── nestedOneOfWithAllOf.bal │ │ │ │ │ │ │ └── oneOfWithInlineSchemas.bal │ │ │ │ │ │ ├── AllOf │ │ │ │ │ │ │ ├── nested_allOf_with_allOf.bal │ │ │ │ │ │ │ ├── allOfWithEmptyObject.bal │ │ │ │ │ │ │ ├── oneAllOf.bal │ │ │ │ │ │ │ ├── allOf_with_one_ref.bal │ │ │ │ │ │ │ ├── allOf_with_cyclic.bal │ │ │ │ │ │ │ ├── allOfWithNoType.bal │ │ │ │ │ │ │ └── twoAllOf.bal │ │ │ │ │ │ ├── Nullable │ │ │ │ │ │ │ ├── nullable_option_null_type.bal │ │ │ │ │ │ │ ├── null_empty_record.bal │ │ │ │ │ │ │ ├── nullable_anyof_schema.bal │ │ │ │ │ │ │ ├── nullable_anyof_array_schema.bal │ │ │ │ │ │ │ ├── nullable_ref_array.bal │ │ │ │ │ │ │ ├── nullable_false.bal │ │ │ │ │ │ │ ├── nullable_record.bal │ │ │ │ │ │ │ ├── nullable_option_primitive_fields.bal │ │ │ │ │ │ │ ├── nullable_option_record_schema.bal │ │ │ │ │ │ │ ├── nullale_option_array_schema.bal │ │ │ │ │ │ │ ├── nullable_array.bal │ │ │ │ │ │ │ └── nullable_primitive.bal │ │ │ │ │ │ ├── Array │ │ │ │ │ │ │ ├── oneArray.bal │ │ │ │ │ │ │ ├── schema_with_array.bal │ │ │ │ │ │ │ ├── nestedArray.bal │ │ │ │ │ │ │ ├── schema_with_nested_array.bal │ │ │ │ │ │ │ ├── array_no_item_type.bal │ │ │ │ │ │ │ ├── array_max_item.bal │ │ │ │ │ │ │ ├── schemaArray.bal │ │ │ │ │ │ │ ├── refArray.bal │ │ │ │ │ │ │ ├── array_with_inline_allOf.bal │ │ │ │ │ │ │ ├── array_with_oneOf.bal │ │ │ │ │ │ │ ├── array_with_allOf.bal │ │ │ │ │ │ │ └── array_with_oneOf_complex.bal │ │ │ │ │ │ ├── Record │ │ │ │ │ │ │ ├── schema10.bal │ │ │ │ │ │ │ ├── empty_record.bal │ │ │ │ │ │ │ ├── schema11.bal │ │ │ │ │ │ │ ├── schema05.bal │ │ │ │ │ │ │ ├── default_required_field_schema.bal │ │ │ │ │ │ │ ├── default_optional_schema_with_doublequote.bal │ │ │ │ │ │ │ ├── default_optional_array_schema.bal │ │ │ │ │ │ │ ├── default_optional_string_schema.bal │ │ │ │ │ │ │ ├── default_optional_primitive_schema.bal │ │ │ │ │ │ │ └── nested_schema_refs.bal │ │ │ │ │ │ ├── Primitive │ │ │ │ │ │ │ ├── schema02.bal │ │ │ │ │ │ │ ├── missDataType.bal │ │ │ │ │ │ │ └── schema01.bal │ │ │ │ │ │ ├── AnyOf │ │ │ │ │ │ │ └── oneAnyOf.bal │ │ │ │ │ │ ├── Reference │ │ │ │ │ │ │ ├── referred_inclusion.bal │ │ │ │ │ │ │ ├── resolve_reference_docs.bal │ │ │ │ │ │ │ └── multiple_references.bal │ │ │ │ │ │ └── Constraint │ │ │ │ │ │ │ ├── additional_properties_with_constraint.bal │ │ │ │ │ │ │ ├── record_field.bal │ │ │ │ │ │ │ ├── type_def_node.bal │ │ │ │ │ │ │ └── array.bal │ │ │ │ │ ├── ballerina_project │ │ │ │ │ │ └── Ballerina.toml │ │ │ │ │ └── Errors │ │ │ │ │ │ └── Error.yaml │ │ │ │ ├── ballerina_project │ │ │ │ │ └── Ballerina.toml │ │ │ │ └── test_cases │ │ │ │ │ └── ballerina_project │ │ │ │ │ └── Ballerina.toml │ │ │ ├── ballerina-to-asyncapi │ │ │ │ ├── yaml_outputs │ │ │ │ │ ├── service │ │ │ │ │ │ └── multiple_service_empty_file.yaml │ │ │ │ │ ├── additional │ │ │ │ │ │ └── dispatcherStreamId_present.yaml │ │ │ │ │ ├── response │ │ │ │ │ │ ├── rs_scenario10_inline_record_type_inclusion.yaml │ │ │ │ │ │ ├── rs_scenario04_builtin.yaml │ │ │ │ │ │ ├── rs_scenario08_float.yaml │ │ │ │ │ │ ├── rs_scenario09_decimal.yaml │ │ │ │ │ │ ├── rs_scenario06_xml.yaml │ │ │ │ │ │ └── rs_scenario01_json.yaml │ │ │ │ │ ├── channels │ │ │ │ │ │ ├── channel_scenario01.yaml │ │ │ │ │ │ ├── channel_scenario03.yaml │ │ │ │ │ │ ├── channel_scenario04.yaml │ │ │ │ │ │ └── channel_scenario02.yaml │ │ │ │ │ ├── asyncapi_info │ │ │ │ │ │ ├── project01.yaml │ │ │ │ │ │ ├── project02.yaml │ │ │ │ │ │ ├── project04.yaml │ │ │ │ │ │ └── project03.yaml │ │ │ │ │ ├── headers │ │ │ │ │ │ ├── header_scenario06.yaml │ │ │ │ │ │ ├── header_scenario09.yaml │ │ │ │ │ │ ├── header_scenario01.yaml │ │ │ │ │ │ ├── header_scenario02.yaml │ │ │ │ │ │ ├── header_scenario03.yaml │ │ │ │ │ │ ├── header_scenario10.yaml │ │ │ │ │ │ ├── header_scenario15.yaml │ │ │ │ │ │ ├── header_scenario07.yaml │ │ │ │ │ │ ├── header_scenario14.yaml │ │ │ │ │ │ ├── header_scenario13.yaml │ │ │ │ │ │ ├── header_scenario05.yaml │ │ │ │ │ │ ├── header_scenario11.yaml │ │ │ │ │ │ ├── header_scenario08.yaml │ │ │ │ │ │ ├── header_scenario12.yaml │ │ │ │ │ │ └── header_scenario04.yaml │ │ │ │ │ ├── query │ │ │ │ │ │ ├── query_scenario01.yaml │ │ │ │ │ │ ├── query_scenario03.yaml │ │ │ │ │ │ ├── query_scenario05.yaml │ │ │ │ │ │ ├── query_scenario02.yaml │ │ │ │ │ │ ├── query_scenario04.yaml │ │ │ │ │ │ ├── query_scenario07.yaml │ │ │ │ │ │ └── query_scenario08.yaml │ │ │ │ │ ├── optional │ │ │ │ │ │ ├── optional_error_return.yaml │ │ │ │ │ │ └── optional_int_return.yaml │ │ │ │ │ ├── advance │ │ │ │ │ │ ├── multiple_service_02.yaml │ │ │ │ │ │ ├── multiple_service_03.yaml │ │ │ │ │ │ └── multiple_service_01.yaml │ │ │ │ │ ├── listeners │ │ │ │ │ │ ├── with_check_key_word.yaml │ │ │ │ │ │ ├── listener_scenario02.yaml │ │ │ │ │ │ ├── listener_scenario01.yaml │ │ │ │ │ │ ├── listener_scenario03.yaml │ │ │ │ │ │ ├── listener_scenario04.yaml │ │ │ │ │ │ └── listener_scenario05.yaml │ │ │ │ │ ├── apidoc │ │ │ │ │ │ ├── resource_function.yaml │ │ │ │ │ │ └── path_param.yaml │ │ │ │ │ ├── alias │ │ │ │ │ │ └── websocket.yaml │ │ │ │ │ └── record │ │ │ │ │ │ └── nullable01.yaml │ │ │ │ ├── ballerina-project │ │ │ │ │ └── service │ │ │ │ │ │ ├── Ballerina.toml │ │ │ │ │ │ └── arrayTypeResponse.bal │ │ │ │ ├── asyncapi_info │ │ │ │ │ └── project01 │ │ │ │ │ │ ├── Ballerina.toml │ │ │ │ │ │ └── project01.bal │ │ │ │ ├── service │ │ │ │ │ ├── project_bal │ │ │ │ │ │ ├── Ballerina.toml │ │ │ │ │ │ ├── schema.bal │ │ │ │ │ │ └── record_request_service.bal │ │ │ │ │ └── rabbitmq_service.bal │ │ │ │ ├── close_frame │ │ │ │ │ ├── Ballerina.toml │ │ │ │ │ ├── normal_closure.bal │ │ │ │ │ ├── close_frame.bal │ │ │ │ │ ├── close_frame_and_stream.bal │ │ │ │ │ └── types.bal │ │ │ │ ├── listeners │ │ │ │ │ ├── scenario02.bal │ │ │ │ │ ├── scenario01.bal │ │ │ │ │ ├── scenario03.bal │ │ │ │ │ ├── listener_scenario02.bal │ │ │ │ │ ├── listener_http_load_balancer.bal │ │ │ │ │ ├── listener_scenario01.bal │ │ │ │ │ ├── listener_scenario06.bal │ │ │ │ │ └── listener_scenario05.bal │ │ │ │ ├── headers │ │ │ │ │ ├── header_scenario06.bal │ │ │ │ │ ├── header_scenario09.bal │ │ │ │ │ ├── header_scenario01.bal │ │ │ │ │ ├── header_scenario03.bal │ │ │ │ │ ├── header_scenario05.bal │ │ │ │ │ ├── header_scenario11.bal │ │ │ │ │ ├── header_scenario13.bal │ │ │ │ │ └── header_scenario02.bal │ │ │ │ ├── query │ │ │ │ │ ├── query_scenario05.bal │ │ │ │ │ ├── query_scenario02.bal │ │ │ │ │ ├── query_scenario04.bal │ │ │ │ │ ├── query_scenario01.bal │ │ │ │ │ ├── query_scenario03.bal │ │ │ │ │ └── query_scenario07.bal │ │ │ │ ├── response │ │ │ │ │ ├── rs_scenario08_float.bal │ │ │ │ │ ├── rs_scenario09_decimal.bal │ │ │ │ │ ├── rs_scenario04_builtin.bal │ │ │ │ │ ├── rs_scenario01_json.bal │ │ │ │ │ ├── rs_scenario06_xml.bal │ │ │ │ │ └── rs_scenario05_inline_record_builtin.bal │ │ │ │ ├── alias │ │ │ │ │ └── websocket.bal │ │ │ │ ├── additional │ │ │ │ │ └── dispatcherStreamId_present.bal │ │ │ │ ├── dispatcher-mapping-annotation │ │ │ │ │ └── expected_gen │ │ │ │ │ │ └── listener.yaml │ │ │ │ ├── record │ │ │ │ │ └── nullable01.bal │ │ │ │ └── apidoc │ │ │ │ │ └── resource_function_scenario.bal │ │ │ └── cmd │ │ │ │ └── ballerina-to-asyncapi │ │ │ │ └── exceptions │ │ │ │ ├── no_service_class_present.bal │ │ │ │ ├── check_websocket_serviceConfig_annotation.bal │ │ │ │ ├── request_type_record_check.bal │ │ │ │ ├── dispatcherKey_field_not_present_in_record.bal │ │ │ │ └── empty_dispatcherKey_check.bal │ │ └── expected_gen │ │ │ └── service_types.bal │ └── java │ │ └── io │ │ └── ballerina │ │ └── asyncapi │ │ └── wsgenerators │ │ └── ballerina_project │ │ └── Ballerina.toml │ └── main │ ├── resources │ ├── META-INF │ │ └── services │ │ │ └── io.ballerina.cli.BLauncherCmd │ ├── config_toml_files │ │ ├── bearer_config.toml │ │ ├── api_key_config.toml │ │ ├── basic_config.toml │ │ ├── password_config.toml │ │ ├── client_credentials_config.toml │ │ └── refresh_token_config.toml │ ├── architecture.jpg │ └── data_types.bal │ └── java │ ├── io │ └── ballerina │ │ └── asyncapi │ │ ├── codegenerator │ │ ├── usecase │ │ │ ├── Generator.java │ │ │ └── Extractor.java │ │ ├── controller │ │ │ ├── BalController.java │ │ │ └── SpecController.java │ │ ├── application │ │ │ └── Application.java │ │ ├── configuration │ │ │ └── BallerinaAsyncApiException.java │ │ └── entity │ │ │ └── RemoteFunction.java │ │ └── websocketscore │ │ ├── exception │ │ └── BallerinaAsyncApiExceptionWs.java │ │ ├── ErrorMessages.java │ │ └── generators │ │ └── asyncspec │ │ └── diagnostic │ │ └── AsyncApiConverterDiagnostic.java │ └── module-info.java ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── samples ├── basic-chat │ ├── client │ │ └── Ballerina.toml │ ├── server │ │ ├── Ballerina.toml │ │ └── messages.md │ ├── server-demo │ │ ├── Ballerina.toml │ │ └── messages.md │ ├── client-with-dispatcherStreamId │ │ └── Ballerina.toml │ └── server-with-dispatcherStreamId │ │ ├── Ballerina.toml │ │ └── messages.md └── slack │ └── usercode │ └── usercode.bal ├── asyncapi-tool ├── BalTool.toml ├── Ballerina.toml ├── Dependencies.toml └── tool.bal ├── native.handler ├── init.bal ├── native_handler.bal ├── Package.md ├── Ballerina.toml ├── java-wrapper │ └── src │ │ └── main │ │ └── java │ │ ├── module-info.java │ │ └── io │ │ └── ballerinax │ │ └── event │ │ └── ModuleUtils.java └── Dependencies.toml ├── config └── resources │ ├── BalTool.toml │ └── Ballerina.toml ├── .github ├── CODEOWNERS └── workflows │ ├── trivy-scan.yml │ ├── pull-request.yml │ ├── build-timestamped-master.yml │ └── release-native-handler.yml └── issue_template.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Ensure all Java files use LF. 2 | *.java eol=lf 3 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-without-identifier-path.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/out/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | !placeholder.txt -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/baloutputs/Real/gemini_websocket.bal: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/InvalidResponse/int_type_response.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/OneOf/oneOfAsProperties.bal: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/out/placeholder.txt: -------------------------------------------------------------------------------- 1 | This is a placeholder file to push the directory. -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/AllOf/nested_allOf_with_allOf.bal: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/service/multiple_service_empty_file.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/resources/META-INF/services/io.ballerina.cli.BLauncherCmd: -------------------------------------------------------------------------------- 1 | io.ballerina.asyncapi.cmd.AsyncApiCmd 2 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/resources/config_toml_files/bearer_config.toml: -------------------------------------------------------------------------------- 1 | [authConfig] 2 | token = "" 3 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/additional/dispatcherStreamId_present.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/resources/config_toml_files/api_key_config.toml: -------------------------------------------------------------------------------- 1 | [apiKeyConfig.apiKeys] 2 | YOUR-API-KEY-1 = "" 3 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/response/rs_scenario10_inline_record_type_inclusion.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ballerina-platform/asyncapi-tools/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-with-identifier-path-missing-path.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | x-ballerina-event-identifier: 3 | type : "body" 4 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-with-identifier-path-missing-type.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | x-ballerina-event-identifier: 3 | path : "event.type" 4 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/ballerina-project/service/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | org-name = "test" 3 | version = "0.1.0" 4 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/resources/architecture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ballerina-platform/asyncapi-tools/HEAD/asyncapi-cli/src/main/resources/architecture.jpg -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-with-event-identifier-missing-header-name.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | x-ballerina-event-identifier: 3 | type : "header" 4 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-with-identifier-path.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | x-ballerina-event-identifier: 3 | type : "body" 4 | path : "event.type" 5 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/resources/config_toml_files/basic_config.toml: -------------------------------------------------------------------------------- 1 | [authConfig] 2 | username = "" 3 | password = "" 4 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/java/io/ballerina/asyncapi/wsgenerators/ballerina_project/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org= "ballerina" 3 | name= "test" 4 | version= "0.0.0" 5 | 6 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Nullable/nullable_option_null_type.bal: -------------------------------------------------------------------------------- 1 | # Latitude 2 | public type Latitude anydata?; 3 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/ballerina_project/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org= "ballerina" 3 | name= "test" 4 | version= "0.0.0" 5 | 6 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/asyncapi_info/project01/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org= "ballerina" 3 | name= "asyncapi" 4 | version= "2.0.0" -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/service/project_bal/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org= "ballerina" 3 | name= "asyncAPI" 4 | version= "0.1.0" 5 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-with-event-identifier-invalid-type.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | x-ballerina-event-identifier: 3 | type : "" 4 | path : "event.type" 5 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/ballerina_project/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org= "ballerina" 3 | name= "test" 4 | version= "0.0.0" 5 | 6 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-with-event-identifier-valid-header-type.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | x-ballerina-event-identifier: 3 | type : "header" 4 | name : "event-name" 5 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/test_cases/ballerina_project/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org= "ballerina" 3 | name= "testopenapi" 4 | version= "0.0.0" 5 | 6 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/resources/config_toml_files/password_config.toml: -------------------------------------------------------------------------------- 1 | [authConfig] 2 | tokenUrl = "" 3 | username = "" 4 | password = "" 5 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Array/oneArray.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int zipCode?; 3 | string event; 4 | string[] tag; 5 | }; 6 | -------------------------------------------------------------------------------- /samples/basic-chat/client/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org = "wso2" 3 | name = "test_websocket" 4 | version = "0.1.0" 5 | distribution = "2201.9.0" 6 | 7 | [build-options] 8 | observabilityIncluded = true 9 | -------------------------------------------------------------------------------- /samples/basic-chat/server/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org = "wso2" 3 | name = "websocket_test" 4 | version = "0.1.0" 5 | distribution = "2201.9.0" 6 | 7 | [build-options] 8 | observabilityIncluded = true 9 | -------------------------------------------------------------------------------- /samples/basic-chat/server-demo/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org = "wso2" 3 | name = "websocket_test" 4 | version = "0.1.0" 5 | distribution = "2201.9.0" 6 | 7 | [build-options] 8 | observabilityIncluded = true 9 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/close_frame/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org = "wso2" 3 | name = "closeframe_test" 4 | version = "0.1.0" 5 | 6 | [build-options] 7 | observabilityIncluded = true 8 | -------------------------------------------------------------------------------- /samples/basic-chat/client-with-dispatcherStreamId/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org = "wso2" 3 | name = "test_websocket" 4 | version = "0.1.0" 5 | distribution = "2201.9.0" 6 | 7 | [build-options] 8 | observabilityIncluded = true 9 | -------------------------------------------------------------------------------- /samples/basic-chat/server-with-dispatcherStreamId/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org = "wso2" 3 | name = "websocket_test" 4 | version = "0.1.0" 5 | distribution = "2201.9.0" 6 | 7 | [build-options] 8 | observabilityIncluded = true 9 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/resources/config_toml_files/client_credentials_config.toml: -------------------------------------------------------------------------------- 1 | [authConfig] 2 | tokenUrl = "" 3 | clientId = "" 4 | clientSecret = "" 5 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/resources/data_types.bal: -------------------------------------------------------------------------------- 1 | import ballerina/http; 2 | 3 | // Listener related configurations should be included here 4 | public type ListenerConfiguration record {| 5 | *http:ListenerConfiguration; 6 | |}; 7 | -------------------------------------------------------------------------------- /asyncapi-tool/BalTool.toml: -------------------------------------------------------------------------------- 1 | [tool] 2 | id = "asyncapi" 3 | 4 | [[dependency]] 5 | path = "../native.handler/build/libs/native.handler-0.12.0.jar" 6 | 7 | [[dependency]] 8 | path = "../asyncapi-cli/build/libs/asyncapi-cli-0.12.0.jar" 9 | -------------------------------------------------------------------------------- /native.handler/init.bal: -------------------------------------------------------------------------------- 1 | import ballerina/jballerina.java; 2 | 3 | isolated function init() { 4 | setModule(); 5 | } 6 | 7 | isolated function setModule() = @java:Method { 8 | 'class: "io.ballerinax.event.ModuleUtils" 9 | } external; 10 | -------------------------------------------------------------------------------- /config/resources/BalTool.toml: -------------------------------------------------------------------------------- 1 | [tool] 2 | id = "asyncapi" 3 | 4 | [[dependency]] 5 | path = "../native.handler/build/libs/native.handler-@project.version@.jar" 6 | 7 | [[dependency]] 8 | path = "../asyncapi-cli/build/libs/asyncapi-cli-@project.version@.jar" 9 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/resources/config_toml_files/refresh_token_config.toml: -------------------------------------------------------------------------------- 1 | [authConfig] 2 | refreshUrl = "" 3 | refreshToken = "" 4 | clientId = "" 5 | clientSecret = "" 6 | -------------------------------------------------------------------------------- /asyncapi-tool/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org = "ballerina" 3 | name = "tool.asyncapi" 4 | version = "0.12.0" 5 | authors = ["Ballerina"] 6 | keywords = ["asyncapi", "asyncapi tool", "asyncapi generator", "asyncapi spec"] 7 | license = ["Apache-2.0"] 8 | distribution = "2201.13.0" 9 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Record/schema10.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | anydata pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | }; 10 | -------------------------------------------------------------------------------- /config/resources/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org = "ballerina" 3 | name = "tool.asyncapi" 4 | version = "@toml.version@" 5 | authors = ["Ballerina"] 6 | keywords = ["asyncapi", "asyncapi tool", "asyncapi generator", "asyncapi spec"] 7 | license = ["Apache-2.0"] 8 | distribution = "2201.13.0" 9 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Array/schema_with_array.bal: -------------------------------------------------------------------------------- 1 | public type Address record { 2 | int streetNo?; 3 | string mainStreet?; 4 | string country?; 5 | }; 6 | 7 | public type UserAddress Address[]; 8 | 9 | public type Pet string[]; 10 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Lines starting with '#' are comments. 2 | # Each line is a file pattern followed by one or more owners. 3 | 4 | # See: https://help.github.com/articles/about-codeowners/ 5 | 6 | # These owners will be the default owners for everything in the repo. 7 | * @NipunaRanasinghe @Nuvindu @shafreenAnfar 8 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Array/nestedArray.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int zipCode?; 3 | string event; 4 | string[][][] tag; 5 | }; 6 | 7 | public type UnSubscribe record { 8 | int zipCode?; 9 | string event; 10 | }; 11 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Array/schema_with_nested_array.bal: -------------------------------------------------------------------------------- 1 | public type Address record { 2 | int streetNo?; 3 | string mainStreet?; 4 | string country?; 5 | }; 6 | 7 | public type UserAddress Address[][][]; 8 | 9 | public type Pet string[][]; 10 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/channels/channel_scenario01.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/Errors/Error.yaml: -------------------------------------------------------------------------------- 1 | components: 2 | schemas: 3 | Error: 4 | required: 5 | - code 6 | - message 7 | properties: 8 | code: 9 | type: integer 10 | format: int32 11 | message: 12 | type: string 13 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/asyncapi_info/project01.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.1 2 | info: 3 | title: PayloadV 4 | version: 0.1.0 5 | servers: 6 | - url: "{server}:{port}/payloadV" 7 | variables: 8 | server: 9 | default: http://localhost 10 | port: 11 | default: "9090" 12 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/asyncapi_info/project02.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.1 2 | info: 3 | title: PayloadV 4 | version: 2.0.0 5 | servers: 6 | - url: "{server}:{port}/payloadV" 7 | variables: 8 | server: 9 | default: http://localhost 10 | port: 11 | default: "9090" 12 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/asyncapi_info/project04.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.1 2 | info: 3 | title: PayloadV 4 | version: 2.0.0 5 | servers: 6 | - url: "{server}:{port}/payloadV" 7 | variables: 8 | server: 9 | default: http://localhost 10 | port: 11 | default: "9090" 12 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Array/array_no_item_type.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | Activity activity?; 3 | string event; 4 | anydata[] tag; 5 | }; 6 | 7 | public type UnSubscribe record { 8 | int zipCode?; 9 | string event; 10 | }; 11 | 12 | public type Activity anydata[]; -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/asyncapi_info/project03.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.1 2 | info: 3 | title: PayloadV 4 | version: 2.0.0 5 | servers: 6 | - url: "{server}:{port}/payloadV" 7 | variables: 8 | server: 9 | default: http://localhost 10 | port: 11 | default: "9090" 12 | 13 | -------------------------------------------------------------------------------- /native.handler/native_handler.bal: -------------------------------------------------------------------------------- 1 | import ballerina/jballerina.java; 2 | 3 | public class NativeHandler { 4 | public isolated function invokeRemoteFunction(any event, string eventName, string eventFunction, service object {} serviceObj) returns error? = @java:Method { 5 | 'class: "io.ballerinax.event.NativeHttpToEventAdaptor" 6 | } external; 7 | } 8 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-single-schema-with-enum.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | components: 3 | schemas: 4 | occupancyStatus: 5 | enum: 6 | - EMPTY 7 | - MANY_SEATS_AVAILABLE 8 | - FEW_SEATS_AVAILABLE 9 | - STANDING_ROOM_ONLY 10 | - CRUSHED_STANDING_ROOM_ONLY 11 | - FULL 12 | - NOT_ACCEPTING_PASSENGERS 13 | -------------------------------------------------------------------------------- /native.handler/Package.md: -------------------------------------------------------------------------------- 1 | This is a wrapper, which is being used by triggers. 2 | In Ballerina, resource functions can not execute remote functions directly. 3 | Java interop must be used to execute those kinds of calls. 4 | This module contains a wrapper, which wraps a set of interop functions. 5 | Triggers use this wrapper to execute calls from the resource functions to the remote functions. -------------------------------------------------------------------------------- /.github/workflows/trivy-scan.yml: -------------------------------------------------------------------------------- 1 | name: Trivy 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: "30 20 * * *" 7 | 8 | jobs: 9 | call_workflow: 10 | name: Run Trivy Scan Workflow 11 | if: ${{ github.repository_owner == 'ballerina-platform' }} 12 | uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main 13 | secrets: inherit 14 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/AllOf/allOfWithEmptyObject.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | boolean timing?; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | *Time; 8 | }; 9 | 10 | public type Time record { 11 | int minute; 12 | string second?; 13 | string hour?; 14 | string day?; 15 | string event; 16 | }; 17 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Array/array_max_item.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | @constraint:Array {maxLength: 7} 3 | int[] tag; 4 | string event; 5 | Activity activity?; 6 | }; 7 | 8 | public type UnSubscribe record { 9 | int zipCode?; 10 | string event; 11 | }; 12 | 13 | @constraint:Array {maxLength: 7} 14 | public type Activity int[]; 15 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Array/schemaArray.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int zipCode?; 3 | string event; 4 | # Code array 5 | Activity[] code?; 6 | boolean codePen?; 7 | }; 8 | 9 | public type UnSubscribe record { 10 | int zipCode?; 11 | string event; 12 | }; 13 | 14 | public type Activity Request[]; 15 | 16 | public type Request int; -------------------------------------------------------------------------------- /samples/basic-chat/server/messages.md: -------------------------------------------------------------------------------- 1 | ## Subscribe Message Example 2 | 3 | ```json 4 | {"event":"subscribe","name":"Gopi","gender":"Male"} 5 | ``` 6 | 7 | ## Unsubscribe Message Example 8 | 9 | ```json 10 | {"event":"unsubscribe"} 11 | ``` 12 | 13 | ## Chat Message Example 14 | 15 | ```json 16 | {"event":"chat","message":"Hello Ballerina", "toUserId": "cc6b1efffe42ea75-0003c7e2-00000002-aa19eabfbcf62d1d-48179b7d"} 17 | ``` -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/AllOf/oneAllOf.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | boolean timing?; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | *Time; 8 | boolean timing?; 9 | }; 10 | 11 | public type Time record { 12 | int minute; 13 | string second?; 14 | string hour?; 15 | string day?; 16 | string event; 17 | }; 18 | -------------------------------------------------------------------------------- /samples/basic-chat/server-demo/messages.md: -------------------------------------------------------------------------------- 1 | ## Subscribe Message Example 2 | 3 | ```json 4 | {"event":"subscribe","name":"Gopi","gender":"Male"} 5 | ``` 6 | 7 | ## Unsubscribe Message Example 8 | 9 | ```json 10 | {"event":"unsubscribe"} 11 | ``` 12 | 13 | ## Chat Message Example 14 | 15 | ```json 16 | {"event":"chat","message":"Hello Ballerina", "toUserId": "cc6b1efffe42ea75-0001e3b1-00000002-237f98c8d2877f67-d7aa765b"} 17 | ``` -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/AllOf/allOf_with_one_ref.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | boolean timing?; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | *Time; 8 | Time time?; 9 | }; 10 | 11 | public type Time record { 12 | int minute; 13 | string second?; 14 | string hour?; 15 | string day?; 16 | string event; 17 | }; 18 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Primitive/schema02.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | anydata pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | Request request?; 10 | }; 11 | 12 | public type Request record { 13 | int id; 14 | string name; 15 | string tag?; 16 | string 'type?; 17 | }; 18 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/AllOf/allOf_with_cyclic.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | boolean timing?; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | *Time; 8 | UnSubscribe time?; 9 | }; 10 | 11 | public type Time record { 12 | int minute; 13 | string second?; 14 | string hour?; 15 | string day?; 16 | string event; 17 | }; 18 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/channels/channel_scenario03.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /v1/{id}: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | parameters: 12 | id: 13 | schema: 14 | type: integer 15 | format: int64 -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario06.yaml: -------------------------------------------------------------------------------- 1 | paths: 2 | /ping: 3 | get: 4 | operationId: getPing 5 | parameters: 6 | - name: headerValue 7 | in: header 8 | required: true 9 | schema: 10 | type: string 11 | nullable: true 12 | responses: 13 | "200": 14 | description: Ok 15 | components: {} 16 | -------------------------------------------------------------------------------- /native.handler/Ballerina.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | org = "ballerinax" 3 | name = "asyncapi.native.handler" 4 | version = "0.5.1-SNAPSHOT" 5 | distribution = "2201.12.0" 6 | readme = "Package.md" 7 | 8 | [[platform.java21.dependency]] 9 | path = "./java-wrapper/build/libs/java-wrapper-0.10.1-SNAPSHOT.jar" 10 | groupId = "io.ballerinax.asyncapi" 11 | artifactId = "java-wrapper" 12 | version = "0.10.1" 13 | 14 | [build-options] 15 | observabilityIncluded = true 16 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Array/refArray.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int zipCode?; 3 | string event; 4 | # Code array 5 | Activity[] code?; 6 | boolean codePen?; 7 | }; 8 | 9 | public type UnSubscribe record { 10 | int zipCode?; 11 | string event; 12 | }; 13 | 14 | public type Activity record { 15 | int id; 16 | string name; 17 | string tag?; 18 | }; 19 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario09.yaml: -------------------------------------------------------------------------------- 1 | paths: 2 | /ping: 3 | get: 4 | operationId: getPing 5 | parameters: 6 | - name: headerValue 7 | in: header 8 | schema: 9 | type: string 10 | nullable: true 11 | default: default 12 | responses: 13 | "200": 14 | description: Ok 15 | components: {} 16 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/AllOf/allOfWithNoType.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | boolean pure?; 3 | boolean timing?; 4 | string event; 5 | }; 6 | 7 | public type UnSubscribe record { 8 | *Time; 9 | boolean timing?; 10 | }; 11 | 12 | public type Time record { 13 | int minute; 14 | string second?; 15 | string hour?; 16 | string day?; 17 | string event; 18 | }; 19 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Nullable/null_empty_record.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | Request request?; 10 | }; 11 | 12 | public type Request record { 13 | int id?; 14 | string name?; 15 | string tag?; 16 | string 'type?; 17 | record {}? details?; 18 | }; -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Nullable/nullable_anyof_schema.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | Request request?; 10 | }; 11 | 12 | public type Request record { 13 | # The customer's address. 14 | Response? address?; 15 | string name?; 16 | }; 17 | 18 | public type Response string; 19 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Record/empty_record.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | Request request?; 10 | }; 11 | 12 | # Response details 13 | public type Response record { 14 | int id; 15 | string name; 16 | string tag?; 17 | }; 18 | 19 | public type Request record { 20 | }; 21 | -------------------------------------------------------------------------------- /samples/basic-chat/server-with-dispatcherStreamId/messages.md: -------------------------------------------------------------------------------- 1 | ## Subscribe Message Example 2 | 3 | ```json 4 | {"event":"subscribe","name":"Gopi","gender":"Male", "id":"ALOHA"} 5 | ``` 6 | 7 | ## Unsubscribe Message Example 8 | 9 | ```json 10 | {"event":"unsubscribe", id:"UNSUB_ID"} 11 | ``` 12 | 13 | ## Chat Message Example 14 | 15 | ```json 16 | {"event":"chat","message":"Hello Ballerina", "toUserId": "cc6b1efffe42ea75-000420c8-00000002-3ff441ce1aa91480-ef8175ca", "id":"CHAT_ID"} 17 | ``` -------------------------------------------------------------------------------- /.github/workflows/pull-request.yml: -------------------------------------------------------------------------------- 1 | name: PR Build 2 | 3 | concurrency: 4 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} 5 | cancel-in-progress: true 6 | 7 | on: [pull_request] 8 | 9 | jobs: 10 | call_workflow: 11 | name: Run PR Build Workflow 12 | if: ${{ github.repository_owner == 'ballerina-platform' }} 13 | uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main 14 | secrets: inherit 15 | -------------------------------------------------------------------------------- /asyncapi-tool/Dependencies.toml: -------------------------------------------------------------------------------- 1 | # AUTO-GENERATED FILE. DO NOT MODIFY. 2 | 3 | # This file is auto-generated by Ballerina for managing dependency versions. 4 | # It should not be modified by hand. 5 | 6 | [ballerina] 7 | dependencies-toml-version = "2" 8 | distribution-version = "2201.13.0" 9 | 10 | [[package]] 11 | org = "ballerina" 12 | name = "tool.asyncapi" 13 | version = "0.12.0" 14 | modules = [ 15 | {org = "ballerina", packageName = "tool.asyncapi", moduleName = "tool.asyncapi"} 16 | ] 17 | 18 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Nullable/nullable_anyof_array_schema.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | Request request?; 10 | }; 11 | 12 | public type Request record { 13 | # The customer's address. 14 | Response[]|string address?; 15 | string name?; 16 | }; 17 | 18 | public type Response string; 19 | 20 | -------------------------------------------------------------------------------- /.github/workflows/build-timestamped-master.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths-ignore: 8 | - "*.md" 9 | - "docs/**" 10 | - "load-tests/**" 11 | 12 | workflow_dispatch: 13 | 14 | jobs: 15 | call_workflow: 16 | name: Run Build Workflow 17 | if: ${{ github.repository_owner == 'ballerina-platform' }} 18 | uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@main 19 | secrets: inherit 20 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/OneOf/twoOneOf.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int zipCode?; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe Time|Activity; 7 | 8 | public type Time record { 9 | int minute; 10 | string second?; 11 | string hour?; 12 | string day?; 13 | string event; 14 | }; 15 | 16 | public type Activity record { 17 | # Unique identifier for the activity 18 | string uuid?; 19 | string event; 20 | }; 21 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/channels/channel_scenario04.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /v1/{id}/v2/{name}: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | parameters: 12 | id: 13 | schema: 14 | type: integer 15 | format: int64 16 | name: 17 | schema: 18 | type: string -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario01.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /ping: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | bindings: 12 | ws: 13 | bindingVersion: 0.1.0 14 | headers: 15 | type: object 16 | properties: 17 | X-Client: 18 | type: string -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario02.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /ping: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | bindings: 12 | ws: 13 | bindingVersion: 0.1.0 14 | headers: 15 | type: object 16 | properties: 17 | x-item: 18 | type: string -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/OneOf/twoOneOfWithObjectType.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int zipCode?; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe Time|Activity; 7 | 8 | public type Time record { 9 | int minute; 10 | string second?; 11 | string hour?; 12 | string day?; 13 | string event; 14 | }; 15 | 16 | public type Activity record { 17 | # Unique identifier for the activity 18 | string uuid?; 19 | string event; 20 | }; -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario03.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /ping: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | bindings: 12 | ws: 13 | bindingVersion: 0.1.0 14 | headers: 15 | type: object 16 | properties: 17 | headerValue: 18 | type: string -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario10.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /ping: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | bindings: 12 | ws: 13 | bindingVersion: 0.1.0 14 | headers: 15 | type: object 16 | properties: 17 | headerValue: 18 | type: string -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario15.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /ping: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | bindings: 12 | ws: 13 | bindingVersion: 0.1.0 14 | headers: 15 | type: object 16 | properties: 17 | headerValue: 18 | type: string -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/query/query_scenario01.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /: 3 | subscribe: 4 | message: 5 | payload: 6 | type: string 7 | publish: 8 | message: 9 | $ref: '#/components/messages/Subscribe' 10 | bindings: 11 | ws: 12 | bindingVersion: 0.1.0 13 | query: 14 | type: object 15 | properties: 16 | offset: 17 | type: integer 18 | format: int64 19 | 20 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Primitive/missDataType.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | anydata pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | # Test description 10 | Request request?; 11 | }; 12 | 13 | # Test description 14 | public type Request record { 15 | # this is missing dataType 16 | anydata id; 17 | string name; 18 | decimal tag?; 19 | string 'type?; 20 | }; 21 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/AllOf/twoAllOf.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | boolean timing?; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | *Time; 8 | *Activity; 9 | }; 10 | 11 | public type Time record { 12 | int minute; 13 | string second?; 14 | string hour?; 15 | string day?; 16 | string event; 17 | }; 18 | 19 | public type Activity record { 20 | # Unique identifier for the activity 21 | string uuid?; 22 | }; 23 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Record/schema11.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | Request request?; 10 | }; 11 | 12 | public type Request record { 13 | int id; 14 | # name field 15 | string name; 16 | string tag?; 17 | record { 18 | # type id 19 | string typeId?; 20 | string tagType?; 21 | } 'type?; 22 | }; 23 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/query/query_scenario03.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /: 3 | subscribe: 4 | message: 5 | payload: 6 | type: string 7 | publish: 8 | message: 9 | $ref: '#/components/messages/Subscribe' 10 | bindings: 11 | ws: 12 | bindingVersion: 0.1.0 13 | query: 14 | type: object 15 | properties: 16 | tags: 17 | type: array 18 | items: 19 | type: string -------------------------------------------------------------------------------- /samples/slack/usercode/usercode.bal: -------------------------------------------------------------------------------- 1 | import ballerinax/triggers.slack; 2 | import ballerina/io; 3 | 4 | listener slack:Listener slackListener = new ("verification_token"); 5 | 6 | service slack:AppService on slackListener { 7 | remote function onAppMention(slack:GenericEventWrapper event) returns error? { 8 | io:println(event.event.'type); 9 | } 10 | 11 | remote function onAppRateLimited(slack:GenericEventWrapper event) returns error? {} 12 | 13 | remote function onAppUninstalled(slack:GenericEventWrapper event) returns error? {} 14 | } -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/AnyOf/oneAnyOf.bal: -------------------------------------------------------------------------------- 1 | public type ResponseMessage record { 2 | string event; 3 | }; 4 | 5 | public type ResponseMessageWithId record { 6 | string event; 7 | string id; 8 | }; 9 | 10 | public type Subscribe record { 11 | boolean timing?; 12 | string event; 13 | }; 14 | 15 | public type UnSubscribe Time; 16 | 17 | public type Time record { 18 | int minute; 19 | string second?; 20 | string hour?; 21 | string day?; 22 | string event; 23 | }; 24 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Primitive/schema01.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | anydata pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | # Test description 10 | Request request?; 11 | }; 12 | 13 | # Test description 14 | public type Request record { 15 | # tests 16 | int id; 17 | # tests 18 | string name; 19 | # tests 20 | decimal tag?; 21 | # tests 22 | string 'type?; 23 | }; 24 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Record/schema05.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | anydata pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | Request request?; 10 | }; 11 | 12 | # Response details 13 | public type Response record { 14 | int id; 15 | string name; 16 | string tag?; 17 | }; 18 | 19 | public type Request record { 20 | # Response details 21 | Response time; 22 | boolean detail?; 23 | }; 24 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario07.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /ping: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | bindings: 12 | ws: 13 | bindingVersion: 0.1.0 14 | headers: 15 | type: object 16 | properties: 17 | x-client: 18 | type: string 19 | default: header1 -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Record/default_required_field_schema.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | Request request?; 10 | }; 11 | 12 | # Response details 13 | public type Response record { 14 | int id; 15 | string name; 16 | string tag?; 17 | }; 18 | 19 | public type Request record { 20 | int id; 21 | string name = "Name"; 22 | string 'type?; 23 | }; 24 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario14.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /v1: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | bindings: 12 | ws: 13 | bindingVersion: 0.1.0 14 | headers: 15 | type: object 16 | properties: 17 | x-item: 18 | type: array 19 | items: 20 | type: string -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario13.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /v1: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | bindings: 12 | ws: 13 | bindingVersion: 0.1.0 14 | headers: 15 | type: object 16 | properties: 17 | XClient: 18 | type: array 19 | items: 20 | type: string -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/query/query_scenario05.yaml: -------------------------------------------------------------------------------- 1 | #paths: 2 | # /pets: 3 | # get: 4 | # summary: Mock example 5 | # operationId: getPets 6 | # parameters: 7 | # - name: pet 8 | # in: query 9 | # description: Mock optional query parameter Description 10 | # required: true 11 | # schema: 12 | # type: number 13 | # format: double 14 | # nullable: true 15 | # responses: 16 | # "200": 17 | # description: Ok 18 | #components: {} 19 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-single-schema-with-unrecognized-type.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | components: 3 | schemas: 4 | GenericEventWrapper: 5 | additionalProperties: true 6 | description: Adapted from auto-generated content 7 | properties: 8 | api_app_id: 9 | description: ' Use this to distinguish which app the event belongs to if you use multiple apps with the same Request URL.' 10 | title: The unique identifier your installed application. 11 | type: unknown_type 12 | x-examples: 13 | - A2H9RFS1A 14 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Nullable/nullable_ref_array.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int pet_type; 3 | string event; 4 | Time time?; 5 | }; 6 | 7 | public type UnSubscribe record { 8 | int zipCode?; 9 | string event; 10 | Request request?; 11 | }; 12 | 13 | public type Request record { 14 | int id; 15 | string name; 16 | string tag?; 17 | string 'type?; 18 | }; 19 | 20 | public type Response record { 21 | *Request; 22 | boolean isTime?; 23 | }; 24 | 25 | public type Time Request[]?; 26 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario05.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /ping: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | bindings: 12 | ws: 13 | bindingVersion: 0.1.0 14 | headers: 15 | type: object 16 | properties: 17 | headerValue: 18 | type: string 19 | extensions: 20 | x-nullable: true -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/query/query_scenario02.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /: 3 | subscribe: 4 | message: 5 | payload: 6 | type: string 7 | publish: 8 | message: 9 | $ref: '#/components/messages/Subscribe' 10 | bindings: 11 | ws: 12 | bindingVersion: 0.1.0 13 | query: 14 | type: object 15 | properties: 16 | offset: 17 | type: integer 18 | format: int64 19 | extensions: 20 | x-nullable: true 21 | 22 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Record/default_optional_schema_with_doublequote.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | Request request?; 10 | }; 11 | 12 | # Response details 13 | public type Response record { 14 | int id; 15 | string name; 16 | string tag?; 17 | }; 18 | 19 | public type Request record { 20 | int id; 21 | string name; 22 | string textQualifier = "\""; 23 | string 'type?; 24 | }; 25 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario11.yaml: -------------------------------------------------------------------------------- 1 | default: "9090" 2 | channels: 3 | /ping: 4 | subscribe: 5 | message: 6 | payload: 7 | type: integer 8 | format: int64 9 | publish: 10 | message: 11 | $ref: '#/components/messages/Subscribe' 12 | bindings: 13 | ws: 14 | bindingVersion: 0.1.0 15 | headers: 16 | type: object 17 | properties: 18 | headerValue: 19 | type: array 20 | items: 21 | type: boolean -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-single-schema-with-invalid-number-format.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | components: 3 | schemas: 4 | GenericEventWrapper: 5 | additionalProperties: true 6 | description: Adapted from auto-generated content 7 | properties: 8 | api_app_id: 9 | description: ' Use this to distinguish which app the event belongs to if you use multiple apps with the same Request URL.' 10 | title: The unique identifier your installed application. 11 | type: number 12 | format: unknown 13 | x-examples: 14 | - A2H9RFS1A 15 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Record/default_optional_array_schema.bal: -------------------------------------------------------------------------------- 1 | 2 | public type Subscribe record { 3 | int pet_type; 4 | string event; 5 | }; 6 | 7 | public type UnSubscribe record { 8 | int zipCode?; 9 | string event; 10 | Request request?; 11 | }; 12 | 13 | # Response details 14 | public type Response record { 15 | int id; 16 | string name; 17 | string tag?; 18 | }; 19 | 20 | public type Request record { 21 | int id; 22 | string name; 23 | string[] tagArray = ["available","busy"]; 24 | string 'type?; 25 | }; 26 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario08.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /ping: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | bindings: 12 | ws: 13 | bindingVersion: 0.1.0 14 | headers: 15 | type: object 16 | properties: 17 | x-client: 18 | type: string 19 | extensions: 20 | x-nullable: true 21 | default: header1 -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario12.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /ping: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | bindings: 12 | ws: 13 | bindingVersion: 0.1.0 14 | headers: 15 | type: object 16 | properties: 17 | x-client: 18 | type: array 19 | items: 20 | type: boolean 21 | default: "[true, false]" -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Array/array_with_inline_allOf.bal: -------------------------------------------------------------------------------- 1 | # List of addresses 2 | public type Owner record { 3 | record { 4 | # Street No 5 | string streetNo?; 6 | # House number 7 | string houseNo?; 8 | # Street Name 9 | string streatName?; 10 | # Country Name 11 | string country?; 12 | # Zip code 13 | int zipCode?; 14 | *NameData; 15 | }[] AdressList?; 16 | string[] Pets?; 17 | }; 18 | 19 | public type NameData record { 20 | string FirstName?; 21 | string LastName?; 22 | }; 23 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/query/query_scenario04.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /: 3 | subscribe: 4 | message: 5 | payload: 6 | type: string 7 | publish: 8 | message: 9 | $ref: '#/components/messages/Subscribe' 10 | bindings: 11 | ws: 12 | bindingVersion: 0.1.0 13 | query: 14 | type: object 15 | properties: 16 | pet: 17 | type: array 18 | items: 19 | type: integer 20 | format: int64 21 | extensions: 22 | x-nullable: true -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/baloutputs/PathParam/path_param_with_ref_schema.bal: -------------------------------------------------------------------------------- 1 | # Path parameters as a record 2 | # 3 | # + id - Unique identification of location 4 | public type PathParams record {| 5 | Id id; 6 | |}; 7 | 8 | public type Message readonly & record {string event;}; 9 | 10 | public type MessageWithId readonly & record {string event; string id;}; 11 | 12 | public type Subscribe record { 13 | string id; 14 | string event; 15 | }; 16 | 17 | public type Id int; 18 | 19 | public type UnSubscribe record { 20 | string 'type; 21 | record {} payload?; 22 | string event; 23 | }; 24 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/query/query_scenario07.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /hello: 3 | subscribe: 4 | message: 5 | payload: 6 | type: string 7 | publish: 8 | message: 9 | $ref: '#/components/messages/Subscribe' 10 | bindings: 11 | ws: 12 | bindingVersion: 0.1.0 13 | query: 14 | type: object 15 | properties: 16 | test: 17 | type: array 18 | items: 19 | type: integer 20 | format: int64 21 | extensions: 22 | x-nullable: true -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/headers/header_scenario04.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /ping: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | bindings: 12 | ws: 13 | bindingVersion: 0.1.0 14 | headers: 15 | type: object 16 | properties: 17 | headerValue: 18 | type: string 19 | x-request-client: 20 | type: string 21 | extensions: 22 | x-nullable: true -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-single-channel-missing-x-event-type-without-oneof.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | channels: 3 | events/foo/1: 4 | subscribe: 5 | message: 6 | externalDocs: 7 | description: Event documentation for bar_event_1 8 | url: 'https://foo.com/events/bar_event_1' 9 | payload: 10 | $ref: '#/components/schemas/GenericEventWrapper' 11 | summary: Subscribe to only the message events that mention your app or bot 12 | tags: 13 | - name: allows_user_tokens 14 | - name: app_event 15 | x-scopes-required: [ ] 16 | x-tokens-allowed: 17 | - user 18 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Reference/referred_inclusion.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | anydata pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | }; 10 | 11 | public type Pet record { 12 | int id; 13 | string name; 14 | string tag?; 15 | string 'type?; 16 | }; 17 | 18 | public type Dog record { 19 | *Pet; 20 | boolean bark?; 21 | }; 22 | 23 | public type Pets Pet[]; 24 | 25 | public type SimpleType int; 26 | 27 | public type ReferredSimpleType SimpleType; 28 | 29 | public type TestPet Pet; 30 | 31 | public type TestDog Dog; 32 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Reference/resolve_reference_docs.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | anydata pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | }; 10 | 11 | # Pet details 12 | public type Pet record { 13 | int id; 14 | string name; 15 | string tag?; 16 | string 'type?; 17 | }; 18 | 19 | # Dog details 20 | public type Dog record { 21 | # Pet details 22 | Pet pet_details?; 23 | boolean bark?; 24 | }; 25 | 26 | # Pets details 27 | public type Pets record { 28 | anydata pet_details?; 29 | int numer_of_pets?; 30 | }; 31 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/query/query_scenario08.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /hello: 3 | subscribe: 4 | message: 5 | payload: 6 | type: string 7 | publish: 8 | message: 9 | $ref: '#/components/messages/Subscribe' 10 | bindings: 11 | ws: 12 | bindingVersion: 0.1.0 13 | query: 14 | type: object 15 | properties: 16 | definedY: 17 | type: string 18 | prefixDefinedY: 19 | type: string 20 | offset: 21 | type: integer 22 | format: int64 23 | limitV: 24 | type: string -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Record/default_optional_string_schema.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | Request request?; 10 | }; 11 | 12 | # Response details 13 | public type Response record { 14 | int id; 15 | string name; 16 | string tag?; 17 | }; 18 | 19 | public type Request record { 20 | int id; 21 | string name; 22 | string tagName = "TagName"; 23 | string? 'type = "<|endoftext|>"; 24 | string|string[]? prompt = "<|endoftext|>"; 25 | int|string anyOfField = "<|endoftext|>"; 26 | }; 27 | -------------------------------------------------------------------------------- /asyncapi-tool/tool.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/expected_gen/service_types.bal: -------------------------------------------------------------------------------- 1 | public type AppMentionHandlingService service object { 2 | remote function onAppMentionAdded(GenericEventWrapper event) returns error?; 3 | remote function onAppMentionRemoved(GenericEventWrapper event) returns error?; 4 | }; 5 | 6 | public type AppRateLimitedHandlingService service object { 7 | remote function onAppRateLimited(GenericEventWrapper event) returns error?; 8 | }; 9 | 10 | public type AppCreatedHandlingService service object { 11 | remote function onAppCreated(CustomTestSchema event) returns error?; 12 | }; 13 | 14 | public type GenericServiceType AppMentionHandlingService|AppRateLimitedHandlingService|AppCreatedHandlingService; 15 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Record/default_optional_primitive_schema.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | Request request?; 10 | }; 11 | 12 | # Response details 13 | public type Response record { 14 | int id; 15 | string name; 16 | string tag?; 17 | }; 18 | 19 | public type Request record { 20 | int id; 21 | string name; 22 | int tagNumber = 10; 23 | string 'type?; 24 | boolean isTrue = true; 25 | decimal decimalValue = 0.05; 26 | float floatValue = 11.5; 27 | string stringDecimalValue = "00.05"; 28 | }; 29 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/channels/channel_scenario02.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | /v1/{id}/v2/{name}: 3 | subscribe: 4 | message: 5 | payload: 6 | type: integer 7 | format: int64 8 | publish: 9 | message: 10 | $ref: '#/components/messages/Subscribe' 11 | parameters: 12 | id: 13 | schema: 14 | type: integer 15 | format: int64 16 | name: 17 | schema: 18 | type: string 19 | bindings: 20 | ws: 21 | bindingVersion: 0.1.0 22 | query: 23 | type: object 24 | properties: 25 | tag: 26 | type: integer 27 | format: int64 -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-single-channel-missing-reference.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | channels: 3 | events/foo/1: 4 | x-ballerina-service-type: "FooService" 5 | subscribe: 6 | message: 7 | x-ballerina-event-type: "bar_event_1" 8 | externalDocs: 9 | description: Event documentation for bar_event_1 10 | url: 'https://foo.com/events/bar_event_1' 11 | payload: 12 | $ref: '#/components/schemas/GenericEventWrapper' 13 | summary: Subscribe to only the message events that mention your app or bot 14 | tags: 15 | - name: allows_user_tokens 16 | - name: app_event 17 | x-scopes-required: [] 18 | x-tokens-allowed: 19 | - user 20 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-single-channel-missing-x-event-type-with-oneof.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | channels: 3 | events/foo/1: 4 | subscribe: 5 | message: 6 | oneOf: 7 | - 8 | externalDocs: 9 | description: Event documentation for bar_event_1 10 | url: 'https://foo.com/events/bar_event_1' 11 | payload: 12 | $ref: '#/components/schemas/GenericEventWrapper' 13 | summary: Subscribe to only the message events that mention your app or bot 14 | tags: 15 | - name: allows_user_tokens 16 | - name: app_event 17 | x-scopes-required: [] 18 | x-tokens-allowed: 19 | - user 20 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-single-channel-missing-payload.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | components: 3 | schemas: 4 | GenericEventWrapper: 5 | description: "This is a dummy schema" 6 | channels: 7 | events/foo/1: 8 | x-ballerina-service-type: "FooService" 9 | subscribe: 10 | message: 11 | x-ballerina-event-type: "bar_event_1" 12 | externalDocs: 13 | description: Event documentation for bar_event_1 14 | url: 'https://foo.com/events/bar_event_1' 15 | summary: Subscribe to only the message events that mention your app or bot 16 | tags: 17 | - name: allows_user_tokens 18 | - name: app_event 19 | x-scopes-required: [] 20 | x-tokens-allowed: 21 | - user 22 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/baloutputs/HeaderParam/header_parameter_types.bal: -------------------------------------------------------------------------------- 1 | # Header parameters as a record 2 | # 3 | public type HeaderParams record {| 4 | # offset 5 | int offset; 6 | # Latitude 7 | string lat; 8 | # Longtitude 9 | string lon; 10 | # exclude 11 | string exclude; 12 | # units description 13 | int units = 12; 14 | |}; 15 | 16 | public type Message readonly & record {string event;}; 17 | 18 | public type MessageWithId readonly & record {string event; string id;}; 19 | 20 | public type Subscribe record { 21 | string id; 22 | string event; 23 | }; 24 | 25 | public type UnSubscribe record { 26 | string 'type; 27 | record {} payload?; 28 | string event; 29 | }; 30 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Constraint/additional_properties_with_constraint.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | Additional_Array additionalArray?; 3 | string event; 4 | Additional_NestedArray additionalNestedArray?; 5 | Additional_Primitive additionalPrimitive?; 6 | }; 7 | 8 | public type UnSubscribe record { 9 | int zipCode?; 10 | string event; 11 | }; 12 | 13 | public type Additional_Primitive record {| 14 | string name?; 15 | decimal age?; 16 | string...; 17 | |}; 18 | 19 | public type Additional_Array record {| 20 | boolean isArray?; 21 | string[]...; 22 | |}; 23 | 24 | public type Additional_NestedArray record {| 25 | boolean isArray?; 26 | string[][]...; 27 | |}; 28 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/OneOf/nestedOneOfWithAllOf.bal: -------------------------------------------------------------------------------- 1 | public type UnSubscribe record { 2 | # Street No 3 | string streetNo?; 4 | # House number 5 | string houseNo?; 6 | # Street Name 7 | string streatName?; 8 | # Country Name 9 | string country?; 10 | string event; 11 | }|record { 12 | # Zip code 13 | int zipCode?; 14 | string event; 15 | }; 16 | 17 | public type Subscribe Time|Activity; 18 | 19 | public type Time record { 20 | int minute; 21 | string second?; 22 | string hour?; 23 | string day?; 24 | string event; 25 | }; 26 | 27 | public type Activity record { 28 | # Unique identifier for the activity 29 | string uuid?; 30 | string event; 31 | }; -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/baloutputs/QueryParam/query_param_without_default_value.bal: -------------------------------------------------------------------------------- 1 | # Query parameters as a record 2 | # 3 | public type QueryParams record {| 4 | # Offset 5 | boolean offset; 6 | # Latitude 7 | string lat; 8 | # Longtitude 9 | string lon; 10 | # exclude 11 | string exclude; 12 | # units description 13 | int units; 14 | |}; 15 | 16 | public type Message readonly & record {string event;}; 17 | 18 | public type MessageWithId readonly & record {string event; string id;}; 19 | 20 | public type Subscribe record { 21 | string id; 22 | string event; 23 | }; 24 | 25 | public type UnSubscribe record { 26 | string 'type; 27 | record {} payload?; 28 | string event; 29 | }; 30 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Nullable/nullable_false.bal: -------------------------------------------------------------------------------- 1 | public type ListObject record { 2 | }; 3 | 4 | public type UserPlayListDetails record { 5 | # A link to the Web API endpoint returning the full result of the request 6 | string? href?; 7 | # The requested data. 8 | ListObject[]? items?; 9 | # The maximum number of items in the response (as set in the query or by default). 10 | int? 'limit?; 11 | # URL to the next page of items. ( `null` if none) 12 | string next?; 13 | # The offset of the items returned (as set in the query or by default) 14 | int? offset?; 15 | # URL to the previous page of items. ( `null` if none) //anydata 16 | anydata previous?; 17 | ListObject total?; 18 | }; 19 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Nullable/nullable_record.bal: -------------------------------------------------------------------------------- 1 | public type ListObject record { 2 | }; 3 | 4 | public type UserPlayListDetails record { 5 | # A link to the Web API endpoint returning the full result of the request 6 | string href?; 7 | # The requested data. 8 | ListObject[] items?; 9 | # The maximum number of items in the response (as set in the query or by default). 10 | int 'limit?; 11 | # URL to the next page of items. ( `null` if none) 12 | string next?; 13 | # The offset of the items returned (as set in the query or by default) 14 | int offset?; 15 | # URL to the previous page of items. ( `null` if none) //anydata 16 | anydata? previous?; 17 | ListObject? total?; 18 | }; 19 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/CloseFrame/license.txt: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Nullable/nullable_option_primitive_fields.bal: -------------------------------------------------------------------------------- 1 | public type ListObject record { 2 | }; 3 | 4 | public type UserPlayListDetails record { 5 | # A link to the Web API endpoint returning the full result of the request 6 | string? href?; 7 | # The requested data. 8 | ListObject[]? items?; 9 | # The maximum number of items in the response (as set in the query or by default). 10 | int? 'limit?; 11 | # URL to the next page of items. ( `null` if none) 12 | string? next?; 13 | # The offset of the items returned (as set in the query or by default) 14 | int? offset?; 15 | # URL to the previous page of items. ( `null` if none) //anydata 16 | anydata? previous?; 17 | ListObject? total?; 18 | }; 19 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Nullable/nullable_option_record_schema.bal: -------------------------------------------------------------------------------- 1 | public type ListObject record { 2 | }; 3 | 4 | public type UserPlayListDetails record { 5 | # A link to the Web API endpoint returning the full result of the request 6 | string? href?; 7 | # The requested data. 8 | ListObject[]? items?; 9 | # The maximum number of items in the response (as set in the query or by default). 10 | int? 'limit?; 11 | # URL to the next page of items. ( `null` if none) 12 | string? next?; 13 | # The offset of the items returned (as set in the query or by default) 14 | int? offset?; 15 | # URL to the previous page of items. ( `null` if none) //anydata 16 | anydata? previous?; 17 | ListObject? total?; 18 | }; 19 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Nullable/nullale_option_array_schema.bal: -------------------------------------------------------------------------------- 1 | public type ListObject record { 2 | }; 3 | 4 | public type UserPlayListDetails record { 5 | # A link to the Web API endpoint returning the full result of the request 6 | string? href?; 7 | # The requested data. 8 | ListObject[]? items?; 9 | # The maximum number of items in the response (as set in the query or by default). 10 | int[]? 'limit?; 11 | # URL to the next page of items. ( `null` if none) 12 | string? next?; 13 | # The offset of the items returned (as set in the query or by default) 14 | int? offset?; 15 | # URL to the previous page of items. ( `null` if none) //anydata 16 | anydata[]? previous?; 17 | ListObject? total?; 18 | }; 19 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/baloutputs/HeaderParam/header_param_with_default_value.bal: -------------------------------------------------------------------------------- 1 | # Header parameters as a record 2 | # 3 | public type HeaderParams record {| 4 | # offset 5 | int offset = 5; 6 | # Latitude 7 | string lat = "78'08"; 8 | # Longtitude 9 | string lon = "90'78"; 10 | # exclude 11 | string exclude = "56'89"; 12 | # units description 13 | int units = 12; 14 | |}; 15 | 16 | public type Message readonly & record {string event;}; 17 | 18 | public type MessageWithId readonly & record {string event; string id;}; 19 | 20 | public type Subscribe record { 21 | string id; 22 | string event; 23 | }; 24 | 25 | public type UnSubscribe record { 26 | string 'type; 27 | record {} payload?; 28 | string event; 29 | }; 30 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/baloutputs/QueryParam/query_param_with_default_value.bal: -------------------------------------------------------------------------------- 1 | # Query parameters as a record 2 | # 3 | public type QueryParams record {| 4 | # Offset 5 | boolean offset = true; 6 | # Latitude 7 | string lat = "05'06'"; 8 | # Longtitude 9 | string lon = "90'05"; 10 | # exclude 11 | string exclude = "current"; 12 | # units description 13 | int units = 12; 14 | |}; 15 | 16 | public type Message readonly & record {string event;}; 17 | 18 | public type MessageWithId readonly & record {string event; string id;}; 19 | 20 | public type Subscribe record { 21 | string id; 22 | string event; 23 | }; 24 | 25 | public type UnSubscribe record { 26 | string 'type; 27 | record {} payload?; 28 | string event; 29 | }; 30 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Constraint/record_field.bal: -------------------------------------------------------------------------------- 1 | import ballerina/constraint; 2 | 3 | public type Subscribe record { 4 | Person person?; 5 | string event; 6 | Address tag; 7 | }; 8 | 9 | public type UnSubscribe record { 10 | int zipCode?; 11 | string event; 12 | }; 13 | 14 | public type Person record { 15 | @constraint:String {maxLength: 14} 16 | string name?; 17 | @constraint:Array {maxLength: 5, minLength: 2} 18 | string[] hobby?; 19 | @constraint:Int {maxValue: 5} 20 | int id; 21 | Address address?; 22 | @constraint:Float {maxValue: 100000} 23 | float salary?; 24 | @constraint:Number {minValue: 500000} 25 | decimal net?; 26 | }; 27 | 28 | @constraint:String {minLength: 5} 29 | public type Address string; 30 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/baloutputs/QueryParam/query_param_with_ref_schema.bal: -------------------------------------------------------------------------------- 1 | # Query parameters as a record 2 | # 3 | public type QueryParams record {| 4 | # Offset 5 | boolean offset = true; 6 | # Latitude 7 | Latitude lat = "78'"; 8 | # Longtitude 9 | string lon = "90'05"; 10 | # exclude 11 | string exclude = "current"; 12 | # units description 13 | int units = 12; 14 | |}; 15 | 16 | public type Message readonly & record {string event;}; 17 | 18 | public type MessageWithId readonly & record {string event; string id;}; 19 | 20 | public type Latitude string; 21 | 22 | public type Subscribe record { 23 | string id; 24 | string event; 25 | }; 26 | 27 | public type UnSubscribe record { 28 | string 'type; 29 | record {} payload?; 30 | string event; 31 | }; 32 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Array/array_with_oneOf.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | (ActivityResponseObject|EmployeeDetails)[] data?; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | }; 10 | 11 | public type ActivityResponseObject record { 12 | # Due date of the Activity. Format: YYYY-MM-DD 13 | string due_date?; 14 | # Due time of the Activity in UTC. Format: HH:MM 15 | string due_time?; 16 | # Duration of the Activity. Format: HH:MM 17 | string duration?; 18 | # The ID of the Deal this Activity is associated with 19 | int deal_id?; 20 | }; 21 | 22 | public type EmployeeDetails record { 23 | # Employee ID 24 | string employee_id?; 25 | # Employee Name 26 | string employee_name?; 27 | }; 28 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/service/project_bal/schema.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | public type Subscribe record{ 18 | int id; 19 | string type1; 20 | }; 21 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Array/array_with_allOf.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | record {*ActivityResponseObject; *EmployeeDetails;}[] data?; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | }; 10 | 11 | public type ActivityResponseObject record { 12 | # Due date of the Activity. Format: YYYY-MM-DD 13 | string due_date?; 14 | # Due time of the Activity in UTC. Format: HH:MM 15 | string due_time?; 16 | # Duration of the Activity. Format: HH:MM 17 | string duration?; 18 | # The ID of the Deal this Activity is associated with 19 | int deal_id?; 20 | }; 21 | 22 | public type EmployeeDetails record { 23 | # Employee ID 24 | string employee_id?; 25 | # Employee Name 26 | string employee_name?; 27 | }; 28 | -------------------------------------------------------------------------------- /issue_template.md: -------------------------------------------------------------------------------- 1 | **Description:** 2 | 3 | 4 | **Suggested Labels:** 5 | 6 | 7 | **Suggested Assignees:** 8 | 9 | 10 | **Affected Product Version:** 11 | 12 | **OS, DB, other environment details and versions:** 13 | 14 | **Steps to reproduce:** 15 | 16 | 17 | **Related Issues:** 18 | -------------------------------------------------------------------------------- /native.handler/java-wrapper/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | module io.ballerinax.event { 18 | requires io.ballerina.lang; 19 | requires io.ballerina.runtime; 20 | } 21 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/diagnostic_files/json_payload.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | version: 1.0.0 4 | title: OpenApi Petstore 5 | license: 6 | name: MIT 7 | servers: 8 | - url: http://petstore.{host}.io/v1 9 | description: The production API server 10 | variables: 11 | host: 12 | default: openapi 13 | description: this value is assigned by the service provider 14 | tags: 15 | - name: pets 16 | description: Pets Tag 17 | - name: list 18 | description: List Tag 19 | 20 | paths: 21 | /pets: 22 | post: 23 | summary: Create a pet 24 | operationId: createPet 25 | tags: 26 | - pets 27 | requestBody: 28 | content: 29 | application/json: 30 | schema: {} 31 | required: true 32 | responses: 33 | '201': 34 | description: Null response 35 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/diagnostic_files/xml_payload.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | version: 1.0.0 4 | title: OpenApi Petstore 5 | license: 6 | name: MIT 7 | servers: 8 | - url: http://petstore.{host}.io/v1 9 | description: The production API server 10 | variables: 11 | host: 12 | default: openapi 13 | description: this value is assigned by the service provider 14 | tags: 15 | - name: pets 16 | description: Pets Tag 17 | - name: list 18 | description: List Tag 19 | 20 | paths: 21 | /pets: 22 | post: 23 | summary: Create a pet 24 | operationId: createPet 25 | tags: 26 | - pets 27 | requestBody: 28 | content: 29 | application/xml: 30 | schema: {} 31 | description: Pet data 32 | required: true 33 | responses: 34 | '201': 35 | description: Null response 36 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Array/array_with_oneOf_complex.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | (EmployeeDetails[]|ActivityResponseObject)[] data?; 3 | string event; 4 | Request request?; 5 | }; 6 | 7 | public type UnSubscribe record { 8 | int zipCode?; 9 | string event; 10 | }; 11 | 12 | public type ActivityResponseObject record { 13 | # Due date of the Activity. Format: YYYY-MM-DD 14 | string due_date?; 15 | # Due time of the Activity in UTC. Format: HH:MM 16 | string due_time?; 17 | # Duration of the Activity. Format: HH:MM 18 | string duration?; 19 | # The ID of the Deal this Activity is associated with 20 | int deal_id?; 21 | }; 22 | 23 | public type EmployeeDetails record { 24 | # Employee ID 25 | string employee_id?; 26 | # Employee Name 27 | string employee_name?; 28 | }; 29 | 30 | public type Request (EmployeeDetails[]|ActivityResponseObject)[]; 31 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/listeners/scenario02.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/http; 18 | 19 | listener http:Listener ep0 = new (80); 20 | 21 | service /v1 on ep0 { 22 | resource function get pets(int? 'limit) returns Pets|Error { 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Nullable/nullable_array.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | Request request?; 10 | }; 11 | 12 | public type Request record { 13 | # A link to the Web API endpoint returning the full result of the request 14 | string href?; 15 | # The requested data. 16 | anydata items?; 17 | # The maximum number of items in the response (as set in the query or by default). 18 | anydata? 'limit?; 19 | # URL to the next page of items. ( `null` if none) 20 | string next?; 21 | # The offset of the items returned (as set in the query or by default) 22 | int offset?; 23 | # URL to the previous page of items. ( `null` if none) //anydata 24 | anydata? previous?; 25 | ListObject total?; 26 | }; 27 | 28 | public type ListObject record { 29 | }; 30 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Nullable/nullable_primitive.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | int pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | Request request?; 10 | }; 11 | 12 | public type Request record { 13 | # A link to the Web API endpoint returning the full result of the request 14 | string href?; 15 | # The requested data. 16 | anydata items?; 17 | # The maximum number of items in the response (as set in the query or by default). 18 | int 'limit?; 19 | # URL to the next page of items. ( `null` if none) 20 | string? next?; 21 | # The offset of the items returned (as set in the query or by default) 22 | int offset?; 23 | # URL to the previous page of items. ( `null` if none) //anydata 24 | anydata? previous?; 25 | ListObject total?; 26 | }; 27 | 28 | public type ListObject record { 29 | }; 30 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/specs/spec-single-channel-with-inline-schema.yml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.1.0 2 | channels: 3 | events/foo/1: 4 | x-ballerina-service-type: "FooService" 5 | subscribe: 6 | message: 7 | x-ballerina-event-type: "bar_event_1" 8 | externalDocs: 9 | description: Event documentation for bar_event_1 10 | url: 'https://foo.com/events/bar_event_1' 11 | payload: 12 | type: object 13 | properties: 14 | foo: 15 | $ref: '#/components/schemas/foo' 16 | data: 17 | type: array 18 | items: 19 | type: string 20 | description: Array containing all active vehicle IDs. 21 | summary: Subscribe to only the message events that mention your app or bot 22 | tags: 23 | - name: allows_user_tokens 24 | - name: app_event 25 | x-scopes-required: [] 26 | x-tokens-allowed: 27 | - user 28 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Constraint/type_def_node.bal: -------------------------------------------------------------------------------- 1 | import ballerina/constraint; 2 | 3 | public type Subscribe record { 4 | string event; 5 | }; 6 | 7 | public type UnSubscribe record { 8 | int zipCode?; 9 | string event; 10 | Person person?; 11 | }; 12 | 13 | public type Person record { 14 | @constraint:String {maxLength: 14} 15 | string name?; 16 | @constraint:Array {maxLength: 5, minLength: 2} 17 | string[] hobby?; 18 | @constraint:Int {maxValue: 5} 19 | int id; 20 | Address address?; 21 | @constraint:Float {maxValue: 100000} 22 | float salary?; 23 | @constraint:Number {minValue: 500000} 24 | decimal net?; 25 | Book fav?; 26 | }; 27 | 28 | public type Book record { 29 | @constraint:String {maxLength: 67} 30 | string name?; 31 | @constraint:Number {maxValue: 89.0} 32 | decimal price?; 33 | }; 34 | 35 | @constraint:String {minLength: 5} 36 | public type Address string; 37 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/listeners/scenario01.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/http; 18 | 19 | listener http:Listener ep0 = new (80, config = {host: petstore.openapi.io}); 20 | 21 | service /v1 on ep0 { 22 | resource function get pets(int? 'limit) returns Pets|Error { 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/OneOf/oneOfWithInlineSchemas.bal: -------------------------------------------------------------------------------- 1 | public type CountryDetails record { 2 | string iso_code?; 3 | string name?; 4 | string event; 5 | }; 6 | 7 | public type Subscribe record { 8 | int zipCode?; 9 | string event; 10 | }; 11 | 12 | public type UnSubscribe Time|Activity|record { 13 | # Street Number 14 | string streetNo?; 15 | # House Number 16 | string houseNo?; 17 | string event; 18 | }|record { 19 | # Street Name 20 | string streatName?; 21 | string event; 22 | # Country Name 23 | string country?; 24 | }|record { 25 | # Zipcode 26 | int zipCode?; 27 | string event; 28 | }|CountryDetails; 29 | 30 | public type Time record { 31 | int minute; 32 | string second?; 33 | string hour?; 34 | string day?; 35 | string event; 36 | }; 37 | 38 | public type Activity record { 39 | # Unique identifier for the activity 40 | string uuid?; 41 | string event; 42 | }; 43 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/listeners/scenario03.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/http; 18 | 19 | listener http:Listener ep0 = new (80); 20 | listener http:Listener ep1 = new (443, config = {host: petstore.openapi.io}); 21 | 22 | service /v1 on ep0, ep1 { 23 | resource function get pets(int? 'limit) returns Pets|Error { 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/optional/optional_error_return.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /: 17 | publish: 18 | message: 19 | $ref: '#/components/messages/Location' 20 | components: 21 | schemas: 22 | Location: 23 | type: object 24 | required: 25 | - id 26 | - event 27 | properties: 28 | id: 29 | type: string 30 | description: Unique identification 31 | event: 32 | type: string 33 | const: Location 34 | description: Represents location 35 | messages: 36 | Location: 37 | payload: 38 | $ref: '#/components/schemas/Location' 39 | description: Represents Snowpeak location resource 40 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Constraint/array.bal: -------------------------------------------------------------------------------- 1 | import ballerina/constraint; 2 | 3 | @constraint:String {maxLength: 23} 4 | public type HobbyItemsString string; 5 | 6 | @constraint:String {minLength: 7} 7 | public type PersonDetailsItemsString string; 8 | 9 | @constraint:Float {maxValue: 445.4} 10 | public type PersonFeeItemsNumber float; 11 | 12 | @constraint:Array {maxLength: 5, minLength: 2} 13 | public type Hobby HobbyItemsString[]; 14 | 15 | public type Subscribe record { 16 | Person person?; 17 | string event; 18 | Address tag; 19 | }; 20 | 21 | public type UnSubscribe record { 22 | int zipCode?; 23 | string event; 24 | }; 25 | 26 | public type Person record { 27 | Hobby hobby?; 28 | @constraint:Array {maxLength: 5} 29 | PersonDetailsItemsString[] Details?; 30 | int id; 31 | PersonFeeItemsNumber[] fee?; 32 | # The maximum number of items in the response (as set in the query or by default). 33 | anydata 'limit?; 34 | }; 35 | 36 | @constraint:String {minLength: 5} 37 | public type Address string; 38 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/headers/header_scenario06.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/http; 18 | 19 | listener http:Listener helloEp = new (9090); 20 | 21 | @http:ServiceConfig { 22 | treatNilableAsOptional: false 23 | } 24 | service /payloadV on helloEp { 25 | resource function get ping(@http:Header string? headerValue) returns http:Ok { 26 | http:Ok ok = {body: ()}; 27 | return ok; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/headers/header_scenario09.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/http; 18 | 19 | listener http:Listener helloEp = new (9090); 20 | 21 | @http:ServiceConfig { 22 | treatNilableAsOptional: false 23 | } 24 | service /payloadV on helloEp { 25 | resource function get ping(@http:Header string? headerValue = "default") returns http:Ok { 26 | http:Ok ok = {body: ()}; 27 | return ok; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/response/rs_scenario04_builtin.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /: 17 | subscribe: 18 | message: 19 | payload: 20 | type: string 21 | publish: 22 | message: 23 | $ref: '#/components/messages/Subscribe' 24 | components: 25 | schemas: 26 | Subscribe: 27 | type: object 28 | required: 29 | - id 30 | - event 31 | properties: 32 | id: 33 | type: integer 34 | format: int64 35 | event: 36 | type: string 37 | const: Subscribe 38 | messages: 39 | Subscribe: 40 | payload: 41 | $ref: '#/components/schemas/Subscribe' 42 | x-response: 43 | payload: 44 | type: string 45 | x-response-type: simple-rpc 46 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/main/java/io/ballerina/asyncapi/codegenerator/usecase/Generator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package io.ballerina.asyncapi.codegenerator.usecase; 20 | 21 | import io.ballerina.asyncapi.codegenerator.configuration.BallerinaAsyncApiException; 22 | 23 | /** 24 | * Interface for the use cases related to the Ballerina code generation. 25 | */ 26 | public interface Generator { 27 | T generate() throws BallerinaAsyncApiException; 28 | } 29 | -------------------------------------------------------------------------------- /.github/workflows/release-native-handler.yml: -------------------------------------------------------------------------------- 1 | name: Release AsyncAPI native handler library 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | publish-release: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout Repository 11 | uses: actions/checkout@v3 12 | 13 | - name: Set up JDK 21 14 | uses: actions/setup-java@v3 15 | with: 16 | distribution: 'adopt' 17 | java-version: 21.0.3 18 | 19 | - name: Build the Package 20 | env: 21 | GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }} 22 | packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} 23 | packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} 24 | run: | 25 | ./gradlew build -x test 26 | 27 | - name: Set Up Ballerina 28 | uses: ballerina-platform/setup-ballerina@v1.1.3 29 | with: 30 | version: 2201.11.0 31 | 32 | - name: Release the package 33 | env: 34 | BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }} 35 | working-directory: native.handler 36 | run: | 37 | bal pack 38 | bal push 39 | 40 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/java/io/ballerina/asyncapi/codegenerator/usecase/Extractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package io.ballerina.asyncapi.codegenerator.usecase; 20 | 21 | import io.ballerina.asyncapi.codegenerator.configuration.BallerinaAsyncApiException; 22 | 23 | /** 24 | * Interface for the use cases related to the data extraction from the AsyncAPI specification. 25 | */ 26 | public interface Extractor { 27 | T extract() throws BallerinaAsyncApiException; 28 | } 29 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/advance/multiple_service_02.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: / 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "80" 15 | channels: 16 | /hi: 17 | subscribe: 18 | message: 19 | payload: 20 | type: integer 21 | format: int64 22 | publish: 23 | message: 24 | $ref: '#/components/messages/Subscribe' 25 | components: 26 | schemas: 27 | Subscribe: 28 | type: object 29 | required: 30 | - id 31 | - type1 32 | properties: 33 | id: 34 | type: integer 35 | format: int64 36 | type1: 37 | type: string 38 | const: Subscribe 39 | messages: 40 | Subscribe: 41 | payload: 42 | $ref: '#/components/schemas/Subscribe' 43 | x-response: 44 | payload: 45 | type: integer 46 | format: int64 47 | x-response-type: simple-rpc 48 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/advance/multiple_service_03.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: "" 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "80" 15 | channels: 16 | /hi: 17 | subscribe: 18 | message: 19 | payload: 20 | type: integer 21 | format: int64 22 | publish: 23 | message: 24 | $ref: '#/components/messages/Subscribe' 25 | components: 26 | schemas: 27 | Subscribe: 28 | type: object 29 | required: 30 | - id 31 | - type1 32 | properties: 33 | id: 34 | type: integer 35 | format: int64 36 | type1: 37 | type: string 38 | const: Subscribe 39 | messages: 40 | Subscribe: 41 | payload: 42 | $ref: '#/components/schemas/Subscribe' 43 | x-response: 44 | payload: 45 | type: integer 46 | format: int64 47 | x-response-type: simple-rpc 48 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/advance/multiple_service_01.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: Hello 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/hello" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "80" 15 | channels: 16 | /hi: 17 | subscribe: 18 | message: 19 | payload: 20 | type: integer 21 | format: int64 22 | publish: 23 | message: 24 | $ref: '#/components/messages/Subscribe' 25 | components: 26 | schemas: 27 | Subscribe: 28 | type: object 29 | required: 30 | - id 31 | - type1 32 | properties: 33 | id: 34 | type: integer 35 | format: int64 36 | type1: 37 | type: string 38 | const: Subscribe 39 | messages: 40 | Subscribe: 41 | payload: 42 | $ref: '#/components/schemas/Subscribe' 43 | x-response: 44 | payload: 45 | type: integer 46 | format: int64 47 | x-response-type: simple-rpc 48 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/response/rs_scenario08_float.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /: 17 | subscribe: 18 | message: 19 | payload: 20 | type: number 21 | format: float 22 | publish: 23 | message: 24 | $ref: '#/components/messages/Subscribe' 25 | components: 26 | schemas: 27 | Subscribe: 28 | type: object 29 | required: 30 | - id 31 | - event 32 | properties: 33 | id: 34 | type: integer 35 | format: int64 36 | event: 37 | type: string 38 | const: Subscribe 39 | messages: 40 | Subscribe: 41 | payload: 42 | $ref: '#/components/schemas/Subscribe' 43 | x-response: 44 | payload: 45 | type: number 46 | format: float 47 | x-response-type: simple-rpc 48 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/main/java/io/ballerina/asyncapi/codegenerator/controller/BalController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package io.ballerina.asyncapi.codegenerator.controller; 20 | 21 | import io.ballerina.asyncapi.codegenerator.configuration.BallerinaAsyncApiException; 22 | 23 | /** 24 | * This is the Interface used for Ballerina code generation related Controllers. 25 | */ 26 | public interface BalController { 27 | String generateBalCode(String balTemplate) throws BallerinaAsyncApiException; 28 | } 29 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/query/query_scenario05.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/http; 18 | 19 | @http:ServiceConfig { 20 | treatNilableAsOptional: false 21 | } 22 | service /payloadV on new http:Listener(9090) { 23 | # Mock example 24 | # 25 | # + pet - Mock optional query parameter Description 26 | # + return - Return Value Description 27 | resource function get pets(decimal? pet) returns http:Ok { 28 | http:Ok ok = {body: ()}; 29 | return ok; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/listeners/with_check_key_word.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "8080" 15 | channels: 16 | /: 17 | subscribe: 18 | message: 19 | payload: 20 | type: integer 21 | format: int64 22 | publish: 23 | message: 24 | $ref: '#/components/messages/Subscribe' 25 | components: 26 | schemas: 27 | Subscribe: 28 | type: object 29 | required: 30 | - id 31 | - event 32 | properties: 33 | id: 34 | type: integer 35 | format: int64 36 | event: 37 | type: string 38 | const: Subscribe 39 | messages: 40 | Subscribe: 41 | payload: 42 | $ref: '#/components/schemas/Subscribe' 43 | x-response: 44 | payload: 45 | type: integer 46 | format: int64 47 | x-response-type: simple-rpc 48 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/response/rs_scenario09_decimal.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /: 17 | subscribe: 18 | message: 19 | payload: 20 | type: number 21 | format: double 22 | publish: 23 | message: 24 | $ref: '#/components/messages/Subscribe' 25 | components: 26 | schemas: 27 | Subscribe: 28 | type: object 29 | required: 30 | - id 31 | - event 32 | properties: 33 | id: 34 | type: integer 35 | format: int64 36 | event: 37 | type: string 38 | const: Subscribe 39 | messages: 40 | Subscribe: 41 | payload: 42 | $ref: '#/components/schemas/Subscribe' 43 | x-response: 44 | payload: 45 | type: number 46 | format: double 47 | x-response-type: simple-rpc 48 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/listeners/listener_scenario02.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "80" 15 | channels: 16 | /pathParam: 17 | subscribe: 18 | message: 19 | payload: 20 | type: integer 21 | format: int64 22 | publish: 23 | message: 24 | $ref: '#/components/messages/Subscribe' 25 | components: 26 | schemas: 27 | Subscribe: 28 | type: object 29 | required: 30 | - id 31 | - event 32 | properties: 33 | id: 34 | type: integer 35 | format: int64 36 | event: 37 | type: string 38 | const: Subscribe 39 | messages: 40 | Subscribe: 41 | payload: 42 | $ref: '#/components/schemas/Subscribe' 43 | x-response: 44 | payload: 45 | type: integer 46 | format: int64 47 | x-response-type: simple-rpc 48 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/main/java/io/ballerina/asyncapi/codegenerator/application/Application.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package io.ballerina.asyncapi.codegenerator.application; 20 | 21 | import io.ballerina.asyncapi.codegenerator.configuration.BallerinaAsyncApiException; 22 | 23 | /** 24 | * This is the interface of the application, Async API CMD class uses this interface. 25 | */ 26 | public interface Application { 27 | void generate(String specPath, String outputPath) throws BallerinaAsyncApiException; 28 | } 29 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/listeners/listener_scenario01.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://www.asyncapi.com 13 | port: 14 | default: "80" 15 | channels: 16 | /pathParam: 17 | subscribe: 18 | message: 19 | payload: 20 | type: integer 21 | format: int64 22 | publish: 23 | message: 24 | $ref: '#/components/messages/Subscribe' 25 | components: 26 | schemas: 27 | Subscribe: 28 | type: object 29 | required: 30 | - id 31 | - event 32 | properties: 33 | id: 34 | type: integer 35 | format: int64 36 | event: 37 | type: string 38 | const: Subscribe 39 | messages: 40 | Subscribe: 41 | payload: 42 | $ref: '#/components/schemas/Subscribe' 43 | x-response: 44 | payload: 45 | type: integer 46 | format: int64 47 | x-response-type: simple-rpc 48 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/response/rs_scenario06_xml.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /: 17 | subscribe: 18 | message: 19 | payload: 20 | type: object 21 | additionalProperties: {} 22 | publish: 23 | message: 24 | $ref: '#/components/messages/Subscribe' 25 | components: 26 | schemas: 27 | Subscribe: 28 | type: object 29 | required: 30 | - id 31 | - event 32 | properties: 33 | id: 34 | type: integer 35 | format: int64 36 | event: 37 | type: string 38 | const: Subscribe 39 | messages: 40 | Subscribe: 41 | payload: 42 | $ref: '#/components/schemas/Subscribe' 43 | x-response: 44 | payload: 45 | type: object 46 | additionalProperties: {} 47 | x-response-type: simple-rpc 48 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/response/rs_scenario01_json.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /hello: 17 | subscribe: 18 | message: 19 | payload: 20 | type: object 21 | additionalProperties: {} 22 | publish: 23 | message: 24 | $ref: '#/components/messages/Subscribe' 25 | components: 26 | schemas: 27 | Subscribe: 28 | type: object 29 | required: 30 | - id 31 | - event 32 | properties: 33 | id: 34 | type: integer 35 | format: int64 36 | event: 37 | type: string 38 | const: Subscribe 39 | messages: 40 | Subscribe: 41 | payload: 42 | $ref: '#/components/schemas/Subscribe' 43 | x-response: 44 | payload: 45 | type: object 46 | additionalProperties: {} 47 | x-response-type: simple-rpc 48 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/apidoc/resource_function.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /locations: 17 | description: Represents Snowpeak location resource 18 | subscribe: 19 | message: 20 | payload: 21 | type: integer 22 | format: int64 23 | publish: 24 | message: 25 | $ref: '#/components/messages/Subscribe' 26 | components: 27 | schemas: 28 | Subscribe: 29 | type: object 30 | required: 31 | - id 32 | - event 33 | properties: 34 | id: 35 | type: integer 36 | format: int64 37 | event: 38 | type: string 39 | const: Subscribe 40 | messages: 41 | Subscribe: 42 | payload: 43 | $ref: '#/components/schemas/Subscribe' 44 | x-response: 45 | payload: 46 | type: integer 47 | format: int64 48 | x-response-type: simple-rpc 49 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/main/java/io/ballerina/asyncapi/websocketscore/exception/BallerinaAsyncApiExceptionWs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | package io.ballerina.asyncapi.websocketscore.exception; 19 | 20 | /** 21 | * Exception type definition for AsyncApi to Ballerina parsing related errors. 22 | * 23 | */ 24 | public class BallerinaAsyncApiExceptionWs extends Exception { 25 | public BallerinaAsyncApiExceptionWs(String message, Throwable e) { 26 | super(message, e); 27 | } 28 | 29 | public BallerinaAsyncApiExceptionWs(String message) { 30 | super(message); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/diagnostic_files/duplicated_response.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | version: 1.0.0 4 | title: OpenApi Petstore 5 | license: 6 | name: MIT 7 | servers: 8 | - url: https://petstore/v1 9 | description: The production API server 10 | paths: 11 | /pets: 12 | get: 13 | summary: Get a pet 14 | operationId: getPet 15 | description: "Get pet details" 16 | responses: 17 | '200': 18 | description: The status information is returned for the requested file upload. 19 | content: 20 | application/json: 21 | schema: 22 | $ref: '#/components/schemas/PetDetails' 23 | '202': 24 | description: The status information is returned for the requested file upload. 25 | content: 26 | application/json: 27 | schema: 28 | $ref: '#/components/schemas/PetDetails' 29 | '204': 30 | description: The status information cannot be retrieved for the specified request ID. 31 | content: {} 32 | components: 33 | schemas: 34 | PetDetails: 35 | properties: 36 | name: 37 | type: string 38 | age: 39 | type: string 40 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/java/io/ballerina/asyncapi/codegenerator/configuration/BallerinaAsyncApiException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package io.ballerina.asyncapi.codegenerator.configuration; 20 | 21 | /** 22 | * Exception type definition for AsyncApi to Ballerina parsing related errors. 23 | */ 24 | public class BallerinaAsyncApiException extends Exception { 25 | public BallerinaAsyncApiException(String message, Throwable e) { 26 | super(message, e); 27 | } 28 | 29 | public BallerinaAsyncApiException(String message) { 30 | super(message); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/java/io/ballerina/asyncapi/websocketscore/ErrorMessages.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | package io.ballerina.asyncapi.websocketscore; 19 | 20 | /** 21 | * Container for error messages of the AsyncAPI command. 22 | * 23 | */ 24 | public class ErrorMessages { 25 | 26 | public static String invalidFilePath(String path) { 27 | return String.format("AsyncAPI contract doesn't exist in the given location:%n%s", path); 28 | } 29 | 30 | public static String invalidFileType() { 31 | return "Invalid file type. Provide either a .yaml or .json file."; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/diagnostic_files/xml_payload_with_ref.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | version: 1.0.0 4 | title: OpenApi Petstore 5 | license: 6 | name: MIT 7 | servers: 8 | - url: http://petstore.{host}.io/v1 9 | description: The production API server 10 | variables: 11 | host: 12 | default: openapi 13 | description: this value is assigned by the service provider 14 | tags: 15 | - name: pets 16 | description: Pets Tag 17 | - name: list 18 | description: List Tag 19 | 20 | paths: 21 | /pets: 22 | post: 23 | summary: Create a pet 24 | operationId: createPet 25 | tags: 26 | - pets 27 | requestBody: 28 | content: 29 | application/xml: 30 | schema: 31 | $ref: '#/components/schemas/Pet' 32 | description: Pet data 33 | required: true 34 | responses: 35 | '201': 36 | description: Null response 37 | components: 38 | schemas: 39 | Pet: 40 | required: 41 | - id 42 | - name 43 | properties: 44 | id: 45 | type: integer 46 | format: int64 47 | name: 48 | type: string 49 | tag: 50 | type: string 51 | type: 52 | type: string -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/baloutputs/Util/default_util.bal: -------------------------------------------------------------------------------- 1 | import xlibb/pipe; 2 | 3 | # PipesMap class to handle generated pipes 4 | public isolated class PipesMap { 5 | private final map pipes; 6 | 7 | public isolated function init() { 8 | self.pipes = {}; 9 | } 10 | 11 | public isolated function addPipe(string id, pipe:Pipe pipe) { 12 | lock { 13 | self.pipes[id] = pipe; 14 | } 15 | } 16 | 17 | public isolated function getPipe(string id) returns pipe:Pipe { 18 | lock { 19 | if (self.pipes.hasKey(id)) { 20 | return self.pipes.get(id); 21 | } 22 | pipe:Pipe pipe = new (100); 23 | self.addPipe(id, pipe); 24 | return pipe; 25 | } 26 | } 27 | 28 | public isolated function removePipe(string id) returns error? { 29 | lock { 30 | _ = check self.getPipe(id).gracefulClose(); 31 | _ = self.pipes.remove(id); 32 | } 33 | } 34 | 35 | public isolated function removePipes() returns error? { 36 | lock { 37 | foreach pipe:Pipe pipe in self.pipes { 38 | check pipe.gracefulClose(); 39 | } 40 | self.pipes.removeAll(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /native.handler/Dependencies.toml: -------------------------------------------------------------------------------- 1 | # AUTO-GENERATED FILE. DO NOT MODIFY. 2 | 3 | # This file is auto-generated by Ballerina for managing dependency versions. 4 | # It should not be modified by hand. 5 | 6 | [ballerina] 7 | dependencies-toml-version = "2" 8 | distribution-version = "2201.11.0" 9 | 10 | [[package]] 11 | org = "ballerina" 12 | name = "jballerina.java" 13 | version = "0.0.0" 14 | modules = [ 15 | {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} 16 | ] 17 | 18 | [[package]] 19 | org = "ballerina" 20 | name = "observe" 21 | version = "1.4.0" 22 | dependencies = [ 23 | {org = "ballerina", name = "jballerina.java"} 24 | ] 25 | 26 | [[package]] 27 | org = "ballerinai" 28 | name = "observe" 29 | version = "0.0.0" 30 | dependencies = [ 31 | {org = "ballerina", name = "jballerina.java"}, 32 | {org = "ballerina", name = "observe"} 33 | ] 34 | modules = [ 35 | {org = "ballerinai", packageName = "observe", moduleName = "observe"} 36 | ] 37 | 38 | [[package]] 39 | org = "ballerinax" 40 | name = "asyncapi.native.handler" 41 | version = "0.5.1-SNAPSHOT" 42 | dependencies = [ 43 | {org = "ballerina", name = "jballerina.java"}, 44 | {org = "ballerinai", name = "observe"} 45 | ] 46 | modules = [ 47 | {org = "ballerinax", packageName = "asyncapi.native.handler", moduleName = "asyncapi.native.handler"} 48 | ] 49 | 50 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | module io.ballerina.asyncapi { 20 | requires apicurio.data.models; 21 | requires info.picocli; 22 | requires io.ballerina.cli; 23 | requires io.ballerina.tools.api; 24 | requires io.ballerina.parser; 25 | requires io.ballerina.formatter.core; 26 | requires io.ballerina.runtime; 27 | requires org.apache.commons.io; 28 | requires com.fasterxml.jackson.databind; 29 | requires com.fasterxml.jackson.dataformat.yaml; 30 | requires java.sql; 31 | requires io.ballerina.lang; 32 | requires org.apache.commons.lang3; 33 | requires org.slf4j; 34 | } 35 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/response/rs_scenario08_float.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | @websocket:ServiceConfig {dispatcherKey: "event"} 20 | service /payloadV on new websocket:Listener(9090) { 21 | resource function get .() returns websocket:Service|websocket:Error { 22 | return new WsService(); 23 | } 24 | } 25 | 26 | service class WsService { 27 | *websocket:Service; 28 | 29 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns float { 30 | return 1.0; 31 | } 32 | } 33 | 34 | public type Subscribe record { 35 | int id; 36 | string event; 37 | }; 38 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/response/rs_scenario09_decimal.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | @websocket:ServiceConfig {dispatcherKey: "event"} 20 | service /payloadV on new websocket:Listener(9090) { 21 | resource function get .() returns websocket:Service|websocket:Error { 22 | return new WsService(); 23 | } 24 | } 25 | 26 | service class WsService { 27 | *websocket:Service; 28 | 29 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns decimal { 30 | return 1.0; 31 | } 32 | } 33 | 34 | public type Subscribe record { 35 | int id; 36 | string event; 37 | }; 38 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/close_frame/normal_closure.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | listener websocket:Listener websocketListener2 = check new (9092); 20 | 21 | @websocket:ServiceConfig {dispatcherKey: "event"} 22 | service / on websocketListener2 { 23 | 24 | resource function get .() returns websocket:Service|websocket:UpgradeError { 25 | return new WsService2(); 26 | } 27 | } 28 | 29 | service class WsService2 { 30 | *websocket:Service; 31 | 32 | remote function onHello(Hello clientData) returns websocket:NormalClosure { 33 | return websocket:NORMAL_CLOSURE; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/service/rabbitmq_service.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/log; 18 | import ballerinax/rabbitmq; 19 | 20 | public type Order record { 21 | int orderId; 22 | string productName; 23 | decimal price; 24 | boolean isValid; 25 | }; 26 | 27 | // The consumer service listens to the "OrderQueue" queue. 28 | service "query" on new rabbitmq:Listener(rabbitmq:DEFAULT_HOST, rabbitmq:DEFAULT_PORT) { 29 | 30 | remote function onMessage(Order 'order) returns error? { 31 | if 'order.isValid { 32 | log:printInfo(string `Received valid order for ${'order.productName}`); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/response/rs_scenario04_builtin.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | @websocket:ServiceConfig {dispatcherKey: "event"} 20 | service /payloadV on new websocket:Listener(9090) { 21 | resource function get .() returns websocket:Service|websocket:Error { 22 | return new WsService(); 23 | } 24 | } 25 | 26 | service class WsService { 27 | *websocket:Service; 28 | 29 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns string{ 30 | return "subscribed"; 31 | } 32 | } 33 | 34 | public type Subscribe record{ 35 | int id; 36 | string event; 37 | }; 38 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/service/project_bal/record_request_service.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | listener websocket:Listener ep0 = new(9090); 20 | 21 | 22 | @websocket:ServiceConfig {subProtocols: [],dispatcherKey: "type1"} 23 | service /payloadV on ep0{ 24 | resource function get hi(int param) returns websocket:Service|websocket:UpgradeError { 25 | return new ChatServer(); 26 | } 27 | 28 | } 29 | 30 | service class ChatServer{ 31 | *websocket:Service; 32 | 33 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns int { 34 | return 5; 35 | } 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/response/rs_scenario01_json.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | @websocket:ServiceConfig {dispatcherKey: "event"} 20 | service /payloadV on new websocket:Listener(9090) { 21 | resource function get hello() returns websocket:Service|websocket:Error { 22 | return new WsService(); 23 | } 24 | } 25 | 26 | service class WsService { 27 | *websocket:Service; 28 | 29 | remote isolated function onSubscribe(websocket:Caller caller, Subscribe data) returns json { 30 | return "Hello World!"; 31 | } 32 | } 33 | 34 | public type Subscribe record{ 35 | int id; 36 | string event; 37 | }; 38 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/listeners/listener_scenario03.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | enum: 13 | - ws://www.asyncapi.com 14 | - ws://localhost 15 | default: ws://localhost 16 | port: 17 | enum: 18 | - "443" 19 | - "80" 20 | default: "80" 21 | channels: 22 | /pathParam: 23 | subscribe: 24 | message: 25 | payload: 26 | type: integer 27 | format: int64 28 | publish: 29 | message: 30 | $ref: '#/components/messages/Subscribe' 31 | components: 32 | schemas: 33 | Subscribe: 34 | type: object 35 | required: 36 | - id 37 | - event 38 | properties: 39 | id: 40 | type: integer 41 | format: int64 42 | event: 43 | type: string 44 | const: Subscribe 45 | messages: 46 | Subscribe: 47 | payload: 48 | $ref: '#/components/schemas/Subscribe' 49 | x-response: 50 | payload: 51 | type: integer 52 | format: int64 53 | x-response-type: simple-rpc 54 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/listeners/listener_scenario04.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | enum: 13 | - ws://www.asyncapi.com 14 | - ws://localhost 15 | default: ws://localhost 16 | port: 17 | enum: 18 | - "443" 19 | - "80" 20 | default: "80" 21 | channels: 22 | /pathParam: 23 | subscribe: 24 | message: 25 | payload: 26 | type: integer 27 | format: int64 28 | publish: 29 | message: 30 | $ref: '#/components/messages/Subscribe' 31 | components: 32 | schemas: 33 | Subscribe: 34 | type: object 35 | required: 36 | - id 37 | - event 38 | properties: 39 | id: 40 | type: integer 41 | format: int64 42 | event: 43 | type: string 44 | const: Subscribe 45 | messages: 46 | Subscribe: 47 | payload: 48 | $ref: '#/components/schemas/Subscribe' 49 | x-response: 50 | payload: 51 | type: integer 52 | format: int64 53 | x-response-type: simple-rpc 54 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Reference/multiple_references.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | anydata pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | }; 10 | 11 | public type Indicator record { 12 | string id?; 13 | string value?; 14 | }; 15 | 16 | public type Country record { 17 | string id?; 18 | string value?; 19 | }; 20 | 21 | public type AccessToElectricity record { 22 | Indicator indicator?; 23 | Country country?; 24 | string date?; 25 | int value?; 26 | int 'decimal?; 27 | }; 28 | 29 | public type YouthLiteracyRate record { 30 | Indicator indicator?; 31 | Country country?; 32 | string date?; 33 | int value?; 34 | int 'decimal?; 35 | }; 36 | 37 | public type GrossDomesticProduct record { 38 | Indicator indicator?; 39 | Country country?; 40 | string date?; 41 | int value?; 42 | int 'decimal?; 43 | }; 44 | 45 | public type PrimaryEducationExpenditure record { 46 | Indicator indicator?; 47 | Country country?; 48 | string date?; 49 | int value?; 50 | int 'decimal?; 51 | }; 52 | 53 | public type CountryPoplutation record { 54 | Indicator indicator?; 55 | Country country?; 56 | string date?; 57 | int value?; 58 | int 'decimal?; 59 | }; 60 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/query/query_scenario02.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | @websocket:ServiceConfig {dispatcherKey: "event"} 20 | service /payloadV on new websocket:Listener(9090) { 21 | resource function get .(int? offset) returns websocket:Service|websocket:Error { 22 | return new WsService(); 23 | } 24 | } 25 | 26 | service class WsService { 27 | *websocket:Service; 28 | 29 | remote isolated function onSubscribe(websocket:Caller caller, Subscribe data) returns string? { 30 | return "Hello World!"; 31 | } 32 | } 33 | 34 | public type Subscribe record{ 35 | int id; 36 | string event; 37 | }; 38 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/query/query_scenario04.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | @websocket:ServiceConfig {dispatcherKey: "event"} 20 | service /payloadV on new websocket:Listener(9090) { 21 | resource function get .(int[]? pet) returns websocket:Service|websocket:Error { 22 | return new WsService(); 23 | } 24 | } 25 | 26 | service class WsService { 27 | *websocket:Service; 28 | 29 | remote isolated function onSubscribe(websocket:Caller caller, Subscribe data) returns string? { 30 | return "Hello World!"; 31 | } 32 | } 33 | 34 | public type Subscribe record{ 35 | int id; 36 | string event; 37 | }; 38 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/listeners/listener_scenario05.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | enum: 13 | - ws://www.asyncapi.com 14 | - ws://localhost 15 | default: ws://localhost 16 | port: 17 | enum: 18 | - "443" 19 | - "8080" 20 | default: "8080" 21 | channels: 22 | /pathParam: 23 | subscribe: 24 | message: 25 | payload: 26 | type: integer 27 | format: int64 28 | publish: 29 | message: 30 | $ref: '#/components/messages/Subscribe' 31 | components: 32 | schemas: 33 | Subscribe: 34 | type: object 35 | required: 36 | - id 37 | - event 38 | properties: 39 | id: 40 | type: integer 41 | format: int64 42 | event: 43 | type: string 44 | const: Subscribe 45 | messages: 46 | Subscribe: 47 | payload: 48 | $ref: '#/components/schemas/Subscribe' 49 | x-response: 50 | payload: 51 | type: integer 52 | format: int64 53 | x-response-type: simple-rpc 54 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/close_frame/close_frame.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | listener websocket:Listener websocketListener = check new (9092); 20 | 21 | @websocket:ServiceConfig {dispatcherKey: "event"} 22 | service / on websocketListener { 23 | 24 | resource function get .() returns websocket:Service|websocket:UpgradeError { 25 | return new WsService(); 26 | } 27 | } 28 | 29 | service class WsService { 30 | *websocket:Service; 31 | 32 | remote function onHello(Hello clientData) returns Response|websocket:CloseFrame? { 33 | return {message: "You sent: " + clientData.message}; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/close_frame/close_frame_and_stream.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | listener websocket:Listener l6 = check new (9092); 20 | 21 | @websocket:ServiceConfig {dispatcherKey: "event"} 22 | service / on l6 { 23 | 24 | resource function get .() returns websocket:Service|websocket:UpgradeError { 25 | return new WsService6(); 26 | } 27 | } 28 | 29 | service class WsService6 { 30 | *websocket:Service; 31 | 32 | isolated remote function onHello(Hello clientData) returns stream|websocket:CloseFrame? { 33 | int[] arr = [1, 2, 3]; 34 | return arr.toStream(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/query/query_scenario01.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | @websocket:ServiceConfig {dispatcherKey: "event"} 20 | service /payloadV on new websocket:Listener(9090) { 21 | resource function get .(int offset) returns websocket:Service|websocket:Error { 22 | return new WsService(); 23 | } 24 | } 25 | 26 | service class WsService { 27 | *websocket:Service; 28 | 29 | remote isolated function onSubscribe(websocket:Caller caller, Subscribe data) returns string? { 30 | return "Hello World!"; 31 | } 32 | } 33 | 34 | 35 | public type Subscribe record{ 36 | int id; 37 | string event; 38 | }; 39 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/query/query_scenario03.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | @websocket:ServiceConfig {dispatcherKey: "event"} 20 | service /payloadV on new websocket:Listener(9090) { 21 | resource function get .(string[] tags) returns websocket:Service|websocket:Error { 22 | return new WsService(); 23 | } 24 | } 25 | 26 | service class WsService { 27 | *websocket:Service; 28 | 29 | remote isolated function onSubscribe(websocket:Caller caller, Subscribe data) returns string? { 30 | return "Hello World!"; 31 | } 32 | } 33 | 34 | public type Subscribe record{ 35 | int id; 36 | string event; 37 | }; 38 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/query/query_scenario07.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | @websocket:ServiceConfig {dispatcherKey: "event"} 20 | service /payloadV on new websocket:Listener(9090) { 21 | resource function get hello(int?[] test) returns websocket:Service|websocket:Error { 22 | return new WsService(); 23 | } 24 | } 25 | 26 | service class WsService { 27 | *websocket:Service; 28 | 29 | remote isolated function onSubscribe(websocket:Caller caller, Subscribe data) returns string? { 30 | return "Hello World!"; 31 | } 32 | } 33 | 34 | public type Subscribe record{ 35 | int id; 36 | string event; 37 | }; 38 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/asyncapi_info/project01/project01.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | public type Subscribe record{ 20 | int id; 21 | string event; 22 | }; 23 | 24 | listener websocket:Listener ep0 = new(9090); 25 | @websocket:ServiceConfig{dispatcherKey: "event"} 26 | service /payloadV on ep0 { 27 | resource function get pets () returns websocket:Service|websocket:Error { 28 | return new ChatServer(); 29 | } 30 | } 31 | 32 | service class ChatServer{ 33 | *websocket:Service; 34 | 35 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns int { 36 | return 5; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/listeners/listener_scenario02.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | listener websocket:Listener ep0 = new (80); 20 | 21 | public type Subscribe record{ 22 | int id; 23 | string event; 24 | }; 25 | 26 | @websocket:ServiceConfig{dispatcherKey: "event"} 27 | service /payloadV on ep0 { 28 | resource function get pathParam() returns websocket:Service|websocket:UpgradeError { 29 | return new ChatServer(); 30 | } 31 | } 32 | 33 | service class ChatServer{ 34 | *websocket:Service; 35 | 36 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns int { 37 | return 5; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/listeners/listener_http_load_balancer.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | listener websocket:Listener ep1 = check new (8080); 20 | 21 | public type Subscribe record{ 22 | int id; 23 | string event; 24 | }; 25 | 26 | @websocket:ServiceConfig{dispatcherKey: "event"} 27 | service /payloadV on ep1 { 28 | resource function get .() returns websocket:Service|websocket:UpgradeError { 29 | return new ChatServer(); 30 | } 31 | } 32 | 33 | service class ChatServer{ 34 | *websocket:Service; 35 | 36 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns int { 37 | return 5; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/java/io/ballerina/asyncapi/codegenerator/entity/RemoteFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package io.ballerina.asyncapi.codegenerator.entity; 20 | 21 | /** 22 | * Entity used for remote function definition. 23 | */ 24 | public class RemoteFunction { 25 | private final String funcName; 26 | private final String eventType; 27 | 28 | public RemoteFunction(String funcName, String eventType) { 29 | this.funcName = funcName; 30 | this.eventType = eventType; 31 | } 32 | 33 | public String getEventName() { 34 | return funcName; 35 | } 36 | 37 | public String getEventType() { 38 | return eventType; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/close_frame/types.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | type Hello record {| 18 | string message; 19 | string event; 20 | |}; 21 | 22 | type HelloError record {| 23 | string message; 24 | string event; 25 | |}; 26 | 27 | type Response record {| 28 | string event = "just a message"; 29 | string message; 30 | |}; 31 | 32 | public type Heartbeat record { 33 | int heartbeatId; 34 | string event; 35 | }; 36 | 37 | public type HeartbeatResponse record { 38 | int id; 39 | }; 40 | 41 | public type Subscribe record { 42 | int subscribeId; 43 | string event; 44 | }; 45 | 46 | public type SubscribeResponse record { 47 | int id; 48 | }; 49 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/response/rs_scenario06_xml.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | @websocket:ServiceConfig {dispatcherKey: "event"} 20 | service /payloadV on new websocket:Listener(9090) { 21 | resource function get .() returns websocket:Service|websocket:Error { 22 | return new WsService(); 23 | } 24 | } 25 | 26 | service class WsService { 27 | *websocket:Service; 28 | 29 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns xml { 30 | xml x1 = xml `The Lost World`; 31 | return x1; 32 | } 33 | } 34 | 35 | public type Subscribe record { 36 | int id; 37 | string event; 38 | }; 39 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/alias/websocket.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket as ws; 18 | import ballerina/http; 19 | 20 | listener ws:Listener helloEp = new (9090); 21 | 22 | public type Subscribe record{ 23 | int id; 24 | string event; 25 | }; 26 | 27 | @ws:ServiceConfig{dispatcherKey: "event"} 28 | service /payloadV on helloEp { 29 | resource function get ping(@http:Header string headerValue) returns ws:Service|ws:UpgradeError { 30 | return new ChatServer(); 31 | } 32 | } 33 | 34 | service class ChatServer{ 35 | *ws:Service; 36 | 37 | remote function onSubscribe(ws:Caller caller, Subscribe message) returns int { 38 | return 5; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/response/rs_scenario05_inline_record_builtin.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | @websocket:ServiceConfig {dispatcherKey: "event"} 20 | service /payloadV on new websocket:Listener(9090) { 21 | resource function get .() returns websocket:Service|websocket:Error { 22 | return new WsService(); 23 | } 24 | } 25 | 26 | service class WsService { 27 | *websocket:Service; 28 | 29 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns record{| int id; string body;|} { 30 | return {id:1, body: "ooo"}; 31 | } 32 | } 33 | 34 | public type Subscribe record { 35 | int id; 36 | string event; 37 | }; 38 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/alias/websocket.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /ping: 17 | subscribe: 18 | message: 19 | payload: 20 | type: integer 21 | format: int64 22 | publish: 23 | message: 24 | $ref: '#/components/messages/Subscribe' 25 | bindings: 26 | ws: 27 | bindingVersion: 0.1.0 28 | headers: 29 | type: object 30 | properties: 31 | headerValue: 32 | type: string 33 | components: 34 | schemas: 35 | Subscribe: 36 | type: object 37 | required: 38 | - id 39 | - event 40 | properties: 41 | id: 42 | type: integer 43 | format: int64 44 | event: 45 | type: string 46 | const: Subscribe 47 | messages: 48 | Subscribe: 49 | payload: 50 | $ref: '#/components/schemas/Subscribe' 51 | x-response: 52 | payload: 53 | type: integer 54 | format: int64 55 | x-response-type: simple-rpc 56 | x-dispatcherKey: event 57 | -------------------------------------------------------------------------------- /native.handler/java-wrapper/src/main/java/io/ballerinax/event/ModuleUtils.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | package io.ballerinax.event; 18 | 19 | import io.ballerina.runtime.api.Environment; 20 | import io.ballerina.runtime.api.Module; 21 | 22 | /** 23 | * {@code ModuleUtils} contains the utility methods for the module. 24 | * 25 | * @since 2.0.0 26 | */ 27 | public class ModuleUtils { 28 | private static Module httpListenerModule; 29 | 30 | private ModuleUtils() {} 31 | 32 | public static void setModule(Environment environment) { 33 | httpListenerModule = environment.getCurrentModule(); 34 | } 35 | 36 | public static Module getModule() { 37 | return httpListenerModule; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/optional/optional_int_return.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /: 17 | subscribe: 18 | message: 19 | payload: 20 | type: integer 21 | format: int64 22 | publish: 23 | message: 24 | $ref: '#/components/messages/Location' 25 | components: 26 | schemas: 27 | Location: 28 | type: object 29 | required: 30 | - id 31 | - event 32 | properties: 33 | id: 34 | type: string 35 | description: Unique identification 36 | event: 37 | type: string 38 | const: Location 39 | description: Represents location 40 | messages: 41 | Location: 42 | payload: 43 | $ref: '#/components/schemas/Location' 44 | description: Represents Snowpeak location resource 45 | x-response: 46 | payload: 47 | type: integer 48 | format: int64 49 | description: '`Location` representation' 50 | x-required: false 51 | x-response-type: simple-rpc 52 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/cmd/ballerina-to-asyncapi/exceptions/no_service_class_present.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | listener websocket:Listener helloEp = new (80); 20 | 21 | public type Subscribe record{ 22 | int id; 23 | string event; 24 | }; 25 | 26 | public type Ticker record{ 27 | int id; 28 | }; 29 | 30 | @websocket:ServiceConfig{dispatcherKey: "event"} 31 | service / on helloEp { 32 | resource function get .() returns int { 33 | return 1; 34 | } 35 | } 36 | 37 | service class ChatServer { 38 | *websocket:Service; 39 | 40 | remote function onSubscribe(websocket:Caller caller,Subscribe message) returns Ticker { 41 | return {id:1}; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/InvalidResponse/boolean_type_response.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /locations: 17 | description: Reperesents Snowpeak room collection resource 18 | subscribe: 19 | message: 20 | $ref: '#/components/messages/UnSubscribe' 21 | publish: 22 | message: 23 | $ref: '#/components/messages/Subscribe' 24 | components: 25 | schemas: 26 | Subscribe: 27 | type: object 28 | required: 29 | - id 30 | - event 31 | properties: 32 | id: 33 | type: string 34 | format: int64 35 | event: 36 | type: string 37 | const: Subscribe 38 | UnSubscribe: 39 | type: boolean 40 | messages: 41 | UnSubscribe: 42 | payload: 43 | $ref: '#/components/schemas/UnSubscribe' 44 | Subscribe: 45 | payload: 46 | $ref: '#/components/schemas/Subscribe' 47 | x-response: 48 | $ref: '#/components/messages/UnSubscribe' 49 | x-response-type: simple-rpc 50 | x-dispatcherKey: event 51 | x-dispatcherStreamId: id 52 | 53 | 54 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/InvalidResponse/float_type_response.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /locations: 17 | description: Reperesents Snowpeak room collection resource 18 | subscribe: 19 | message: 20 | $ref: '#/components/messages/UnSubscribe' 21 | publish: 22 | message: 23 | $ref: '#/components/messages/Subscribe' 24 | components: 25 | schemas: 26 | Subscribe: 27 | type: object 28 | required: 29 | - id 30 | - event 31 | properties: 32 | id: 33 | type: string 34 | format: int64 35 | event: 36 | type: string 37 | const: Subscribe 38 | UnSubscribe: 39 | type: number 40 | messages: 41 | UnSubscribe: 42 | payload: 43 | $ref: '#/components/schemas/UnSubscribe' 44 | Subscribe: 45 | payload: 46 | $ref: '#/components/schemas/Subscribe' 47 | x-response: 48 | $ref: '#/components/messages/UnSubscribe' 49 | x-response-type: simple-rpc 50 | x-dispatcherKey: event 51 | x-dispatcherStreamId: id 52 | 53 | 54 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/InvalidResponse/string_type_response.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /locations: 17 | description: Reperesents Snowpeak room collection resource 18 | subscribe: 19 | message: 20 | $ref: '#/components/messages/UnSubscribe' 21 | publish: 22 | message: 23 | $ref: '#/components/messages/Subscribe' 24 | components: 25 | schemas: 26 | Subscribe: 27 | type: object 28 | required: 29 | - id 30 | - event 31 | properties: 32 | id: 33 | type: string 34 | format: int64 35 | event: 36 | type: string 37 | const: Subscribe 38 | UnSubscribe: 39 | type: string 40 | messages: 41 | UnSubscribe: 42 | payload: 43 | $ref: '#/components/schemas/UnSubscribe' 44 | Subscribe: 45 | payload: 46 | $ref: '#/components/schemas/Subscribe' 47 | x-response: 48 | $ref: '#/components/messages/UnSubscribe' 49 | x-response-type: simple-rpc 50 | x-dispatcherKey: event 51 | x-dispatcherStreamId: id 52 | 53 | 54 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/cmd/ballerina-to-asyncapi/exceptions/check_websocket_serviceConfig_annotation.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | listener websocket:Listener helloEp = new (80); 20 | 21 | public type Subscribe record { 22 | int id; 23 | int event; 24 | }; 25 | 26 | public type Ticker record { 27 | int id; 28 | }; 29 | 30 | service / on helloEp { 31 | resource function get .() returns websocket:Service|websocket:UpgradeError { 32 | return new ChatServer(); 33 | } 34 | } 35 | 36 | service class ChatServer{ 37 | *websocket:Service; 38 | 39 | remote function onSubscribe(websocket:Caller caller,Subscribe message) returns Ticker { 40 | return {id:1}; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/schema/baloutputs/Record/nested_schema_refs.bal: -------------------------------------------------------------------------------- 1 | public type Subscribe record { 2 | anydata pet_type; 3 | string event; 4 | }; 5 | 6 | public type UnSubscribe record { 7 | int zipCode?; 8 | string event; 9 | # A generic Asana Resource, containing a globally unique identifier. 10 | AsanaResource request?; 11 | }; 12 | 13 | # A generic Asana Resource, containing a globally unique identifier. 14 | public type AsanaResource record { 15 | # Globally unique identifier of the resource, as a string. 16 | string gid?; 17 | # The base type of this resource. 18 | string resource_type?; 19 | }; 20 | 21 | public type UserCompact record { 22 | *AsanaResource; 23 | # Read-only except when same user as requester. 24 | string name?; 25 | }; 26 | 27 | public type ProjectStatusCompact record { 28 | *AsanaResource; 29 | # The title of the project status update. 30 | string title?; 31 | }; 32 | 33 | public type ProjectStatusRequest ProjectStatusBase; 34 | 35 | public type ProjectStatusBase record { 36 | *ProjectStatusCompact; 37 | UserCompact author?; 38 | # The time at which this project status was last modified. 39 | anydata modified_at?; 40 | # The text content of the status update. 41 | string text; 42 | string html_text?; 43 | # The color associated with the status update. 44 | string color; 45 | }; 46 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/listeners/listener_scenario01.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | listener websocket:Listener ep0 = new (80, config = {host: "www.asyncapi.com"}); 20 | 21 | public type Subscribe record{ 22 | int id; 23 | string event; 24 | }; 25 | 26 | @websocket:ServiceConfig{dispatcherKey: "event"} 27 | service /payloadV on ep0 { 28 | resource function get pathParam() returns websocket:Service|websocket:UpgradeError { 29 | return new ChatServer(); 30 | } 31 | } 32 | 33 | service class ChatServer{ 34 | *websocket:Service; 35 | 36 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns int { 37 | return 5; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/listeners/listener_scenario06.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | listener websocket:Listener ep1 = new (443, config = {host: "www.asyncapi.com"}); 20 | 21 | public type Subscribe record{ 22 | int id; 23 | string event; 24 | }; 25 | 26 | @websocket:ServiceConfig{dispatcherKey: "event"} 27 | service /payloadV on { 28 | resource function get pathParam() returns websocket:Service|websocket:UpgradeError { 29 | return new ChatServer(); 30 | } 31 | } 32 | 33 | service class ChatServer{ 34 | *websocket:Service; 35 | 36 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns int { 37 | return 5; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/apidoc/path_param.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /locations/{id}/rooms: 17 | description: Reperesents Snowpeak room collection resource 18 | subscribe: 19 | message: 20 | payload: 21 | type: integer 22 | format: int64 23 | publish: 24 | message: 25 | $ref: '#/components/messages/Subscribe' 26 | parameters: 27 | id: 28 | description: Unique identification of location 29 | schema: 30 | type: string 31 | components: 32 | schemas: 33 | Subscribe: 34 | type: object 35 | required: 36 | - id 37 | - event 38 | properties: 39 | id: 40 | type: integer 41 | format: int64 42 | event: 43 | type: string 44 | const: Subscribe 45 | messages: 46 | Subscribe: 47 | payload: 48 | $ref: '#/components/schemas/Subscribe' 49 | x-response: 50 | payload: 51 | type: integer 52 | format: int64 53 | x-response-type: simple-rpc 54 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/additional/dispatcherStreamId_present.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | @websocket:ServiceConfig {dispatcherKey: "event",dispatcherStreamId: "id"} 20 | service /chat on new websocket:Listener(9090) { 21 | resource function get .() returns websocket:Service { 22 | return new ChatService(); 23 | } 24 | } 25 | 26 | service class ChatService { 27 | *websocket:Service; 28 | remote function onPing(Ping message) returns Pong { 29 | return {"event":"pong","id":"5"}; 30 | } 31 | } 32 | 33 | public type Ping record{ 34 | string event; 35 | string id; 36 | }; 37 | 38 | public type Pong record { 39 | string event; 40 | string id; 41 | }; 42 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/dispatcher-mapping-annotation/expected_gen/listener.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: / 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /: 17 | subscribe: 18 | message: 19 | $ref: '#/components/messages/SubscribeResponse' 20 | publish: 21 | message: 22 | $ref: '#/components/messages/Subscribe' 23 | components: 24 | schemas: 25 | Subscribe: 26 | type: object 27 | required: 28 | - type 29 | properties: 30 | type: 31 | type: string 32 | const: Subscribe 33 | SubscribeResponse: 34 | type: object 35 | required: 36 | - type 37 | properties: 38 | type: 39 | type: string 40 | payload: 41 | type: object 42 | additionalProperties: true 43 | messages: 44 | SubscribeResponse: 45 | payload: 46 | $ref: '#/components/schemas/SubscribeResponse' 47 | Subscribe: 48 | payload: 49 | $ref: '#/components/schemas/Subscribe' 50 | x-response: 51 | $ref: '#/components/messages/SubscribeResponse' 52 | x-response-type: simple-rpc 53 | x-dispatcherKey: type 54 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/java/io/ballerina/asyncapi/codegenerator/controller/SpecController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package io.ballerina.asyncapi.codegenerator.controller; 20 | 21 | import io.apicurio.datamodels.models.asyncapi.AsyncApiSchema; 22 | import io.ballerina.asyncapi.codegenerator.entity.ServiceType; 23 | 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | /** 28 | * This is the Interface used for entity extraction from the AsyncAPI specification related Controllers. 29 | */ 30 | public interface SpecController { 31 | List getServiceTypes(); 32 | Map getSchemas(); 33 | String getEventIdentifierType(); 34 | String getEventIdentifierPath(); 35 | } 36 | -------------------------------------------------------------------------------- /asyncapi-cli/src/main/java/io/ballerina/asyncapi/websocketscore/generators/asyncspec/diagnostic/AsyncApiConverterDiagnostic.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). 3 | * 4 | * WSO2 LLC. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | package io.ballerina.asyncapi.websocketscore.generators.asyncspec.diagnostic; 19 | 20 | import io.ballerina.tools.diagnostics.DiagnosticSeverity; 21 | import io.ballerina.tools.diagnostics.Location; 22 | 23 | import java.util.Optional; 24 | /** 25 | * This {@code AsyncAPIConverterDiagnostic} represents diagnostic type in the ballerina to AsyncApi command. 26 | * 27 | */ 28 | public interface AsyncApiConverterDiagnostic { 29 | 30 | DiagnosticSeverity getDiagnosticSeverity(); 31 | 32 | String getMessage(); 33 | 34 | Optional getLocation(); 35 | 36 | String getCode(); 37 | } 38 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/record/nullable01.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | type Link record {| 20 | string? rel?; 21 | string href; 22 | string event; 23 | |}; 24 | 25 | listener websocket:Listener ep0 = new(443, config = {host: "petstore.swagger.io"}); 26 | 27 | @websocket:ServiceConfig{dispatcherKey: "event"} 28 | service /payloadV on ep0 { 29 | resource function get pet(Link payload) returns websocket:Service|websocket:UpgradeError{ 30 | return new ChatServer(); 31 | } 32 | } 33 | 34 | service class ChatServer{ 35 | *websocket:Service; 36 | 37 | remote function onLink(websocket:Caller caller, Link message) returns int { 38 | return 5; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/cmd/ballerina-to-asyncapi/exceptions/request_type_record_check.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | listener websocket:Listener helloEp = new (80); 20 | 21 | public type Subscribe int; 22 | public type Ticker record { 23 | int id; 24 | }; 25 | 26 | public type Reqid int?; 27 | @websocket:ServiceConfig{dispatcherKey: "event"} 28 | service / on helloEp { 29 | resource function get .() returns websocket:Service| websocket:UpgradeError { 30 | return new ChatServer(); 31 | } 32 | } 33 | 34 | service class ChatServer{ 35 | *websocket:Service; 36 | 37 | remote function onSubscribe(websocket:Caller caller,Subscribe message) returns Ticker { 38 | return {id:1}; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/apidoc/resource_function_scenario.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | public type Subscribe record{ 20 | int id; 21 | string event; 22 | }; 23 | 24 | @websocket:ServiceConfig{dispatcherKey: "event"} 25 | service /payloadV on new websocket:Listener(9090) { 26 | # Represents Snowpeak location resource 27 | resource function get locations() returns websocket:Service|websocket:UpgradeError { 28 | return new ChatServer(); 29 | } 30 | } 31 | 32 | service class ChatServer{ 33 | *websocket:Service; 34 | 35 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns int { 36 | // io:println(data); 37 | return 5; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/headers/header_scenario01.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | import ballerina/http; 19 | 20 | listener websocket:Listener helloEp = new (9090); 21 | 22 | public type Subscribe record{ 23 | int id; 24 | string event; 25 | }; 26 | 27 | @websocket:ServiceConfig{dispatcherKey: "event"} 28 | service /payloadV on helloEp { 29 | resource function get ping(@http:Header {} string X\-Client) returns websocket:Service|websocket:UpgradeError { 30 | return new ChatServer(); 31 | } 32 | } 33 | 34 | service class ChatServer{ 35 | *websocket:Service; 36 | 37 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns int { 38 | return 5; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/headers/header_scenario03.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | import ballerina/http; 19 | 20 | listener websocket:Listener helloEp = new (9090); 21 | 22 | public type Subscribe record{ 23 | int id; 24 | string event; 25 | }; 26 | 27 | @websocket:ServiceConfig{dispatcherKey: "event"} 28 | service /payloadV on helloEp { 29 | resource function get ping(@http:Header string headerValue) returns websocket:Service|websocket:UpgradeError { 30 | return new ChatServer(); 31 | } 32 | } 33 | 34 | service class ChatServer{ 35 | *websocket:Service; 36 | 37 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns int { 38 | return 5; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/headers/header_scenario05.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | import ballerina/http; 19 | 20 | listener websocket:Listener helloEp = new (9090); 21 | 22 | public type Subscribe record{ 23 | int id; 24 | string event; 25 | }; 26 | 27 | @websocket:ServiceConfig{dispatcherKey: "event"} 28 | service /payloadV on helloEp { 29 | resource function get ping(@http:Header string? headerValue) returns websocket:Service|websocket:UpgradeError { 30 | return new ChatServer(); 31 | } 32 | } 33 | 34 | service class ChatServer{ 35 | *websocket:Service; 36 | 37 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns int { 38 | return 5; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/headers/header_scenario11.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | import ballerina/http; 19 | 20 | listener websocket:Listener helloEp = new (9090); 21 | 22 | public type Subscribe record{ 23 | int id; 24 | string event; 25 | }; 26 | 27 | @websocket:ServiceConfig{dispatcherKey: "event"} 28 | service /payloadV on helloEp { 29 | resource function get ping(@http:Header boolean[] headerValue) returns websocket:Service|websocket:UpgradeError { 30 | return new ChatServer(); 31 | } 32 | } 33 | 34 | service class ChatServer{ 35 | *websocket:Service; 36 | 37 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns int { 38 | return 5; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/headers/header_scenario13.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | import ballerina/http; 19 | 20 | listener websocket:Listener helloEp = new (9090); 21 | 22 | public type Subscribe record{ 23 | int id; 24 | string event; 25 | }; 26 | 27 | @websocket:ServiceConfig{dispatcherKey: "event"} 28 | service /payloadV on helloEp { 29 | resource function get v1(@http:Header {} string[] XClient) returns websocket:Service|websocket:UpgradeError { 30 | return new ChatServer(); 31 | } 32 | } 33 | 34 | service class ChatServer{ 35 | *websocket:Service; 36 | 37 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns int { 38 | return 5; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/asyncapi-to-ballerina/client/InvalidResponse/map_type_response.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://localhost 13 | port: 14 | default: "9090" 15 | channels: 16 | /locations: 17 | description: Reperesents Snowpeak room collection resource 18 | subscribe: 19 | message: 20 | $ref: '#/components/messages/UnSubscribe' 21 | publish: 22 | message: 23 | $ref: '#/components/messages/Subscribe' 24 | components: 25 | schemas: 26 | Subscribe: 27 | type: object 28 | required: 29 | - id 30 | - event 31 | properties: 32 | id: 33 | type: string 34 | format: int64 35 | event: 36 | type: string 37 | const: Subscribe 38 | UnSubscribe: 39 | type: object 40 | additionalProperties: true 41 | messages: 42 | UnSubscribe: 43 | payload: 44 | $ref: '#/components/schemas/UnSubscribe' 45 | Subscribe: 46 | payload: 47 | $ref: '#/components/schemas/Subscribe' 48 | x-response: 49 | $ref: '#/components/messages/UnSubscribe' 50 | x-response-type: simple-rpc 51 | x-dispatcherKey: event 52 | x-dispatcherStreamId: id 53 | 54 | 55 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/ballerina-project/service/arrayTypeResponse.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | import 'service.types; 19 | 20 | @websocket:ServiceConfig{dispatcherKey: "event"} 21 | service /payloadV on new websocket:Listener(8080) { 22 | # List all products 23 | # + return - List of products 24 | resource function get .() returns websocket:Service|websocket:UpgradeError { 25 | return new ArrayChatServer(); 26 | } 27 | } 28 | 29 | service class ArrayChatServer{ 30 | 31 | *websocket:Service; 32 | private map products = {}; 33 | 34 | remote function onPrice(types:Price price) returns types:Product[]{ 35 | 36 | return self.products.toArray(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/listeners/listener_scenario05.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | listener websocket:Listener ep1 = new (443, config = {host: "www.asyncapi.com"}); 20 | 21 | public type Subscribe record{ 22 | int id; 23 | string event; 24 | }; 25 | 26 | @websocket:ServiceConfig{dispatcherKey: "event"} 27 | service /payloadV on new websocket:Listener(8080), ep1 { 28 | resource function get pathParam() returns websocket:Service|websocket:UpgradeError { 29 | return new ChatServer(); 30 | } 31 | } 32 | 33 | service class ChatServer{ 34 | *websocket:Service; 35 | 36 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns int { 37 | return 5; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/yaml_outputs/record/nullable01.yaml: -------------------------------------------------------------------------------- 1 | asyncapi: 2.5.0 2 | info: 3 | title: PayloadV 4 | version: 0.0.0 5 | servers: 6 | development: 7 | url: "{server}:{port}/payloadV" 8 | protocol: ws 9 | protocolVersion: "13" 10 | variables: 11 | server: 12 | default: ws://petstore.swagger.io 13 | port: 14 | default: "443" 15 | channels: 16 | /pet: 17 | subscribe: 18 | message: 19 | payload: 20 | type: integer 21 | format: int64 22 | publish: 23 | message: 24 | $ref: '#/components/messages/Link' 25 | bindings: 26 | ws: 27 | bindingVersion: 0.1.0 28 | query: 29 | type: object 30 | properties: 31 | payload: 32 | $ref: '#/components/schemas/Link' 33 | components: 34 | schemas: 35 | Link: 36 | type: object 37 | required: 38 | - href 39 | - event 40 | properties: 41 | rel: 42 | type: string 43 | x-nullable: true 44 | href: 45 | type: string 46 | event: 47 | type: string 48 | const: Link 49 | messages: 50 | Link: 51 | payload: 52 | $ref: '#/components/schemas/Link' 53 | x-response: 54 | payload: 55 | type: integer 56 | format: int64 57 | x-response-type: simple-rpc 58 | x-dispatcherKey: event -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/cmd/ballerina-to-asyncapi/exceptions/dispatcherKey_field_not_present_in_record.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | listener websocket:Listener helloEp = new (80); 20 | 21 | public type Subscribe record { 22 | int id; 23 | }; 24 | 25 | public type Ticker record { 26 | int id; 27 | }; 28 | 29 | @websocket:ServiceConfig{dispatcherKey: "event"} 30 | service / on helloEp { 31 | resource function get .() returns websocket:Service|websocket:UpgradeError { 32 | return new ChatServer(); 33 | } 34 | } 35 | 36 | service class ChatServer{ 37 | *websocket:Service; 38 | 39 | remote function onSubscribe(websocket:Caller caller,Subscribe message) returns Ticker { 40 | return {id:1}; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/cmd/ballerina-to-asyncapi/exceptions/empty_dispatcherKey_check.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | 19 | listener websocket:Listener helloEp = new (80); 20 | 21 | public type Subscribe record { 22 | int id; 23 | string event; 24 | }; 25 | 26 | public type Ticker record { 27 | int id; 28 | }; 29 | 30 | @websocket:ServiceConfig{dispatcherKey: ""} 31 | service / on helloEp { 32 | resource function get .() returns websocket:Service|websocket:UpgradeError { 33 | return new ChatServer(); 34 | } 35 | } 36 | 37 | service class ChatServer { 38 | *websocket:Service; 39 | 40 | remote function onSubscribe(websocket:Caller caller,Subscribe message) returns Ticker { 41 | return {id:1}; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /asyncapi-cli/src/test/resources/websockets/ballerina-to-asyncapi/headers/header_scenario02.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). 2 | // 3 | // WSO2 LLC. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/websocket; 18 | import ballerina/http; 19 | 20 | listener websocket:Listener helloEp = new (9090); 21 | 22 | public type Subscribe record{ 23 | int id; 24 | string event; 25 | }; 26 | 27 | @websocket:ServiceConfig{dispatcherKey: "event"} 28 | service /payloadV on helloEp { 29 | resource function get ping(@http:Header {name: "x-item"} string headerValue) returns websocket:Service|websocket:UpgradeError { 30 | return new ChatServer(); 31 | } 32 | } 33 | 34 | service class ChatServer{ 35 | *websocket:Service; 36 | 37 | remote function onSubscribe(websocket:Caller caller, Subscribe message) returns int { 38 | return 5; 39 | } 40 | } 41 | --------------------------------------------------------------------------------