@@ -41,37 +41,48 @@ public CreateCommand()
41
41
42
42
// create templates from provided configuration
43
43
Template apiVersionSetTemplate = creatorConfig . apiVersionSet != null ? apiVersionSetTemplateCreator . CreateAPIVersionSetTemplate ( creatorConfig ) : null ;
44
- Template initialAPITemplate = await apiTemplateCreator . CreateInitialAPITemplateAsync ( creatorConfig ) ;
45
- Template subsequentAPITemplate = apiTemplateCreator . CreateSubsequentAPITemplate ( creatorConfig ) ;
46
- CreatorFileNames creatorFileNames = fileWriter . GenerateCreatorLinkedFileNames ( creatorConfig ) ;
44
+ List < Template > initialAPITemplates = new List < Template > ( ) ;
45
+ List < Template > subsequentAPITemplates = new List < Template > ( ) ;
46
+ List < LinkedMasterTemplateAPIInformation > apiInformation = new List < LinkedMasterTemplateAPIInformation > ( ) ;
47
+
48
+ foreach ( APIConfig api in creatorConfig . apis )
49
+ {
50
+ Template initialAPITemplate = await apiTemplateCreator . CreateInitialAPITemplateAsync ( creatorConfig , api ) ;
51
+ Template subsequentAPITemplate = apiTemplateCreator . CreateSubsequentAPITemplate ( api ) ;
52
+ initialAPITemplates . Add ( initialAPITemplate ) ;
53
+ subsequentAPITemplates . Add ( subsequentAPITemplate ) ;
54
+ apiInformation . Add ( new LinkedMasterTemplateAPIInformation ( ) { name = api . name , hasAPIVersionSetId = api . apiVersionSetId != null } ) ;
55
+ }
47
56
57
+ CreatorFileNames creatorFileNames = fileWriter . GenerateCreatorLinkedFileNames ( creatorConfig ) ;
48
58
if ( creatorConfig . linked == true )
49
59
{
50
60
// create linked master template
51
- Template masterTemplate = masterTemplateCreator . CreateLinkedMasterTemplate ( apiVersionSetTemplate , initialAPITemplate , subsequentAPITemplate , creatorFileNames ) ;
52
- Template masterTemplateParameters = masterTemplateCreator . CreateMasterTemplateParameterValues ( creatorConfig ) ;
53
-
54
- // write templates to outputLocation
55
- if ( apiVersionSetTemplate != null )
56
- {
57
- fileWriter . WriteJSONToFile ( apiVersionSetTemplate , String . Concat ( creatorConfig . outputLocation , creatorFileNames . apiVersionSet ) ) ;
58
- }
59
- fileWriter . WriteJSONToFile ( initialAPITemplate , String . Concat ( creatorConfig . outputLocation , creatorFileNames . initialAPI ) ) ;
60
- fileWriter . WriteJSONToFile ( subsequentAPITemplate , String . Concat ( creatorConfig . outputLocation , creatorFileNames . subsequentAPI ) ) ;
61
+ Template masterTemplate = masterTemplateCreator . CreateLinkedMasterTemplate ( apiVersionSetTemplate , apiInformation , creatorFileNames ) ;
62
+ // write linked specific template to outputLocationc
61
63
fileWriter . WriteJSONToFile ( masterTemplate , String . Concat ( creatorConfig . outputLocation , creatorFileNames . linkedMaster ) ) ;
62
- fileWriter . WriteJSONToFile ( masterTemplateParameters , String . Concat ( creatorConfig . outputLocation , creatorFileNames . masterParameters ) ) ;
63
64
}
64
65
else
65
66
{
66
- // create unlinked master template
67
- Template initialMasterTemplate = masterTemplateCreator . CreateInitialUnlinkedMasterTemplate ( apiVersionSetTemplate , initialAPITemplate ) ;
68
- Template subsequentMasterTemplate = masterTemplateCreator . CreateSubsequentUnlinkedMasterTemplate ( subsequentAPITemplate ) ;
69
- Template masterTemplateParameters = masterTemplateCreator . CreateMasterTemplateParameterValues ( creatorConfig ) ;
67
+ // write unlinked specific templates to outputLocationc
68
+ foreach ( Template initialAPITemplate in initialAPITemplates )
69
+ {
70
+ fileWriter . WriteJSONToFile ( initialAPITemplate , String . Concat ( creatorConfig . outputLocation , creatorFileNames . initialAPI ) ) ;
71
+ }
72
+ foreach ( Template subsequentAPITemplate in subsequentAPITemplates )
73
+ {
74
+ fileWriter . WriteJSONToFile ( subsequentAPITemplate , String . Concat ( creatorConfig . outputLocation , creatorFileNames . subsequentAPI ) ) ;
75
+ }
70
76
71
- // write templates to outputLocation
72
- fileWriter . WriteJSONToFile ( initialMasterTemplate , String . Concat ( creatorConfig . outputLocation , creatorFileNames . unlinkedMasterOne ) ) ;
73
- fileWriter . WriteJSONToFile ( subsequentMasterTemplate , String . Concat ( creatorConfig . outputLocation , creatorFileNames . unlinkedMasterTwo ) ) ;
74
- fileWriter . WriteJSONToFile ( masterTemplateParameters , String . Concat ( creatorConfig . outputLocation , creatorFileNames . masterParameters ) ) ;
77
+ }
78
+ // write parameters to outputLocation
79
+ Template masterTemplateParameters = masterTemplateCreator . CreateMasterTemplateParameterValues ( creatorConfig ) ;
80
+ fileWriter . WriteJSONToFile ( masterTemplateParameters , String . Concat ( creatorConfig . outputLocation , creatorFileNames . masterParameters ) ) ;
81
+
82
+ // write common templates to outputLocationc
83
+ if ( apiVersionSetTemplate != null )
84
+ {
85
+ fileWriter . WriteJSONToFile ( apiVersionSetTemplate , String . Concat ( creatorConfig . outputLocation , creatorFileNames . apiVersionSet ) ) ;
75
86
}
76
87
ColoredConsole . WriteLine ( "Templates written to output location" ) ;
77
88
}
@@ -98,26 +109,6 @@ public bool ValidateCreatorConfig(CreatorConfig creatorConfig)
98
109
isValid = false ;
99
110
throw new CommandParsingException ( this , "APIM service name is required" ) ;
100
111
}
101
- if ( creatorConfig . api == null )
102
- {
103
- isValid = false ;
104
- throw new CommandParsingException ( this , "API configuration is required" ) ;
105
- }
106
- if ( creatorConfig . api . openApiSpec == null )
107
- {
108
- isValid = false ;
109
- throw new CommandParsingException ( this , "Open API Spec is required" ) ;
110
- }
111
- if ( creatorConfig . api . suffix == null )
112
- {
113
- isValid = false ;
114
- throw new CommandParsingException ( this , "API suffix is required" ) ;
115
- }
116
- if ( creatorConfig . api . name == null )
117
- {
118
- isValid = false ;
119
- throw new CommandParsingException ( this , "API name is required" ) ;
120
- }
121
112
if ( creatorConfig . linked == true && creatorConfig . linkedTemplatesBaseUrl == null )
122
113
{
123
114
isValid = false ;
@@ -133,21 +124,44 @@ public bool ValidateCreatorConfig(CreatorConfig creatorConfig)
133
124
isValid = false ;
134
125
throw new CommandParsingException ( this , "Versioning scheme is required if an API Version Set is provided" ) ;
135
126
}
136
- if ( creatorConfig . api . operations != null )
127
+ foreach ( APIConfig api in creatorConfig . apis )
137
128
{
138
- foreach ( KeyValuePair < string , OperationsConfig > operation in creatorConfig . api . operations )
129
+ if ( api == null )
139
130
{
140
- if ( operation . Value == null || operation . Value . policy == null )
131
+ isValid = false ;
132
+ throw new CommandParsingException ( this , "API configuration is required" ) ;
133
+ }
134
+ if ( api . openApiSpec == null )
135
+ {
136
+ isValid = false ;
137
+ throw new CommandParsingException ( this , "Open API Spec is required" ) ;
138
+ }
139
+ if ( api . suffix == null )
140
+ {
141
+ isValid = false ;
142
+ throw new CommandParsingException ( this , "API suffix is required" ) ;
143
+ }
144
+ if ( api . name == null )
145
+ {
146
+ isValid = false ;
147
+ throw new CommandParsingException ( this , "API name is required" ) ;
148
+ }
149
+ if ( api . operations != null )
150
+ {
151
+ foreach ( KeyValuePair < string , OperationsConfig > operation in api . operations )
141
152
{
142
- isValid = false ;
143
- throw new CommandParsingException ( this , "Policy XML is required if an API operation is provided" ) ;
153
+ if ( operation . Value == null || operation . Value . policy == null )
154
+ {
155
+ isValid = false ;
156
+ throw new CommandParsingException ( this , "Policy XML is required if an API operation is provided" ) ;
157
+ }
144
158
}
145
159
}
146
- }
147
- if ( creatorConfig . api . diagnostic != null && creatorConfig . api . diagnostic . loggerId == null )
148
- {
149
- isValid = false ;
150
- throw new CommandParsingException ( this , "LoggerId is required if an API diagnostic is provided" ) ;
160
+ if ( api . diagnostic != null && api . diagnostic . loggerId == null )
161
+ {
162
+ isValid = false ;
163
+ throw new CommandParsingException ( this , "LoggerId is required if an API diagnostic is provided" ) ;
164
+ }
151
165
}
152
166
return isValid ;
153
167
}
0 commit comments