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