Skip to content

Commit 4f4f698

Browse files
authored
update to use OpenAPI.jl instead of Swagger.jl (#29)
* update to use OpenAPI.jl instead of Swagger.jl * update lower bound of julia version for CI * regenerate with support for aliases, update readme
1 parent 0e2b55e commit 4f4f698

File tree

5,546 files changed

+153339
-82305
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

5,546 files changed

+153339
-82305
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
version:
15-
- '1.3'
15+
- '1.6'
1616
- '1' # automatically expands to the latest stable 1.x release of Julia
1717
- nightly
1818
os:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.jl.cov
22
*.jl.*.cov
33
*.jl.mem
4+
openapi-generator-cli.jar

Project.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "Azure"
22
uuid = "34b51195-c7f2-5807-8107-6ca017e2682c"
33
keywords = ["azure", "cloud", "api", "julia"]
44
desc = "Julia interface to Azure APIs"
5-
version = "0.4.1"
5+
version = "0.5.0"
66

77
[deps]
88
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
@@ -12,18 +12,20 @@ JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1212
MbedTLS = "739be429-bea8-5141-9913-cc70e7f3736d"
1313
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
1414
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
15-
Swagger = "2d69052b-6a58-5cd9-a030-a48559c324ac"
15+
OpenAPI = "d5e62ea6-ddf3-4d43-8e4c-ad5e6c8bfd7d"
16+
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
1617
XMLDict = "228000da-037f-5747-90a9-8195ccbf91a5"
1718
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
1819

1920
[compat]
2021
Downloads = "1"
21-
Swagger = "0.3"
22+
OpenAPI = "0.1"
2223
XMLDict = "0.3,0.4"
2324
JSON = "0.21"
2425
MbedTLS = "0.6.8, 0.7, 1"
25-
URIs = "1.3"
26-
julia = "1.3"
26+
TimeZones = "1"
27+
URIs = "1.3, 1.4"
28+
julia = "1.6"
2729

2830
[extras]
2931
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

README.md

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Azure.jl
22

3-
A Julia library to access Microsoft Azure REST APIs. Most code in this file is generated automatically using [Swagger.jl](https://github.com/JuliaComputing/Swagger.jl)
3+
A Julia library to access Microsoft Azure REST APIs. Most code in this file is generated automatically using [OpenAPI.jl](https://github.com/JuliaComputing/OpenAPI.jl)
44

55
[![Build Status](https://github.com/JuliaComputing/Azure.jl/workflows/CI/badge.svg)](https://github.com/JuliaComputing/Azure.jl/actions?query=workflow%3ACI+branch%3Amaster)
66

77
```
88
using Azure
9-
using Swagger
9+
using OpenAPI
1010
using Azure.StorageManagementClient
1111
using Azure.StorageServices
1212
using Azure.ComputeManagementClient
@@ -44,22 +44,48 @@ ctx = AzureContext(creds)
4444

4545
# Call APIs
4646

47-
## List operations
47+
Each API client module has corresponding API methods that can be invoked by providing an instance of the API and the API version.
48+
49+
The `api` method returns an instance of the API. E.g.: `api(ctx, StorageManagementClient.OperationsApi)`.
50+
51+
The `apiver` method returns the version of the API. E.g.: `apiver(StorageManagementClient.OperationsApi)`
4852

53+
The API methods return a tuple of the decoded response value and the associated HTTP response object.
54+
The `Azure.check_api_response` method can be used to examine the HTTP response and either throw an exception
55+
(`Azure.AzureException`) on error or return the response value on success. E.g.:
56+
57+
```julia
58+
list = Azure.check_api_response(StorageManagementClient.operations_list(
59+
api(ctx, StorageManagementClient.OperationsApi),
60+
apiver(StorageManagementClient.OperationsApi)
61+
))
4962
```
50-
StorageManagementClient.operationsList(api(ctx, OperationsApi), apiver(OperationsApi))
5163

52-
ComputeManagementClient.operationsList(api(ctx, ComputeOperationsApi), apiver(ComputeOperationsApi))
64+
## List operations
65+
66+
```julia
67+
Azure.check_api_response(StorageManagementClient.operations_list(
68+
api(ctx, StorageManagementClient.OperationsApi),
69+
apiver(StorageManagementClient.OperationsApi)
70+
))
71+
72+
Azure.check_api_response(ComputeManagementClient.operations_list(
73+
api(ctx, ComputeManagementClient.ComputeOperationsApi),
74+
apiver(ComputeManagementClient.ComputeOperationsApi)
75+
))
5376
```
5477

5578
## Get a VM and list out some of its attributes
5679

57-
```
80+
```julia
5881
const subscription_id = "subscrip-tion-idxx-xxxx-xxxxxxxxxxxx"
59-
vm = virtualMachinesGet(api(ctx, VirtualMachinesApi),
60-
"test-resource-grp", "my-vm-name",
61-
apiver(VirtualMachinesApi),
62-
subscription_id)
82+
vm = Azure.check_api_response(virtual_machines_get(
83+
api(ctx, ComputeManagementClient.VirtualMachinesApi),
84+
"test-resource-grp",
85+
"my-vm-name",
86+
apiver(ComputeManagementClient.VirtualMachinesApi),
87+
subscription_id
88+
))
6389

6490
vm_props = vm.properties
6591
vm_osdisk = vm_props.storageProfile.osDisk
@@ -73,7 +99,7 @@ nicids = [rsplit(nicid, '/'; limit=2)[2] for nicid in map(nicref->nicref.id, nic
7399

74100
## File share operations
75101

76-
```
102+
```julia
77103
const resource_group_name = "testresgroup"
78104
const fileshare = "https://mystorage.file.core.windows.net/myshare?restype=share"
79105
success = createShare(ctx, subscription_id, resource_group_name, fileshare, "100", Dict("taname"=>"taval"))
@@ -84,14 +110,14 @@ deleteShare(ctx, subscription_id, resource_group_name, fileshare)
84110

85111
## SAS operations
86112

87-
```
113+
```julia
88114
const blob = "https://mystorage.blob.core.windows.net/testblob/myblob.dat"
89115
appendSAS(ctx, subscription_id, resource_group_name, blob)
90116
```
91117

92118
## File blob operations
93119

94-
```
120+
```julia
95121
const storageaccount_url = "https://mystorage.blob.core.windows.net/"
96122
const testcontainer = storageaccount_url * "testcontainer1"
97123

@@ -121,11 +147,16 @@ More examples [test/test_blobs.jl](here).
121147

122148
## Rate card
123149

124-
```
150+
```julia
125151
ratefilter = join(["OfferDurableId eq 'MS-AZR-0003p'",
126152
"Currency eq 'USD'",
127153
"Locale eq 'en-US'",
128154
"RegionInfo eq 'US'"],
129155
" and ")
130-
rates = rateCardGet(api(ctx, RateCardApi), ratefilter, apiver(RateCardApi), subscription_id)
156+
rates = Azure.check_api_response(rate_card_get(
157+
api(ctx, UsageManagementClient.RateCardApi),
158+
ratefilter,
159+
apiver(UsageManagementClient.RateCardApi),
160+
subscription_id
161+
))
131162
```

gen/generate.jl

Lines changed: 37 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
using Logging
22

33
const DIR = dirname(@__FILE__)
4-
const GENDIR = joinpath(DIR, "..")
5-
const TEMPCFGFILE = joinpath(GENDIR, "config.json")
6-
const SRCDIR = joinpath(GENDIR, "src")
7-
const SWAGGERDIR=read(`$(joinpath(Sys.BINDIR, "julia")) -e 'import Swagger; print(normpath(joinpath(dirname(pathof(Swagger)), "..")))'`, String)
8-
const SWAGGERGEN = joinpath(SWAGGERDIR, "plugin", "generate.sh")
4+
const SRCDIR = abspath(joinpath(DIR, "..", "src"))
95

106
const SPECS = [
117
("DataLakeStoreAccountManagementClient", "DataLakeStore", "2016-11-01", "specification/datalake-store/resource-manager/Microsoft.DataLakeStore/stable/{VER}/account.json"),
@@ -36,25 +32,21 @@ const SPECS = [
3632
("PolicyAssignmentsClient", "Resource", "2019-09-01", "specification/resources/resource-manager/Microsoft.Authorization/stable/{VER}/policyAssignments.json"),
3733
("PolicyDefinitionsClient", "Resource", "2019-09-01", "specification/resources/resource-manager/Microsoft.Authorization/stable/{VER}/policyDefinitions.json"),
3834
("PolicySetDefinitionsClient", "Resource", "2019-09-01", "specification/resources/resource-manager/Microsoft.Authorization/stable/{VER}/policySetDefinitions.json"),
39-
("UsageManagementClient", "Commerce", "2015-06-01-preview", "specification/commerce/resource-manager/Microsoft.Commerce/preview/{VER}/commerce.json")
35+
("UsageManagementClient", "Commerce", "2015-06-01-preview", "specification/commerce/resource-manager/Microsoft.Commerce/preview/{VER}/commerce.json"),
4036
]
4137

42-
const PATCHES = Dict(
43-
("ComputeManagementClient", "Compute") => ["model" => ("Caching", "CreateOption", "StorageAccountType")],
44-
("ResourceManagementClient", "Resource") => ["model" => ("DeploymentPropertiesExtended",)]
45-
)
46-
4738
const MODULE_HEAD = """module Azure
4839
49-
using Swagger
40+
using OpenAPI
5041
using Downloads
5142
using JSON
43+
using URIs
5244
5345
# API versions
5446
const _module_versions = Dict{Module,String}()
5547
const _api_versions = Dict{DataType,String}()
5648
57-
# include Azure REST protocol (not Swagger)
49+
# include Azure REST protocol (not OpenAPI)
5850
include("rest_api_protocol.jl")
5951
6052
# inlcude sub modules for individual API groups"""
@@ -68,65 +60,51 @@ include("helper.jl")
6860
6961
end # module Azure"""
7062

71-
function genunit(pkg, grp, swg)
72-
open(TEMPCFGFILE, "w") do f
73-
println(f, """{ "packageName": "$pkg" } """)
74-
end
75-
outpath = joinpath(SRCDIR, grp)
76-
pkgpath = joinpath(outpath, pkg)
77-
mkpath(pkgpath)
78-
run(`$SWAGGERGEN -i $swg -o $outpath -c $TEMPCFGFILE`)
79-
for outfile in readdir(joinpath(outpath, "src"))
80-
outfile_from = joinpath(outpath, "src", outfile)
81-
outfile_to = joinpath(pkgpath, outfile)
82-
@debug("moving $outfile from $outfile_from to $outfile_to")
83-
mv(outfile_from, outfile_to)
84-
end
85-
rm(joinpath(outpath, "src"); force=true)
86-
rm(joinpath(outpath, "REQUIRE"); force=true)
87-
rm(joinpath(outpath, "LICENSE"); force=true)
88-
rm(joinpath(outpath, ".swagger-codegen-ignore"); force=true)
89-
rm(joinpath(outpath, ".swagger-codegen"); force=true, recursive=true)
90-
rm(TEMPCFGFILE; force=true)
91-
92-
# apply patches if any
93-
patches = get(PATCHES, (pkg,grp), [])
94-
for patch in patches
95-
patch_type, names = patch
96-
for name in names
97-
patchfile = patch_type * "_" * name * ".jl"
98-
cp(joinpath(DIR, patchfile), joinpath(pkgpath, patchfile); force=true)
99-
end
100-
end
63+
function commands(pkg, outpath, specfile)
64+
# add --global-property debugModels=true to turn on model debug output
65+
gencmd = `java -jar openapi-generator-cli.jar generate -i $specfile -g julia-client -o $outpath --additional-properties=packageName=$pkg`
66+
cleancmd = `rm -rf $outpath`
10167

102-
# return the module file to include
103-
module_file = joinpath(grp, pkg, pkg * ".jl")
68+
return cleancmd, gencmd
69+
end
70+
71+
function genunit(pkg, grp, specfile)
72+
outpath = joinpath(SRCDIR, grp, pkg)
73+
pkgpath = joinpath(outpath, pkg)
74+
# mkpath(pkgpath)
75+
cleancmd, gencmd = commands(pkg, outpath, specfile)
76+
run(cleancmd)
77+
run(gencmd)
78+
79+
# # return the module file to include
80+
module_file = joinpath(outpath, "src", pkg * ".jl")
81+
apispath = joinpath(outpath, "src", "apis")
10482
apinames = String[]
105-
for f in readdir(joinpath(outpath, pkg))
106-
if startswith(f, "api_")
107-
apiname = split(split(f, '_')[2], '.')[1]
108-
push!(apinames, apiname)
83+
if isdir(apispath)
84+
for f in readdir(apispath)
85+
if startswith(f, "api_")
86+
apiname = split(split(f, '_')[2], '.')[1]
87+
push!(apinames, apiname)
88+
end
10989
end
11090
end
11191
module_file, apinames
11292
end
11393

114-
function gen(swgroot)
94+
function gen(openapiroot)
11595
mkpath(SRCDIR)
11696

117-
for spec in SPECS
118-
pkg, grp, ver, swg = spec
119-
grppath = joinpath(SRCDIR, grp)
120-
rm(grppath; recursive=true, force=true)
121-
end
122-
12397
open(joinpath(SRCDIR, "Azure.jl"), "w") do azf
12498
println(azf, MODULE_HEAD)
12599

126100
for spec in SPECS
127-
pkg, grp, ver, swg = spec
128-
swg = replace(swg, "{VER}"=>ver)
129-
mod, apinames = genunit(pkg, grp, joinpath(swgroot, swg))
101+
pkg, grp, ver, openapispec = spec
102+
openapispec = replace(openapispec, "{VER}"=>ver)
103+
mod, apinames = genunit(pkg, grp, joinpath(openapiroot, openapispec))
104+
# mod returned will be absolute path, so would be SRCDIR
105+
# create relative path for inclusion in .jl file
106+
mod = relpath(mod, SRCDIR)
107+
130108
println(azf, "include(\"", mod, "\")")
131109
println(azf, "_module_versions[$pkg] = \"$ver\"")
132110
for apiname in apinames

gen/model_Caching.jl

Lines changed: 0 additions & 1 deletion
This file was deleted.

gen/model_CreateOption.jl

Lines changed: 0 additions & 1 deletion
This file was deleted.

gen/model_DeploymentPropertiesExtended.jl

Lines changed: 0 additions & 66 deletions
This file was deleted.

gen/model_StorageAccountType.jl

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)