Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
2a40de4
[Do not Merge] Eventgrid to CADL (#19819)
rakshith91 Nov 3, 2022
3435017
Merge branch 'main' of https://github.com/Azure/azure-rest-api-specs …
l0lawrence Nov 4, 2022
143a6fb
updating healthcare api enum for cadl
l0lawrence Nov 7, 2022
36f00c8
change number in Maps.cadl to float64
l0lawrence Nov 7, 2022
393129b
changing Map<k,V> to Record<V>
l0lawrence Nov 7, 2022
16645b4
update service title and version for healthcareapi
l0lawrence Nov 15, 2022
34fc27f
fix containerregistry
l0lawrence Nov 17, 2022
b08393a
container registry updated
l0lawrence Nov 28, 2022
d4ec258
updating container service cadl
l0lawrence Nov 28, 2022
be2094b
eventgrid service version
l0lawrence Nov 28, 2022
cce4031
eventhub cadl service version
l0lawrence Nov 28, 2022
0225638
healthcare api cadl
l0lawrence Nov 28, 2022
0facb8c
iothub cadl
l0lawrence Nov 28, 2022
37c2c2e
keyvault cadl
l0lawrence Nov 28, 2022
2abebc9
machine learning cadl
l0lawrence Nov 29, 2022
dccbb91
maps cadl
l0lawrence Nov 29, 2022
c55f5ff
policyInsights cadl
l0lawrence Nov 29, 2022
71e2088
redis cache cadl
l0lawrence Nov 29, 2022
72d72ba
resources cadl
l0lawrence Nov 29, 2022
c82df6f
servicebus cadl
l0lawrence Nov 29, 2022
9956450
signalRservice cadl
l0lawrence Nov 29, 2022
c387788
web cadl -- may need improvements
l0lawrence Nov 29, 2022
76ffb83
updating cadl inheritance story
l0lawrence Dec 2, 2022
b378f78
made a remove an add on communication
l0lawrence Dec 2, 2022
47dfa7a
trying 2 namespaces
l0lawrence Dec 2, 2022
3877057
cleaning up container
l0lawrence Dec 2, 2022
07b7cd0
2nd anmespace for baseevent container
l0lawrence Dec 2, 2022
f10f20d
adding in docs to healthcare cadl
l0lawrence Dec 2, 2022
9212d9d
add doc for healthcareresourcetype enum
l0lawrence Dec 2, 2022
7d342c1
save recent
l0lawrence Dec 3, 2022
c3743ba
two namespaces mediaservices
l0lawrence Dec 3, 2022
94c0d05
policy insights 2 namespaces
l0lawrence Dec 3, 2022
00ffafa
two namespaces resources
l0lawrence Dec 3, 2022
ed0e063
two namespaces sb
l0lawrence Dec 3, 2022
a4df0ff
2 namespace signalr
l0lawrence Dec 3, 2022
00ed94a
storage 2 namespaces
l0lawrence Dec 4, 2022
99f6a7f
2 namespaces web cadl
l0lawrence Dec 4, 2022
09cc3c7
Merge branch 'main' of https://github.com/Azure/azure-rest-api-specs …
l0lawrence Dec 6, 2022
699a920
ran prettier on cadl
l0lawrence Dec 6, 2022
9e2c10e
working on adding publish to EG cadl
l0lawrence Dec 6, 2022
5846e93
updating EG cadl
l0lawrence Dec 6, 2022
730a4ee
updated cadl version
l0lawrence Dec 7, 2022
bbfce94
remove service
l0lawrence Dec 9, 2022
d2334bc
remove repo level files
l0lawrence Dec 9, 2022
5bed832
remove repo level
l0lawrence Dec 9, 2022
9753a3e
changing baseEvents to alias
l0lawrence Dec 12, 2022
a7bcbf5
adding evnetgrid subnamespace to all files
l0lawrence Dec 13, 2022
f5ea629
inital generated swagger files from cadl
l0lawrence Dec 19, 2022
38b3e01
generation step initial
l0lawrence Dec 19, 2022
ba33c51
generation step initial2
l0lawrence Dec 19, 2022
ef97644
changing gen steps
l0lawrence Dec 20, 2022
6dfca48
change extends to spread
l0lawrence Dec 21, 2022
8acfecf
Merge branch 'main' of https://github.com/Azure/azure-rest-api-specs …
l0lawrence Jan 18, 2023
fc199c9
Merge branch 'main' of https://github.com/Azure/azure-rest-api-specs …
l0lawrence Jan 21, 2023
c920463
added in apimanagementgateway to cadl
l0lawrence Jan 21, 2023
0734085
cadl databox
l0lawrence Jan 21, 2023
256a3e9
Merge branch 'main' of https://github.com/Azure/azure-rest-api-specs …
l0lawrence Feb 16, 2023
12d2536
updating cadl to align with public client
l0lawrence Feb 16, 2023
bc26bdc
adding auth and apiversion fix
l0lawrence Feb 16, 2023
3ed06db
adding cadl output and operations file to show overlaod
l0lawrence Feb 17, 2023
f363d2c
overload?
l0lawrence Feb 17, 2023
66a5a1a
eg
l0lawrence Feb 17, 2023
237ab19
try overlaod again
l0lawrence Feb 17, 2023
6c45a0e
save here try to see why models are not showing
l0lawrence Feb 17, 2023
2871f29
save
l0lawrence Feb 17, 2023
4693df6
generalevent publish function
l0lawrence Feb 17, 2023
7cc26c3
shared route
l0lawrence Mar 14, 2023
b6ff831
remove commented code
l0lawrence Mar 14, 2023
46fe6fd
rename to typespec
l0lawrence Mar 15, 2023
a19e059
eventgrid updates
l0lawrence Mar 15, 2023
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
163 changes: 163 additions & 0 deletions specification/eventgrid/data-plane/import_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import json
import sys

def _extract_description(data):
desc = data.get("description", None)
desc = desc.replace('"', '\\"') if desc else desc
return desc


class CadlEnum:
def __init__(self, ctx, data, name=None):
self._ctx = ctx
enum = data.get("enum", None)
enum_ext = data.get("x-ms-enum", None)
self.name = enum_ext["name"] if enum_ext else name
self.model_as_string = enum_ext.get("modelAsString", False) if enum_ext else False
self.values = enum

def to_cadl(self):
lines = []
if self.model_as_string:
lines.append(f"@knownValues({self.name}KV)")
lines.append(f"model {self.name} is string \x7b\x7d")
lines.append(f"enum {self.name}KV \x7b")
for val in self.values:
lines.append(f"\t{val},")
lines.append("}")
else:
lines.append(f"enum {self.name} \x7b")
for val in self.values:
lines.append(f"\t{val},")
lines.append("}")
return "\n".join(lines)


class CadlProperty:
def __init__(self, ctx, name, data, required):
self._ctx = ctx
self.name = name
self.required = required
self.description = _extract_description(data)
self.type = self._parse_type(data)

_STRING_MAP = {
"date-time": "zonedDateTime",
"date": "plainDate",
"time": "plainTime",
"uuid": "string", # No uuid type in CADL
}

_NUMBER_MAP = {
"float": "float64",
"double": "float64"
}

_INTEGER_MAP = {
"int16": "int16",
"int32": "int32",
"int64": "int64"
}

def _parse_type_format(self, data):
type = data["type"]
format = data.get("format", None)
if type == "string":
return CadlProperty._STRING_MAP[format] if format else type
elif type == "number":
return CadlProperty._NUMBER_MAP[format] if format else type
elif type == "integer":
return CadlProperty._INTEGER_MAP[format] if format else type
elif type == "boolean":
assert format == None
return type
elif type == "object":
return "Map<string, string>"
raise TypeError(f"Unexpected type: {type}")

def _parse_type(self, data):
ref = data.get("$ref", None)
enum = data.get("enum", None)
type = data.get("type", None)
if ref:
return ref.rsplit("/", 1)[-1]
elif enum:
enum_ext = data.get("x-ms-enum", None)
self._ctx._models.append(CadlEnum(self._ctx, data))
return enum_ext["name"]
elif type == "array":
item_data = data["items"]
item_type = self._parse_type(item_data)
return f"{item_type}[]"
else:
return self._parse_type_format(data)

def to_cadl(self):
lines = []
if self.description:
lines.append(f'\t@doc("{self.description}")')
lines.append(f"\t{self.name}{':' if self.required else '?:'} {self.type};")
return lines


class CadlModel:
def __init__(self, ctx, name, data):
self._ctx = ctx
self.name = name
self.description = _extract_description(data)
self.type = data.get("type", None)
self.properties = []
required = data.get("required", [])
properties = data.get("properties", [])
if properties:
for name, data in properties.items():
self.properties.append(CadlProperty(ctx, name, data, name in required))

def to_cadl(self):
lines = []
if self.description:
lines.append(f'@doc("{self.description}")')
lines.append(f"model {self.name} \x7b")
for property in self.properties:
lines += property.to_cadl()
lines.append("}")
return "\n".join(lines)

class SwaggerImport:

def __init__(self):
self._models = []

# args = sys.argv[1:]
# if len(args) != 2:
# print("usage: import_models.py SRC DST")
# sys.exit(1)

base_path = "C:/Users/Administrator/Documents/Workspace/azure-rest-api-specs/specification/eventgrid/data-plane/"
src = base_path + "Microsoft." + sys.argv[1] + "/stable/2018-01-01/" + sys.argv[-1] + ".json"
self._dest = base_path + "cadl/" + sys.argv[-1] + ".cadl"
with open(src, "r") as infile:
swagger = json.loads(infile.read())

models = swagger.get('parameters', {})
models.update(swagger["definitions"])
self._process_models(models)

def _process_models(self, data):
for key, value in data.items():
enum = value.get("enum", None)
if enum:
self._models.append(CadlEnum(self, value, key))
else:
self._models.append(CadlModel(self, key, value))

def save(self):
dest = self._dest
dest = f"{dest}.cadl" if not dest.endswith(".cadl") else dest
with open(self._dest, "w") as outfile:
for model in self._models:
outfile.write(model.to_cadl())
outfile.write("\n\n")

model = SwaggerImport()
model.save()
157 changes: 157 additions & 0 deletions specification/eventgrid/data-plane/typespec/ApiManagement.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
@doc("Describes the schema of the Azure API Management events published to Azure Event Grid. This corresponds to the Data property of an EventGridEvent.")
namespace EventGrid.ApiManagement {
@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.UserCreated event.")
model ApiManagementUserCreatedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.UserUpdated event.")
model ApiManagementUserUpdatedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.UserDeleted event.")
model ApiManagementUserDeletedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.SubscriptionCreated event.")
model ApiManagementSubscriptionCreatedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.SubscriptionUpdated event.")
model ApiManagementSubscriptionUpdatedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.SubscriptionDeleted event.")
model ApiManagementSubscriptionDeletedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.ProductCreated event.")
model ApiManagementProductCreatedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.ProductUpdated event.")
model ApiManagementProductUpdatedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.ProductDeleted event.")
model ApiManagementProductDeletedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.APICreated event.")
model ApiManagementApiCreatedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.APIUpdated event.")
model ApiManagementApiUpdatedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.APIDeleted event.")
model ApiManagementApiDeletedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.APIReleaseCreated event.")
model ApiManagementApiReleaseCreatedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.APIReleaseUpdated event.")
model ApiManagementApiReleaseUpdatedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.APIReleaseDeleted event.")
model ApiManagementApiReleaseDeletedEventData {
...ApiManagementBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.GatewayCreated event.")
model ApiManagementGatewayCreatedEventData {
...ApiGatewayBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.GatewayUpdated event.")
model ApiManagementGatewayUpdatedEventData {
...ApiGatewayBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.GatewayDeleted event.")
model ApiManagementGatewayDeletedEventData {
...ApiGatewayBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.GatewayHostnameConfigurationCreated event.")
model ApiManagementGatewayHostnameConfigurationCreatedEventData {
...ApiGatewayHostnameBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.GatewayHostnameConfigurationUpdated event.")
model ApiManagementGatewayHostnameConfigurationUpdatedEventData {
...ApiGatewayHostnameBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.GatewayHostnameConfigurationDeleted event.")
model ApiManagementGatewayHostnameConfigurationDeletedEventData {
...ApiGatewayHostnameBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.GatewayCertificateAuthorityCreated event.")
model ApiManagementGatewayCertificateAuthorityCreatedEventData {
...ApiGatewayCertificateBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.GatewayCertificateAuthorityUpdated event.")
model ApiManagementGatewayCertificateAuthorityUpdatedEventData {
...ApiGatewayCertificateBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.GatewayCertificateAuthorityDeleted event.")
model ApiManagementGatewayCertificateAuthorityDeletedEventData {
...ApiGatewayCertificateBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.GatewayAPIAdded event.")
model ApiManagementGatewayApiAddedEventData {
...ApiGatewayApiBase;
}

@doc("Schema of the Data property of an EventGridEvent for a Microsoft.ApiManagement.GatewayAPIRemoved event.")
model ApiManagementGatewayApiRemovedEventData {
...ApiGatewayApiBase;
}

alias ApiManagementBase = {
@doc("The fully qualified ID of the resource that the compliance state change is for, including the resource name and resource type. Uses the format, `/subscriptions/<SubscriptionID>/resourceGroups/<ResourceGroup>/Microsoft.ApiManagement/service/<ServiceName>/<ResourceType>/<ResourceName>`")
resourceUri?: string;
};

alias ApiGatewayBase = {
@doc("The fully qualified ID of the resource that the compliance state change is for, including the resource name and resource type. Uses the format, `/subscriptions/<SubscriptionID>/resourceGroups/<ResourceGroup>/Microsoft.ApiManagement/service/<ServiceName>/gateways/<ResourceName>`")
resourceUri?: string;
};

alias ApiGatewayHostnameBase = {
@doc("The fully qualified ID of the resource that the compliance state change is for, including the resource name and resource type. Uses the format, `/subscriptions/<SubscriptionID>/resourceGroups/<ResourceGroup>/Microsoft.ApiManagement/service/<ServiceName>/gateways/<GatewayName>/hostnameConfigurations/<ResourceName>`")
resourceUri?: string;
};

alias ApiGatewayCertificateBase = {
@doc("The fully qualified ID of the resource that the compliance state change is for, including the resource name and resource type. Uses the format, `/subscriptions/<SubscriptionID>/resourceGroups/<ResourceGroup>/Microsoft.ApiManagement/service/<ServiceName>/gateways/<GatewayName>/certificateAuthorities/<ResourceName>`")
resourceUri?: string;
};

alias ApiGatewayApiBase = {
@doc("The fully qualified ID of the resource that the compliance state change is for, including the resource name and resource type. Uses the format, `/subscriptions/<SubscriptionID>/resourceGroups/<ResourceGroup>/Microsoft.ApiManagement/service/<ServiceName>/gateways/<GatewayName>/apis/<ResourceName>`")
resourceUri?: string;
};
}
Loading