From bd79b2498551ac511b56384d99414ff2aec52296 Mon Sep 17 00:00:00 2001 From: "aravind.est" Date: Thu, 7 Mar 2024 18:32:15 +0000 Subject: [PATCH] Refactor SME swagger generation and remove OS profiles SME swagger generation logic moved to go. OS based files removed. OS based profile handling in maven removed. Issue-ID: NONRTRIC-986 Change-Id: Ic33050488843fbd5400cb754092e0630ba40dc03 Signed-off-by: aravind.est --- pom.xml | 27 +--------- rapp-manager-sme/pom.xml | 36 ++++++++++++- scripts/init/getsmeswagger.go | 116 ++++++++++++++++++++++------------------- scripts/init/init-sme-spec.bat | 46 ---------------- scripts/init/init-sme-spec.sh | 47 ----------------- 5 files changed, 97 insertions(+), 175 deletions(-) delete mode 100755 scripts/init/init-sme-spec.bat delete mode 100755 scripts/init/init-sme-spec.sh diff --git a/pom.xml b/pom.xml index 79d2934..f392133 100755 --- a/pom.xml +++ b/pom.xml @@ -63,34 +63,9 @@ 2.0.12 4.4.16 3.1.0 + 3.3.1 1.25.0 - - - Windows - - - Windows - - - - .bat - \ - - - - unix - - - unix - - - - .sh - / - - - diff --git a/rapp-manager-sme/pom.xml b/rapp-manager-sme/pom.xml index eb82cfa..dd877d2 100755 --- a/rapp-manager-sme/pom.xml +++ b/rapp-manager-sme/pom.xml @@ -96,14 +96,46 @@ initialize-sme-openapi-specs - initialize + generate-sources exec + + ${project.parent.basedir}/sme/capifcore + - ..${file.separator}scripts${file.separator}init${file.separator}init-sme-spec${script.extension} + go + + run + getsmeswagger.go + + + + + + + maven-resources-plugin + ${copy-resources-maven-plugin.version} + + + copy-swagger-generator + initialize + + copy-resources + + + ${project.parent.basedir}/sme/capifcore + + + ${project.parent.basedir}/scripts/init/ + + getsmeswagger.go + + false + + diff --git a/scripts/init/getsmeswagger.go b/scripts/init/getsmeswagger.go index 65826a2..0e2c8ce 100755 --- a/scripts/init/getsmeswagger.go +++ b/scripts/init/getsmeswagger.go @@ -3,6 +3,7 @@ // O-RAN-SC // %% // Copyright (C) 2023: Nordix Foundation +// Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved. // %% // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -20,76 +21,83 @@ package main - import ( + "encoding/json" + "fmt" "github.com/getkin/kin-openapi/openapi3" log "github.com/sirupsen/logrus" "gopkg.in/yaml.v3" - "encoding/json" - "io/ioutil" + "io/ioutil" + "os" + "oransc.org/nonrtric/capifcore/internal/common" + "oransc.org/nonrtric/capifcore/internal/common29122" + "oransc.org/nonrtric/capifcore/internal/common29571" "oransc.org/nonrtric/capifcore/internal/invokermanagementapi" "oransc.org/nonrtric/capifcore/internal/providermanagementapi" "oransc.org/nonrtric/capifcore/internal/publishserviceapi" - "oransc.org/nonrtric/capifcore/internal/common" - "oransc.org/nonrtric/capifcore/internal/common29122" - "oransc.org/nonrtric/capifcore/internal/common29571" ) -func main() { - var swagger *openapi3.T - var err error - - swagger,err = providermanagementapi.GetSwagger() - if err == nil { - generateSwaggerYaml(swagger, "TS29222_CAPIF_API_Provider_Management_API.yaml") - } - - swagger,err = publishserviceapi.GetSwagger() - if err == nil { - generateSwaggerYaml(swagger, "TS29222_CAPIF_Publish_Service_API.yaml") - } - - swagger,err = invokermanagementapi.GetSwagger() - if err == nil { - generateSwaggerYaml(swagger, "TS29222_CAPIF_API_Invoker_Management_API.yaml") - } +type fn func() (swagger *openapi3.T, err error) - swagger,err = common.GetSwagger() - if err == nil { - generateSwaggerYaml(swagger, "CommonData.yaml") - } +var smeOpenApiFileLocation string = "../../openapi/sme/" - swagger,err = common29122.GetSwagger() - if err == nil { - generateSwaggerYaml(swagger, "TS29122_CommonData.yaml") - } +func main() { - swagger,err = common29571.GetSwagger() - if err == nil { - generateSwaggerYaml(swagger, "TS29571_CommonData.yaml") - } + var err error + fmt.Println("Generating SME openapi spec...") + os.MkdirAll(smeOpenApiFileLocation, 0755) + if err == nil { + generateAndCopySwagger("TS29222_CAPIF_API_Provider_Management_API.yaml", providermanagementapi.GetSwagger) + generateAndCopySwagger("TS29222_CAPIF_Publish_Service_API.yaml", publishserviceapi.GetSwagger) + generateAndCopySwagger("TS29222_CAPIF_API_Invoker_Management_API.yaml", invokermanagementapi.GetSwagger) + generateAndCopySwagger("CommonData.yaml", common.GetSwagger) + generateAndCopySwagger("TS29122_CommonData.yaml", common29122.GetSwagger) + generateAndCopySwagger("TS29571_CommonData.yaml", common29571.GetSwagger) + } } func generateSwaggerYaml(swagger *openapi3.T, filename string) { - jsondataarr, jsondataarrerr := json.Marshal(&swagger) - if jsondataarrerr != nil { - log.Fatalf("Error loading json data from swagger \n: %s", jsondataarrerr) - } + jsondataarr, jsondataarrerr := json.Marshal(&swagger) + if jsondataarrerr != nil { + log.Fatalf("Error loading json data from swagger \n: %s", jsondataarrerr) + } - var data map[string]interface{} - if err := json.Unmarshal(jsondataarr, &data); err != nil { - log.Fatalf("Error loading json data to map \n: %s", jsondataarrerr) - log.Fatal(err) - } + var data map[string]interface{} + if err := json.Unmarshal(jsondataarr, &data); err != nil { + log.Fatalf("Error loading json data to map \n: %s", jsondataarrerr) + log.Fatal(err) + } - yamldataarr, yamldataarrerr := yaml.Marshal(&data) - if yamldataarrerr != nil { - log.Fatalf("Error loading json data map to array \n: %s", yamldataarrerr) - } + yamldataarr, yamldataarrerr := yaml.Marshal(&data) + if yamldataarrerr != nil { + log.Fatalf("Error loading json data map to array \n: %s", yamldataarrerr) + } + + err2 := ioutil.WriteFile(filename, yamldataarr, 0755) + if err2 != nil { + log.Fatalf("Error writing provider yaml \n: %s", err2) + } +} - err2 := ioutil.WriteFile(filename, yamldataarr, 0755) - if err2 != nil { - log.Fatalf("Error writing provider yaml \n: %s", err2) - } -} \ No newline at end of file +func copy(srcFile string, targetFile string) error { + data, err := os.ReadFile(srcFile) + if err != nil { + return err + } + err = os.WriteFile(targetFile, data, 0644) + if err != nil { + return err + } + return nil +} + +func generateAndCopySwagger(openApiFileName string, getSwagger fn) { + fmt.Printf("Generating %s...\n", openApiFileName) + swagger, err := getSwagger() + if err == nil { + generateSwaggerYaml(swagger, openApiFileName) + fmt.Printf("Copying %s to %s \n", openApiFileName, smeOpenApiFileLocation + openApiFileName) + copy(openApiFileName, smeOpenApiFileLocation +openApiFileName) + } +} diff --git a/scripts/init/init-sme-spec.bat b/scripts/init/init-sme-spec.bat deleted file mode 100755 index e9ee0b6..0000000 --- a/scripts/init/init-sme-spec.bat +++ /dev/null @@ -1,46 +0,0 @@ -:: ============LICENSE_START=============================================== -:: Copyright (C) 2023 Nordix Foundation. All rights reserved. -:: ======================================================================== -:: Licensed under the Apache License, Version 2.0 (the "License"); -:: you may not use this file except in compliance with the License. -:: You may obtain a copy of the License at -:: -:: http:\\www.apache.org\licenses\LICENSE-2.0 -:: -:: Unless required by applicable law or agreed to in writing, software -:: distributed under the License is distributed on an "AS IS" BASIS, -:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -:: See the License for the specific language governing permissions and -:: limitations under the License. -:: ============LICENSE_END================================================= -:: - -@echo off -set SME_LOCATION="..\sme\capifcore" -set SME_OPENAPI_LOCATION="..\..\openapi\sme" -cp ..\scripts\init\getsmeswagger.go %SME_LOCATION% -cd %SME_LOCATION% - -echo Generating SME openapi spec... - -IF EXIST getsmeswagger.go ( - echo Generating... - go run getsmeswagger.go - - echo Copying generated specs... - mkdir %SME_OPENAPI_LOCATION% - echo Copying CommonData.yaml - mv CommonData.yaml %SME_OPENAPI_LOCATION% - echo Copying TS29122_CommonData.yaml - mv TS29122_CommonData.yaml %SME_OPENAPI_LOCATION% - echo Copying TS29571_CommonData.yaml - mv TS29571_CommonData.yaml %SME_OPENAPI_LOCATION% - echo Copying TS29222_CAPIF_API_Invoker_Management_API.yaml - mv TS29222_CAPIF_API_Invoker_Management_API.yaml %SME_OPENAPI_LOCATION% - echo Copying TS29222_CAPIF_API_Provider_Management_API.yaml - mv TS29222_CAPIF_API_Provider_Management_API.yaml %SME_OPENAPI_LOCATION% - echo Copying TS29222_CAPIF_Publish_Service_API.yaml - mv TS29222_CAPIF_Publish_Service_API.yaml %SME_OPENAPI_LOCATION% -) ELSE ( - echo Unable to find the openapi spec generator. -) diff --git a/scripts/init/init-sme-spec.sh b/scripts/init/init-sme-spec.sh deleted file mode 100755 index ee3e108..0000000 --- a/scripts/init/init-sme-spec.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -# ============LICENSE_START=============================================== -# Copyright (C) 2023 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -SME_LOCATION="../sme/capifcore" -SME_OPENAPI_LOCATION="../../openapi/sme" -cp ../scripts/init/getsmeswagger.go $SME_LOCATION -cd $SME_LOCATION - -echo "Generating SME openapi spec..." - -if [ -f "getsmeswagger.go" ]; then - echo "Generating..." - go run getsmeswagger.go - - echo "Copying generated specs..." - mkdir -p $SME_OPENAPI_LOCATION - echo "Copying CommonData.yaml" - mv CommonData.yaml $SME_OPENAPI_LOCATION - echo "Copying TS29122_CommonData.yaml" - mv TS29122_CommonData.yaml $SME_OPENAPI_LOCATION - echo "Copying TS29571_CommonData.yaml" - mv TS29571_CommonData.yaml $SME_OPENAPI_LOCATION - echo "Copying TS29222_CAPIF_API_Invoker_Management_API.yaml" - mv TS29222_CAPIF_API_Invoker_Management_API.yaml $SME_OPENAPI_LOCATION - echo "Copying TS29222_CAPIF_API_Provider_Management_API.yaml" - mv TS29222_CAPIF_API_Provider_Management_API.yaml $SME_OPENAPI_LOCATION - echo "Copying TS29222_CAPIF_Publish_Service_API.yaml" - mv TS29222_CAPIF_Publish_Service_API.yaml $SME_OPENAPI_LOCATION -else - echo "Unable to find the openapi spec generator." -fi -- 2.16.6