Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Convert Cxml application to TypeSpec #10

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,137 changes: 535 additions & 602 deletions api/signalwire-rest/fabric-api/_spec_.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import "@typespec/http";
import "@typespec/openapi";
import "./models/core.tsp";
import "./models/responses.tsp";
import "../../types";

using TypeSpec.Http;
using Types.StatusCodes;

@route("/resources/cxml_applications/{cxml_application_id}/addresses")
namespace FabricAPI.CxmlApplicationAddresses {
@tag("cXML Application")
@friendlyName("cXML Applications")
interface CxmlApplicationAddresses {
@summary("List cXML Application Addresses")
@doc("A list of cXML Application Addresses")
list(...CxmlApplicationIDPath):
CxmlApplicationAddressListResponse |
StatusCode401 |
StatusCode404;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import "@typespec/openapi3";
import "./enums.tsp";
import "../../../types";

using TypeSpec.Http;
using TypeSpec.OpenAPI;

model CxmlApplicationIDPath {
@doc("Unique ID of a cXML Application.")
@path
cxml_application_id: uuid
}

model CxmlApplicationAddress {
@doc("Unique ID of the Fabric Address.")
@example("691af061-cd86-4893-a605-173f47afc4c2")
id: uuid;

@doc("Fabric resource ID that the Fabric Address belongs to.")
@example("691af061-cd86-4893-a605-173f47afc4c2")
resource_id: uuid;

@doc("Name of the Fabric Address.")
@example("justice-league")
name: string;

@doc("Display name of the Fabric Address.")
@example("Justice League")
display_name: string;

@doc("Type of the Fabric Address.")
@example(DisplayTypes.App)
type: DisplayTypes;

@doc("Cover url of the Fabric Address.")
@example("https://coverurl.com")
cover_url: string;

@doc("Preview url of the Fabric Address.")
@example("https://previewurl.com")
preview_url: string;

@doc("Channels of the Fabric Address.")
channel: AddressChannel;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./../../enums.tsp";
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
model CxmlApplicationAddressListResponse {
data: CxmlApplicationAddress[];
links: CxmlApplicationAddressPaginationResponse;
}

model CxmlApplicationAddressPaginationResponse {
@doc("Link of the current page")
@example("https://{space_name}.signalwire.com/api/fabric/resources/cxml_applications/a87db7ed-8ebe-42e4-829f-8ba5a4152f54/addresses?page_number=0&page_size=50")
self: url;

@doc("Link to the first page")
@example("https://{space_name}.signalwire.com/api/fabric/resources/cxml_applications/a87db7ed-8ebe-42e4-829f-8ba5a4152f54/addresses?page_number=0&page_size=50")
first: url;

@doc("Link to the next page")
@example("https://{space_name}.signalwire.com/api/fabric/resources/cxml_applications/a87db7ed-8ebe-42e4-829f-8ba5a4152f54/addresses?page_number=1&page_size=50&page_token=PAbff61159-faab-48b3-959a-3021a8f5beca")
next: url;
}
58 changes: 58 additions & 0 deletions api/signalwire-rest/fabric-api/cxml-application/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import "@typespec/http";
import "@typespec/openapi";
import "./models/core.tsp";
import "./models/requests.tsp";
import "./models/responses.tsp";
import "./models/errors.tsp";
import "../../types";

using TypeSpec.Http;
using Types.StatusCodes;

@route("/resources/cxml_applications")
namespace FabricAPI.CxmlApplications {
@tag("cXML Application")
@friendlyName("cXML Applications")
interface CxmlApplications {
@summary("List cXML Applications")
@doc("A list of cXML Applications")
list():
CxmlApplicationListResponse |
StatusCode401 |
StatusCode404;

@summary("Get cXML Application")
@doc("Returns an cXML Application by ID")
read(...CxmlApplicationID): {
@statusCode statusCode: 200;
@body cxml_application: CxmlApplicationResponse;
} |
StatusCode401 |
StatusCode404;

@summary("Create cXML Application")
@doc("Creates acXML Application")
@post create(...CxmlApplicationCreateRequest):
{ @statusCode statusCode: 201; @body cxml_application: CxmlApplicationResponse; } |
StatusCode401 |
StatusCode404 |
CxmlApplicationCreateStatusCode422;

@summary("Update cXML Application")
@doc("Updates a cXML Application by ID")
@patch update(...CxmlApplicationID, ...CxmlApplicationUpdateRequest): {
@statusCode statusCode: 200; @body cxml_application: CxmlApplicationResponse;
} |
StatusCode401 |
StatusCode404 |
CxmlApplicationUpdateStatusCode422;

@summary("Delete cXML Application")
@doc("Deletes a cXML Application by ID")
@delete delete(...CxmlApplicationID):
{ @statusCode statusCode: 204; } |
StatusCode401 |
StatusCode404;
}
}

48 changes: 48 additions & 0 deletions api/signalwire-rest/fabric-api/cxml-application/models/core.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import "./enums.tsp";
import "../../../types";

using TypeSpec.Http;

model CxmlApplicationID {
@doc("Unique ID of a cXML Application.")
@path
id: uuid
}

model CxmlApplication {
@doc("Unique ID of the cXML Application.")
@example("a87db7ed-8ebe-42e4-829f-8ba5a4152f54")
id: uuid;

@doc("Name of the cXML Application.")
@example("My cXML Application")
name: string;

@doc("Indicates whether the call will be handled by a script or an external URL.")
@example(HandleCallsUsing.Script)
handle_calls_using: HandleCallsUsing;

@doc("Call handler URL")
@example("https://example.com/cxml")
call_handler_url: string;

@doc("Call handler URL method")
@example(UrlMethodType.Get)
call_handler_method: UrlMethodType;

@doc("Call handler callback URL.")
@example("https://example.com/cxml")
call_handler_fallback_url: string;

@doc("Call handler fallback method.")
@example(UrlMethodType.Get)
call_handler_fallback_method: UrlMethodType;

@doc("Call status callback URL")
@example("https://callback.com")
call_status_callback_url: string;

@doc("Call status callback method.")
@example(UrlMethodType.Post)
call_status_callback_method: UrlMethodType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./../../enums.tsp";
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import "../../../types/status-codes";

using Types.StatusCodes;

@example(#{
errors: #[#{
type: "validation_error",
code: "missing_required_parameter",
message: "Name is required",
attribute: "name",
url: "https://developer.signalwire.com/rest/signalwire-rest/overview/error-codes/#missing_required_parameter"
}],
})
model CxmlApplicationCreateStatusCode422 is StatusCode422;

model CxmlApplicationUpdateStatusCode422 is CxmlApplicationCreateStatusCode422;
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
model CxmlApplicationCreateRequest {
@doc("Name of the cXML Application.")
@example("My cXML Application")
name: string;

@doc("Indicates whether the call will be handled by a script or an external URL.")
@example(HandleCallsUsing.Script)
handle_calls_using?: HandleCallsUsing;

@doc("Call handler URL")
@example("https://example.com/cxml")
call_handler_url?: string;

@doc("Call handler URL method")
@example(UrlMethodType.Get)
call_handler_method?: UrlMethodType = UrlMethodType.Post;

@doc("Call handler callback URL.")
@example("https://example.com/cxml")
call_handler_fallback_url?: string;

@doc("Call handler fallback method.")
@example(UrlMethodType.Get)
call_handler_fallback_method?: UrlMethodType = UrlMethodType.Post;

@doc("Call status callback URL")
@example("https://callback.com")
call_status_callback_url?: string;

@doc("Call status callback method.")
@example(UrlMethodType.Get)
call_status_callback_method?: UrlMethodType = UrlMethodType.Post;

@doc("Script to handle to call.")
@example("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response>\n <Play loop=\"15\">https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3</Play>\n</Response>")
call_handler_script?: string;
}

model CxmlApplicationUpdateRequest {
@doc("Name of the cXML Application.")
@example("My cXML Application")
name?: string;

@doc("Indicates whether the call will be handled by a script or an external URL.")
@example(HandleCallsUsing.Script)
handle_calls_using?: HandleCallsUsing;

@doc("Call handler URL")
@example("https://example.com/cxml")
call_handler_url?: string;

@doc("Call handler URL method")
@example(UrlMethodType.Get)
call_handler_method?: UrlMethodType = UrlMethodType.Post;

@doc("Call handler callback URL.")
@example("https://example.com/cxml")
call_handler_fallback_url?: string;

@doc("Call handler fallback method.")
@example(UrlMethodType.Get)
call_handler_fallback_method?: UrlMethodType = UrlMethodType.Post;

@doc("Call status callback URL")
@example("https://callback.com")
call_status_callback_url?: string;

@doc("Call status callback method.")
@example(UrlMethodType.Get)
call_status_callback_method?: UrlMethodType = UrlMethodType.Post;

@doc("Script to handle to call.")
@example("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response>\n <Play loop=\"15\">https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3</Play>\n</Response>")
call_handler_script?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

model CxmlApplicationResponse {
@doc("Unique ID of the cXML Application.")
@example("a87db7ed-8ebe-42e4-829f-8ba5a4152f54")
id: uuid;

@doc("Unique ID of the Project.")
@example("99151cf8-9548-4860-ba70-a8de824f3312")
project_id: uuid;

@doc("Display name of the cXML Application Fabric Resource")
@example("Booking Assistant")
display_name: string;

@doc("Type of the Fabric Resource")
@example("cxml_application")
type: string;

@doc("Date and time when the resource was created.")
@example(utcDateTime.fromISO("2024-10-17T14:14:53Z"))
created_at: utcDateTime;

@doc("Date and time when the resource was updated.")
@example(utcDateTime.fromISO("2024-10-17T14:14:53Z"))
updated_at: utcDateTime;

@doc("cXML Application data.")
cxml_application: CxmlApplication;
}
model CxmlApplicationListResponse {
data: CxmlApplicationResponse[];
links: CxmlApplicationPaginationResponse;
}

model CxmlApplicationPaginationResponse {
@doc("Link of the current page")
@example("https://{space_name}.signalwire.com/api/fabric/resources/cxml_applicationis?page_number=0&page_size=50")
self: url;

@doc("Link to the first page")
@example("https://{space_name}.signalwire.com/api/fabric/resources/cxml_applicationis?page_number=0&page_size=50")
first: url;

@doc("Link to the next page")
@example("https://{space_name}.signalwire.com/api/fabric/resources/cxml_applicationis?page_number=1&page_size=50&page_token=PAbff61159-faab-48b3-959a-3021a8f5beca")
next: url;
}
6 changes: 6 additions & 0 deletions api/signalwire-rest/fabric-api/enums.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ enum UrlMethodType {
Post: "POST",
}

@doc("Indicates whether the call will be handled by a script or an external url.")
enum HandleCallsUsing {
Script: "script",
ExternalUrl: "external_url",
}

union AddressChannel {
AudioChannel,
MessagingChannel,
Expand Down
3 changes: 3 additions & 0 deletions api/signalwire-rest/fabric-api/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import "./external-swml-handler";
import "./external-swml-handler-addresses";
import "./ai-agent";
import "./ai-agent-addresses";
import "./cxml-application";
import "./cxml-application-addresses";


using TypeSpec.Http;
using Types.StatusCodes;
Expand Down
Loading