-
Notifications
You must be signed in to change notification settings - Fork 54
/
regeneration.iced
152 lines (131 loc) · 5.79 KB
/
regeneration.iced
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
###############################################
# LEGACY
# Instead: have bunch of configuration files sitting in a well-known spot, discover them, feed them to AutoRest, done.
regenExpected = (opts,done) ->
outputDir = if !!opts.outputBaseDir then "#{opts.outputBaseDir}/#{opts.outputDir}" else opts.outputDir
keys = Object.getOwnPropertyNames(opts.mappings)
instances = keys.length
for kkey in keys
optsMappingsValue = opts.mappings[kkey]
key = kkey.trim();
swaggerFiles = (if optsMappingsValue instanceof Array then optsMappingsValue[0] else optsMappingsValue).split(";")
args = [
"--#{opts.language}",
"--clear-output-folder",
"--output-folder=#{outputDir}/#{key}",
"--license-header=#{if !!opts.header then opts.header else 'MICROSOFT_MIT_NO_VERSION'}",
"--enable-xml",
"--basic-setup-py",
"--trace",
]
for swaggerFile in swaggerFiles
args.push("--input-file=#{if !!opts.inputBaseDir then "#{opts.inputBaseDir}/#{swaggerFile}" else swaggerFile}")
if (opts.addCredentials)
args.push("--#{opts.language}.add-credentials=true")
if (opts.vanilla)
args.push("--#{opts.language}.vanilla=true")
if (opts.azureArm)
args.push("--#{opts.language}.azure-arm=true")
if (opts.flatteningThreshold)
args.push("--#{opts.language}.payload-flattening-threshold=#{opts.flatteningThreshold}")
if (opts.keepVersion)
args.push("--#{opts.language}.keep-version-file=true")
if (!!opts.nsPrefix)
if (optsMappingsValue instanceof Array && optsMappingsValue[1] != undefined)
args.push("--#{opts.language}.namespace=#{optsMappingsValue[1]}")
else
args.push("--#{opts.language}.namespace=#{[opts.nsPrefix, key.replace(/\/|\./, '')].join('.')}")
if (opts['override-info.version'])
args.push("--override-info.version=#{opts['override-info.version']}")
if (opts['override-info.title'])
args.push("--override-info.title=#{opts['override-info.title']}")
if (opts['override-info.description'])
args.push("--override-info.description=#{opts['override-info.description']}")
autorest args,() =>
instances--
return done() if instances is 0
defaultMappings = {
'AcceptanceTests/AdditionalProperties': 'additionalProperties.json',
'AcceptanceTests/ParameterFlattening': 'parameter-flattening.json',
'AcceptanceTests/BodyArray': 'body-array.json',
'AcceptanceTests/BodyBoolean': 'body-boolean.json',
'AcceptanceTests/BodyByte': 'body-byte.json',
'AcceptanceTests/BodyComplex': 'body-complex.json',
'AcceptanceTests/BodyDate': 'body-date.json',
'AcceptanceTests/BodyDateTime': 'body-datetime.json',
'AcceptanceTests/BodyDateTimeRfc1123': 'body-datetime-rfc1123.json',
'AcceptanceTests/BodyDuration': 'body-duration.json',
'AcceptanceTests/BodyDictionary': 'body-dictionary.json',
'AcceptanceTests/BodyFile': 'body-file.json',
'AcceptanceTests/BodyFormData': 'body-formdata.json',
'AcceptanceTests/BodyInteger': 'body-integer.json',
'AcceptanceTests/BodyNumber': 'body-number.json',
'AcceptanceTests/BodyString': 'body-string.json',
'AcceptanceTests/ExtensibleEnums': 'extensible-enums-swagger.json',
'AcceptanceTests/Header': 'header.json',
'AcceptanceTests/Http': 'httpInfrastructure.json',
'AcceptanceTests/Report': 'report.json',
'AcceptanceTests/RequiredOptional': 'required-optional.json',
'AcceptanceTests/Url': 'url.json',
'AcceptanceTests/Validation': 'validation.json',
'AcceptanceTests/CustomBaseUri': 'custom-baseUrl.json',
'AcceptanceTests/CustomBaseUriMoreOptions': 'custom-baseUrl-more-options.json',
'AcceptanceTests/ModelFlattening': 'model-flattening.json',
'AcceptanceTests/Xml': 'xml-service.json',
'AcceptanceTests/UrlMultiCollectionFormat' : 'url-multi-collectionFormat.json'
}
defaultAzureMappings = {
'AcceptanceTests/AzureBodyDuration': 'body-duration.json',
'AcceptanceTests/AzureReport': 'azure-report.json',
'AcceptanceTests/AzureParameterGrouping': 'azure-parameter-grouping.json',
'AcceptanceTests/ModelFlattening': 'model-flattening.json',
'AcceptanceTests/CustomBaseUri': 'custom-baseUrl.json'
}
# The list is mostly built on Swaggers that uses CloudError feature
# These Swagger should be modified to test their features, and not the CloudError one
defaultARMMappings = {
'AcceptanceTests/Head': 'head.json',
'AcceptanceTests/HeadExceptions': 'head-exceptions.json',
'AcceptanceTests/StorageManagementClient': 'storage.json',
'AcceptanceTests/Lro': 'lro.json',
'AcceptanceTests/SubscriptionIdApiVersion': 'subscriptionId-apiVersion.json',
'AcceptanceTests/Paging': 'paging.json',
'AcceptanceTests/CustomUrlPaging': 'custom-baseUrl-paging.json',
'AcceptanceTests/AzureSpecials': 'azure-special-properties.json',
}
swaggerDir = "node_modules/@microsoft.azure/autorest.testserver/swagger"
task 'regenerate-python', '', (done) ->
regenExpected {
'outputBaseDir': 'test/vanilla',
'inputBaseDir': swaggerDir,
'mappings': defaultMappings,
'outputDir': 'Expected',
'language': 'python',
'flatteningThreshold': '1',
'vanilla': true,
'keepVersion': true
},done
return null
task 'regenerate-pythonazure', '', (done) ->
regenExpected {
'outputBaseDir': 'test/azure',
'inputBaseDir': swaggerDir,
'mappings': defaultAzureMappings,
'outputDir': 'Expected',
'language': 'python',
'flatteningThreshold': '1'
},done
return null
task 'regenerate-pythonarm', '', (done) ->
regenExpected {
'outputBaseDir': 'test/azure',
'inputBaseDir': swaggerDir,
'mappings': defaultARMMappings,
'outputDir': 'Expected',
'language': 'python',
'azureArm': true,
'flatteningThreshold': '1'
},done
return null
task 'regenerate', "regenerate expected code for tests", ['regenerate-python', 'regenerate-pythonazure', 'regenerate-pythonarm'], (done) ->
done();