3 # ========================LICENSE_START=================================
6 # Copyright (C) 2024: OpenInfra Foundation Europe
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 # ========================LICENSE_END===================================
22 make_internal_dirs () {
23 echo "Make the internal API directory structure"
24 mkdir -p internal/discoverserviceapi
25 mkdir -p internal/invokermanagementapi
26 mkdir -p internal/providermanagementapi
27 mkdir -p internal/publishserviceapi
31 echo "Set up dir paths"
33 sme_dir=$(dirname "$cwd")
34 capifcore_dir="$sme_dir/capifcore"
38 echo "Curl down the API specs"
40 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.222/29222-h60.zip -o specs/apidef.zip
41 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.122/29122-h70.zip -o specs/common29122apidef.zip
42 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.508/29508-h80.zip -o specs/common29508apidef.zip
43 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.510/29510-h70.zip -o specs/common29510apidef.zip
44 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.512/29512-h80.zip -o specs/common29512apidef.zip
45 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.514/29514-h60.zip -o specs/common29514apidef.zip
46 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.517/29517-h70.zip -o specs/common29517apidef.zip
47 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.518/29518-h70.zip -o specs/common29518apidef.zip
48 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.522/29522-h70.zip -o specs/common29522apidef.zip
49 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.523/29523-h80.zip -o specs/common29523apidef.zip
50 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.554/29554-h40.zip -o specs/common29554apidef.zip
51 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.571/29571-h70.zip -o specs/common29571apidef.zip
52 curl https://www.3gpp.org/ftp/Specs/archive/29_series/29.572/29572-h60.zip -o specs/common29572apidef.zip
57 echo "Specifications extraction"
59 unzip -o common29122apidef.zip
60 unzip -o common29508apidef.zip
61 unzip -o common29510apidef.zip
62 unzip -o common29512apidef.zip
63 unzip -o common29514apidef.zip
64 unzip -o common29517apidef.zip
65 unzip -o common29518apidef.zip
66 unzip -o common29522apidef.zip
67 unzip -o common29523apidef.zip
68 unzip -o common29554apidef.zip
69 unzip -o common29571apidef.zip
70 unzip -o common29572apidef.zip
74 echo "Fixing with sed"
76 # Remove types that are not used by CAPIF that have dependencies to other specifications.
77 sed -i -e 'H;x;/^\( *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\CivicAddress/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml
78 sed -i -e 'H;x;/^\( *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\ExternalMbsServiceArea/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml
79 sed -i -e 'H;x;/^\( *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\GeographicArea/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml
80 sed -i -e 'H;x;/^\( *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\GeoServiceArea/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml
81 sed -i -e 'H;x;/^\( *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\MbsMediaComp/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml
82 sed -i -e 'H;x;/^\( *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\MbsMediaCompRm/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml
83 sed -i -e 'H;x;/^\( *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\MbsMediaInfo/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml
84 sed -i -e 'H;x;/^\( *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\MbsServiceInfo/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml
85 sed -i -e 'H;x;/^\( *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\MbsSession/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml
86 sed -i -e 'H;x;/^\( *\)\n\1/{s/\n.*//;x;d;}' -e 's/.*//;x;/\SpatialValidityCond/{s/^\( *\).*/ \1/;x;d;}' TS29571_CommonData.yaml
88 # Remove attributes that cannot be generated easily.
89 sed -i '/accessTokenError.*/,+3d' TS29571_CommonData.yaml
90 sed -i '/accessTokenRequest.*/,+3d' TS29571_CommonData.yaml
91 sed -i '/oneOf.*/,+2d' TS29222_CAPIF_Publish_Service_API.yaml
92 sed -i '/oneOf.*/,+2d' TS29222_CAPIF_Security_API.yaml
94 # Replace references to external specs that are collected to the common spec by the commoncollector
95 # <replacements_start>
96 sed -i 's/TS29572_Nlmf_Location/CommonData/g' TS29122_CommonData.yaml
97 sed -i 's/TS29554_Npcf_BDTPolicyControl/CommonData/g' TS29122_CommonData.yaml
98 sed -i 's/TS29514_Npcf_PolicyAuthorization/CommonData/g' TS29122_CommonData.yaml
99 sed -i 's/TS29514_Npcf_PolicyAuthorization/CommonData/g' TS29571_CommonData.yaml
100 sed -i 's/TS29572_Nlmf_Location/CommonData/g' TS29571_CommonData.yaml
101 sed -i 's/TS29572_Nlmf_Location/CommonData/g' TS29222_CAPIF_Publish_Service_API.yaml
102 sed -i 's/TS29520_Nnwdaf_EventsSubscription/CommonData/g' TS29222_CAPIF_Routing_Info_API.yaml
103 sed -i 's/TS29510_Nnrf_NFManagement/CommonData/g' TS29222_CAPIF_Routing_Info_API.yaml
104 sed -i 's/TS29523_Npcf_EventExposure/CommonData/g' TS29222_CAPIF_Events_API.yaml
107 # This spec has references to itself that need to be removed
108 sed -i 's/TS29571_CommonData.yaml//g' TS29571_CommonData.yaml
114 cd "$capifcore_dir/internal/gentools/enumfixer"
116 ./enumfixer -apidir="$sme_dir/servicemanager/specs"
118 echo "Gathering common references"
119 cd "$capifcore_dir/internal/gentools/commoncollector"
121 ./commoncollector -apidir="$sme_dir/servicemanager/specs"
123 echo "Fixing misc in specifications"
124 cd "$capifcore_dir/internal/gentools/specificationfixer"
126 ./specificationfixer -apidir="$sme_dir/servicemanager/specs"
129 generate_apis_from_spec () {
130 go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v1.10.1
135 echo "Generating TS29122_CommonData"
136 mkdir -p internal/common29122
137 oapi-codegen --config "gogeneratorspecs/common29122/generator_settings.yaml" specs/TS29122_CommonData.yaml
139 echo "Generating aggregated CommonData"
140 mkdir -p internal/common
141 oapi-codegen --config "gogeneratorspecs/common/generator_settings.yaml" specs/CommonData.yaml
143 echo "Generating TS29571_CommonData"
144 mkdir -p internal/common29571
145 oapi-codegen --config "gogeneratorspecs/common29571/generator_settings.yaml" specs/TS29571_CommonData.yaml
147 echo "Generating TS29222_CAPIF_Publish_Service_API"
148 mkdir -p internal/publishserviceapi
149 oapi-codegen --config "gogeneratorspecs/publishserviceapi/generator_settings_types.yaml" specs/TS29222_CAPIF_Publish_Service_API.yaml
150 oapi-codegen --config "gogeneratorspecs/publishserviceapi/generator_settings_server.yaml" specs/TS29222_CAPIF_Publish_Service_API.yaml
151 oapi-codegen --config "gogeneratorspecs/publishserviceapi/generator_settings_client.yaml" specs/TS29222_CAPIF_Publish_Service_API.yaml
153 echo "Generating TS29222_CAPIF_API_Invoker_Management_API"
154 mkdir -p internal/invokermanagementapi
155 oapi-codegen --config "gogeneratorspecs/invokermanagementapi/generator_settings_types.yaml" specs/TS29222_CAPIF_API_Invoker_Management_API.yaml
156 oapi-codegen --config "gogeneratorspecs/invokermanagementapi/generator_settings_server.yaml" specs/TS29222_CAPIF_API_Invoker_Management_API.yaml
157 oapi-codegen --config "gogeneratorspecs/invokermanagementapi/generator_settings_client.yaml" specs/TS29222_CAPIF_API_Invoker_Management_API.yaml
159 echo "Generating TS29222_CAPIF_API_Provider_Management_API"
160 mkdir -p internal/providermanagementapi
161 oapi-codegen --config "gogeneratorspecs/providermanagementapi/generator_settings_types.yaml" specs/TS29222_CAPIF_API_Provider_Management_API.yaml
162 oapi-codegen --config "gogeneratorspecs/providermanagementapi/generator_settings_server.yaml" specs/TS29222_CAPIF_API_Provider_Management_API.yaml
163 oapi-codegen --config "gogeneratorspecs/providermanagementapi/generator_settings_client.yaml" specs/TS29222_CAPIF_API_Provider_Management_API.yaml
165 echo "Generating TS29222_CAPIF_Discover_Service_API"
166 mkdir -p internal/discoverserviceapi
167 oapi-codegen --config "gogeneratorspecs/discoverserviceapi/generator_settings_types.yaml" specs/TS29222_CAPIF_Discover_Service_API.yaml
168 oapi-codegen --config "gogeneratorspecs/discoverserviceapi/generator_settings_server.yaml" specs/TS29222_CAPIF_Discover_Service_API.yaml
169 oapi-codegen --config "gogeneratorspecs/discoverserviceapi/generator_settings_client.yaml" specs/TS29222_CAPIF_Discover_Service_API.yaml
172 generate_html2_from_spec() {
175 echo "Generating Provider_Management HTML"
177 -u $(id -u ${USER}):$(id -g ${USER}) \
178 -v ${PWD}:/local openapitools/openapi-generator-cli generate \
179 -i /local/specs/TS29222_CAPIF_API_Provider_Management_API.yaml \
181 -o /local/openapi/html2/Provider_Management
182 mv -v openapi/html2/Provider_Management/index.html openapi/html2/Provider_Management/Provider_Management.html
184 echo "Generating Publish_Service HTML"
186 -u $(id -u ${USER}):$(id -g ${USER}) \
187 -v ${PWD}:/local openapitools/openapi-generator-cli generate \
188 -i /local/specs/TS29222_CAPIF_Publish_Service_API.yaml \
190 -o /local/openapi/html2/Publish_Service
191 mv -v openapi/html2/Publish_Service/index.html openapi/html2/Publish_Service/Publish_Service.html
193 echo "Generating Invoker_Management HTML"
195 -u $(id -u ${USER}):$(id -g ${USER}) \
196 -v ${PWD}:/local openapitools/openapi-generator-cli generate \
197 -i /local/specs/TS29222_CAPIF_API_Invoker_Management_API.yaml \
199 -o /local/openapi/html2/Invoker_Management
200 mv -v openapi/html2/Invoker_Management/index.html openapi/html2/Invoker_Management/Invoker_Management.html
202 echo "Generating Discover_Service HTML"
204 -u $(id -u ${USER}):$(id -g ${USER}) \
205 -v ${PWD}:/local openapitools/openapi-generator-cli generate \
206 -i /local/specs/TS29222_CAPIF_Discover_Service_API.yaml \
208 -o /local/openapi/html2/Discover_Service
209 mv -v openapi/html2/Discover_Service/index.html openapi/html2/Discover_Service/Discover_Service.html
211 echo "Generating Events HTML"
213 -u $(id -u ${USER}):$(id -g ${USER}) \
214 -v ${PWD}:/local openapitools/openapi-generator-cli generate \
215 -i /local/specs/TS29222_CAPIF_Events_API.yaml \
217 -o /local/openapi/html2/Events
218 mv -v openapi/html2/Events/index.html openapi/html2/Events/Events.html
220 echo "Generating Security HTML"
222 -u $(id -u ${USER}):$(id -g ${USER}) \
223 -v ${PWD}:/local openapitools/openapi-generator-cli generate \
224 -i /local/specs/TS29222_CAPIF_Security_API.yaml \
226 -o /local/openapi/html2/Security
227 mv -v openapi/html2/Security/index.html openapi/html2/Security/Security.html
229 mkdir -vp ../docs/openapi
230 find openapi/html2 -type f -name "*.html" -exec cp -v {} ../docs/openapi \;
234 # Make sure that SERVICE_MANAGER_ENV is configured with the required .env file, e.g.
235 # export SERVICE_MANAGER_ENV=development
241 echo $(date -u) "generate started"
243 # Check if the run-tests switch is provided as a command-line argument
245 while [[ "$#" -gt 0 ]]; do
249 shift # consume the switch
252 echo "Unknown argument: $1"
265 generate_apis_from_spec
266 generate_html2_from_spec
270 # Check if the run-tests switch is enabled
271 if [ "$RUN_TESTS" = true ]; then
272 echo "Running tests!"
275 echo "Not running tests."
278 echo $(date -u) "generate completed"