Skip to content

Instantly share code, notes, and snippets.

@lmazuel
Last active December 14, 2022 03:12
Show Gist options
  • Save lmazuel/debbe1a78c4f73ff041f7937eacf6b2a to your computer and use it in GitHub Desktop.
Save lmazuel/debbe1a78c4f73ff041f7937eacf6b2a to your computer and use it in GitHub Desktop.
CADL Model fun

Syntax 1

op (one: int32, two: int32): void;

Send JSON:

{"one": 12, "two": 47}

Python:

@overload
def sum(self, body: JSON) # make this programatically positional only

@overload
def sum(self, *, one: int, two: int)

def sum(self, *args, **kwargs)

Syntax 2

alias MyModel = {
   one: int32;
   two: int32;
}

op (...MyModel): void;

Send JSON:

{"one": 12, "two": 47}

Python:

@overload
def sum(self, body: JSON) # make this programatically positional only

@overload
def sum(self, *, one: int, two: int)

def sum(self, *args, **kwargs)

Syntax 2 is the same compiled CADL than Syntax 1

Syntax 3

model MyModel {
   one: int32;
   two: int32;
}

op (...MyModel): void;

Send JSON:

{"one": 12, "two": 47}

Python:

def sum(self, body: Union[JSON, MyModel])

Syntax 4

model MyModel {
   one: int32;
   two: int32;
}

op (my_model: MyModel): void;

Send JSON:

{"my_model": {"one": 12, "two": 47}}

Python:

# Don't need to solve this for now
# This is bad practice (anonymous class as input) and will be flagged in review

Syntax 5

model MyModel {
   one: int32;
   two: int32;
}

op (@body my_model: MyModel): void;

Send JSON:

{"one": 12, "two": 47}

Python:

def sum(self, body: Union[JSON, MyModel])
@msyyc
Copy link

msyyc commented Dec 14, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment