69516b2ade22f696f6793e99cfcd6b6e3570fbb9
[nonrtric/plt/sme.git] / capifcore / generate.sh
1 # -
2 #   ========================LICENSE_START=================================
3 #   O-RAN-SC
4 #   %%
5 #   Copyright (C) 2022: Nordix Foundation
6 #   %%
7 #   Licensed under the Apache License, Version 2.0 (the "License");
8 #   you may not use this file except in compliance with the License.
9 #   You may obtain a copy of the License at
10 #
11 #        http://www.apache.org/licenses/LICENSE-2.0
12 #
13 #   Unless required by applicable law or agreed to in writing, software
14 #   distributed under the License is distributed on an "AS IS" BASIS,
15 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 #   See the License for the specific language governing permissions and
17 #   limitations under the License.
18 #   ========================LICENSE_END===================================
19 #
20
21 cwd=$(pwd)
22
23 mkdir -p specs
24
25 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.222/29222-h60.zip -o specs/apidef.zip
26 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.122/29122-h70.zip -o specs/common29122apidef.zip
27 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.508/29508-h80.zip -o specs/common29508apidef.zip
28 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.510/29510-h70.zip -o specs/common29510apidef.zip
29 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.512/29512-h80.zip -o specs/common29512apidef.zip
30 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.514/29514-h60.zip -o specs/common29514apidef.zip
31 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.517/29517-h70.zip -o specs/common29517apidef.zip
32 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.518/29518-h70.zip -o specs/common29518apidef.zip
33 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.522/29522-h70.zip -o specs/common29522apidef.zip
34 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.523/29523-h80.zip -o specs/common29523apidef.zip
35 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.554/29554-h40.zip -o specs/common29554apidef.zip
36 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.571/29571-h70.zip -o specs/common29571apidef.zip
37 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.572/29572-h60.zip -o specs/common29572apidef.zip
38
39 cd specs/
40
41 jar xvf apidef.zip
42 jar xvf common29122apidef.zip
43 jar xvf common29508apidef.zip
44 jar xvf common29510apidef.zip
45 jar xvf common29512apidef.zip
46 jar xvf common29514apidef.zip
47 jar xvf common29517apidef.zip
48 jar xvf common29518apidef.zip
49 jar xvf common29522apidef.zip
50 jar xvf common29523apidef.zip
51 jar xvf common29554apidef.zip
52 jar xvf common29571apidef.zip
53 jar xvf common29572apidef.zip
54
55 # Remove types that are not used by CAPIF that have dependencies to other specifications.
56 sed -e 'H;x;/^\(  *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\CivicAddress/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml >temp.yaml
57 mv temp.yaml TS29571_CommonData.yaml
58 sed -e 'H;x;/^\(  *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\ExternalMbsServiceArea/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml >temp.yaml
59 mv temp.yaml TS29571_CommonData.yaml
60 sed -e 'H;x;/^\(  *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\GeographicArea/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml >temp.yaml
61 mv temp.yaml TS29571_CommonData.yaml
62 sed -e 'H;x;/^\(  *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\GeoServiceArea/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml >temp.yaml
63 mv temp.yaml TS29571_CommonData.yaml
64 sed -e 'H;x;/^\(  *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\MbsMediaComp/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml >temp.yaml
65 mv temp.yaml TS29571_CommonData.yaml
66 sed -e 'H;x;/^\(  *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\MbsMediaCompRm/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml >temp.yaml
67 mv temp.yaml TS29571_CommonData.yaml
68 sed -e 'H;x;/^\(  *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\MbsMediaInfo/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml >temp.yaml
69 mv temp.yaml TS29571_CommonData.yaml
70 sed -e 'H;x;/^\(  *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\MbsServiceInfo/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml >temp.yaml
71 mv temp.yaml TS29571_CommonData.yaml
72 sed -e 'H;x;/^\(  *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\MbsSession/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml >temp.yaml
73 mv temp.yaml TS29571_CommonData.yaml
74 sed -e 'H;x;/^\(  *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\SpatialValidityCond/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml >temp.yaml
75 mv temp.yaml TS29571_CommonData.yaml
76
77 # Remove attributes that can not be generated easily.
78 sed '/accessTokenError.*/,+3d' TS29571_CommonData.yaml >temp.yaml
79 mv temp.yaml TS29571_CommonData.yaml
80 sed '/accessTokenRequest.*/,+3d' TS29571_CommonData.yaml >temp.yaml
81 mv temp.yaml TS29571_CommonData.yaml
82
83 sed '/oneOf.*/,+2d' TS29222_CAPIF_Publish_Service_API.yaml >temp.yaml
84 mv temp.yaml TS29222_CAPIF_Publish_Service_API.yaml
85
86 sed '64,68d' TS29222_CAPIF_Discover_Service_API.yaml >temp.yaml # Remove parameter preferred-aef-loc since it doesn't follow the OpenApi specification, "The behavior for nested objects and arrays is undefined."
87 mv temp.yaml TS29222_CAPIF_Discover_Service_API.yaml
88
89 # Replace references to external specs that are collected to the common spec by the commoncollector
90 # <replacements_start>
91 cat TS29122_CommonData.yaml | sed 's/TS29572_Nlmf_Location/CommonData/g' > temp.yaml
92 mv temp.yaml TS29122_CommonData.yaml
93 cat TS29122_CommonData.yaml | sed 's/TS29554_Npcf_BDTPolicyControl/CommonData/g' > temp.yaml
94 mv temp.yaml TS29122_CommonData.yaml
95 cat TS29122_CommonData.yaml | sed 's/TS29514_Npcf_PolicyAuthorization/CommonData/g' > temp.yaml
96 mv temp.yaml TS29122_CommonData.yaml
97 cat TS29571_CommonData.yaml | sed 's/TS29514_Npcf_PolicyAuthorization/CommonData/g' > temp.yaml
98 mv temp.yaml TS29571_CommonData.yaml
99 cat TS29571_CommonData.yaml | sed 's/TS29572_Nlmf_Location/CommonData/g' > temp.yaml
100 mv temp.yaml TS29571_CommonData.yaml
101 cat TS29222_CAPIF_Publish_Service_API.yaml | sed 's/TS29572_Nlmf_Location/CommonData/g' > temp.yaml
102 mv temp.yaml TS29222_CAPIF_Publish_Service_API.yaml
103 cat TS29222_CAPIF_Routing_Info_API.yaml | sed 's/TS29520_Nnwdaf_EventsSubscription/CommonData/g' > temp.yaml
104 mv temp.yaml TS29222_CAPIF_Routing_Info_API.yaml
105 cat TS29222_CAPIF_Routing_Info_API.yaml | sed 's/TS29510_Nnrf_NFManagement/CommonData/g' > temp.yaml
106 mv temp.yaml TS29222_CAPIF_Routing_Info_API.yaml
107 cat TS29222_CAPIF_Events_API.yaml | sed 's/TS29523_Npcf_EventExposure/CommonData/g' > temp.yaml
108 mv temp.yaml TS29222_CAPIF_Events_API.yaml
109 # <new_replacement>
110
111 # This spec has references to itself that need to be removed
112 cat TS29571_CommonData.yaml | sed 's/TS29571_CommonData.yaml//g' > temp.yaml
113 mv temp.yaml TS29571_CommonData.yaml
114
115 cd $cwd
116
117 echo "Fixing enums"
118 cd internal/gentools/enumfixer
119 go build .
120 ./enumfixer -apidir=../../../specs
121
122 cd $cwd
123 echo "Gathering common references"
124 cd internal/gentools/commoncollector
125 go build .
126 ./commoncollector -apidir=../../../specs
127
128 cd $cwd
129 echo "Fixing misc in specifications"
130 cd internal/gentools/specificationfixer
131 go build .
132 ./specificationfixer -apidir=../../../specs
133
134 cd $cwd
135
136 go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v1.10.1
137 PATH=$PATH:~/go/bin
138
139 echo "Generating TS29122_CommonData"
140 mkdir -p internal/common29122
141 oapi-codegen --config gogeneratorspecs/common29122/generator_settings.yaml specs/TS29122_CommonData.yaml
142
143 echo "Generating aggregated CommonData"
144 mkdir -p internal/common
145 oapi-codegen --config gogeneratorspecs/common/generator_settings.yaml specs/CommonData.yaml
146
147 echo "Generating TS29571_CommonData"
148 mkdir -p internal/common29571
149 oapi-codegen --config gogeneratorspecs/common29571/generator_settings.yaml specs/TS29571_CommonData.yaml
150
151 echo "Generating TS29222_CAPIF_Publish_Service_API"
152 mkdir -p internal/publishserviceapi
153 oapi-codegen --config gogeneratorspecs/publishserviceapi/generator_settings_types.yaml specs/TS29222_CAPIF_Publish_Service_API.yaml
154 oapi-codegen --config gogeneratorspecs/publishserviceapi/generator_settings_server.yaml specs/TS29222_CAPIF_Publish_Service_API.yaml
155
156 echo "Generating TS29222_CAPIF_API_Invoker_Management_API"
157 mkdir -p internal/invokermanagementapi
158 oapi-codegen --config gogeneratorspecs/invokermanagementapi/generator_settings_types.yaml specs/TS29222_CAPIF_API_Invoker_Management_API.yaml
159 oapi-codegen --config gogeneratorspecs/invokermanagementapi/generator_settings_server.yaml specs/TS29222_CAPIF_API_Invoker_Management_API.yaml
160
161 echo "Generating TS29222_CAPIF_API_Provider_Management_API"
162 mkdir -p internal/providermanagementapi
163 oapi-codegen --config gogeneratorspecs/providermanagementapi/generator_settings_types.yaml specs/TS29222_CAPIF_API_Provider_Management_API.yaml
164 oapi-codegen --config gogeneratorspecs/providermanagementapi/generator_settings_server.yaml specs/TS29222_CAPIF_API_Provider_Management_API.yaml
165
166 echo "Generating TS29222_CAPIF_Discover_Service_API"
167 mkdir -p internal/discoverserviceapi
168 oapi-codegen --config gogeneratorspecs/discoverserviceapi/generator_settings_types.yaml specs/TS29222_CAPIF_Discover_Service_API.yaml
169 oapi-codegen --config gogeneratorspecs/discoverserviceapi/generator_settings_server.yaml specs/TS29222_CAPIF_Discover_Service_API.yaml
170
171 echo "Generating TS29222_CAPIF_Security_API"
172 mkdir -p internal/securityapi
173 oapi-codegen --config gogeneratorspecs/securityapi/generator_settings_types.yaml specs/TS29222_CAPIF_Security_API.yaml
174 oapi-codegen --config gogeneratorspecs/securityapi/generator_settings_server.yaml specs/TS29222_CAPIF_Security_API.yaml
175
176 echo "Generating TS29222_CAPIF_Logging_API_Invocation_API"
177 mkdir -p internal/loggingapi
178 oapi-codegen --config gogeneratorspecs/loggingapi/generator_settings_types.yaml specs/TS29222_CAPIF_Logging_API_Invocation_API.yaml
179 oapi-codegen --config gogeneratorspecs/loggingapi/generator_settings_server.yaml specs/TS29222_CAPIF_Logging_API_Invocation_API.yaml
180
181 echo "Generating TS29222_CAPIF_Routing_Info_API"
182 mkdir -p internal/routinginfoapi
183 oapi-codegen --config gogeneratorspecs/routinginfoapi/generator_settings_types.yaml specs/TS29222_CAPIF_Routing_Info_API.yaml
184 oapi-codegen --config gogeneratorspecs/routinginfoapi/generator_settings_server.yaml specs/TS29222_CAPIF_Routing_Info_API.yaml
185
186 echo "Generating TS29222_CAPIF_Access_Control_Policy_API"
187 mkdir -p internal/accesscontrolpolicyapi
188 oapi-codegen --config gogeneratorspecs/accesscontrolpolicyapi/generator_settings_types.yaml specs/TS29222_CAPIF_Access_Control_Policy_API.yaml
189 oapi-codegen --config gogeneratorspecs/accesscontrolpolicyapi/generator_settings_server.yaml specs/TS29222_CAPIF_Access_Control_Policy_API.yaml
190
191 echo "Generating TS29222_CAPIF_Events_API"
192 mkdir -p internal/eventsapi
193 oapi-codegen --config gogeneratorspecs/eventsapi/generator_settings_types.yaml specs/TS29222_CAPIF_Events_API.yaml
194 oapi-codegen --config gogeneratorspecs/eventsapi/generator_settings_server.yaml specs/TS29222_CAPIF_Events_API.yaml
195
196 echo "Generating TS29222_CAPIF_Auditing_API"
197 mkdir -p internal/auditingapi
198 oapi-codegen --config gogeneratorspecs/auditingapi/generator_settings_types.yaml specs/TS29222_CAPIF_Auditing_API.yaml
199 oapi-codegen --config gogeneratorspecs/auditingapi/generator_settings_server.yaml specs/TS29222_CAPIF_Auditing_API.yaml
200
201 echo "Generating TS29222_AEF_Security_API"
202 mkdir -p internal/aefsecurityapi
203 oapi-codegen --config gogeneratorspecs/aefsecurityapi/generator_settings_types.yaml specs/TS29222_AEF_Security_API.yaml
204 oapi-codegen --config gogeneratorspecs/aefsecurityapi/generator_settings_server.yaml specs/TS29222_AEF_Security_API.yaml
205
206 echo "Cleanup"
207 rm -rf specs
208
209 echo "Generating mocks."
210 go generate ./...