Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference resolve issue for 3GPP Rel.16 definitions #638

Closed
ShouheiNishi opened this issue Oct 18, 2022 · 1 comment · Fixed by #700
Closed

Reference resolve issue for 3GPP Rel.16 definitions #638

ShouheiNishi opened this issue Oct 18, 2022 · 1 comment · Fixed by #700

Comments

@ShouheiNishi
Copy link
Contributor

We are trying to generate code with the oapi-codegen from the 3GPP Rel.16 openapi definition .yaml file, but the reference resolution fails in the kin-openapi loader and the file cannot be loaded.

We use these files. All files are got from 3GPP webpage.
But encode of TS29544_Nspaf_SecuredPacket.yaml is fixed by hand.
The file from which the import is started is TS29571_CommonData.yaml.

TS28623_GenericNrm.yaml
TS28623_comDefs.yaml
TS29122_AsSessionWithQoS.yaml
TS29122_ChargeableParty.yaml
TS29122_CommonData.yaml
TS29122_CpProvisioning.yaml
TS29122_DeviceTriggering.yaml
TS29122_ECRControl.yaml
TS29122_GMDviaMBMSbyMB2.yaml
TS29122_GMDviaMBMSbyxMB.yaml
TS29122_MonitoringEvent.yaml
TS29122_MsisdnLessMoSms.yaml
TS29122_NIDD.yaml
TS29122_NpConfiguration.yaml
TS29122_PfdManagement.yaml
TS29122_RacsParameterProvisioning.yaml
TS29122_ReportingNetworkStatus.yaml
TS29122_ResourceManagementOfBdt.yaml
TS29502_Nsmf_PDUSession.yaml
TS29503_Nudm_EE.yaml
TS29503_Nudm_MT.yaml
TS29503_Nudm_NIDDAU.yaml
TS29503_Nudm_PP.yaml
TS29503_Nudm_SDM.yaml
TS29503_Nudm_UEAU.yaml
TS29503_Nudm_UECM.yaml
TS29505_Subscription_Data.yaml
TS29507_Npcf_AMPolicyControl.yaml
TS29508_Nsmf_EventExposure.yaml
TS29509_Nausf_SoRProtection.yaml
TS29509_Nausf_UEAuthentication.yaml
TS29509_Nausf_UPUProtection.yaml
TS29510_Nnrf_AccessToken.yaml
TS29510_Nnrf_Bootstrapping.yaml
TS29510_Nnrf_NFDiscovery.yaml
TS29510_Nnrf_NFManagement.yaml
TS29512_Npcf_SMPolicyControl.yaml
TS29514_Npcf_PolicyAuthorization.yaml
TS29517_Naf_EventExposure.yaml
TS29518_Namf_Communication.yaml
TS29518_Namf_EventExposure.yaml
TS29518_Namf_Location.yaml
TS29518_Namf_MT.yaml
TS29519_Application_Data.yaml
TS29519_Exposure_Data.yaml
TS29519_Policy_Data.yaml
TS29520_Nnwdaf_AnalyticsInfo.yaml
TS29520_Nnwdaf_EventsSubscription.yaml
TS29522_5GLANParameterProvision.yaml
TS29522_ACSParameterProvision.yaml
TS29522_AnalyticsExposure.yaml
TS29522_ApplyingBdtPolicy.yaml
TS29522_IPTVConfiguration.yaml
TS29522_LpiParameterProvision.yaml
TS29522_MoLcsNotify.yaml
TS29522_NIDDConfigurationTrigger.yaml
TS29522_ServiceParameter.yaml
TS29522_TrafficInfluence.yaml
TS29523_Npcf_EventExposure.yaml
TS29531_Nnssf_NSSAIAvailability.yaml
TS29531_Nnssf_NSSelection.yaml
TS29544_Nspaf_SecuredPacket.yaml
TS29554_Npcf_BDTPolicyControl.yaml
TS29571_CommonData.yaml
TS29572_Nlmf_Broadcast.yaml
TS29572_Nlmf_Location.yaml
TS32291_Nchf_ConvergedCharging.yaml
TS32291_Nchf_OfflineOnlyCharging.yaml

The error message is here.

error loading swagger spec in lib/openapi/Rel16/yaml/TS29571_CommonData.yaml
: error resolving reference "TS29510_Nnrf_AccessToken.yaml#/components/schemas/AccessTokenReq": error resolving reference "TS29510_Nnrf_NFManagement.yaml#/components/schemas/NFType": error resolving reference "TS29518_Namf_Communication.yaml#/components/schemas/N2InformationClass": error resolving reference "TS29518_Namf_EventExposure.yaml#/components/schemas/AmfEventSubscription": error resolving reference "TS29503_Nudm_EE.yaml#/components/schemas/ReferenceId": error resolving reference "TS29503_Nudm_SDM.yaml#/components/schemas/ContextInfo": error resolving reference "TS29503_Nudm_PP.yaml#/components/schemas/PlmnEcInfo": error resolving reference "TS29572_Nlmf_Location.yaml#/components/schemas/CivicAddress": failed to resolve "ProblemDetails" in fragment in URI: "#/components/schemas/ProblemDetails": map key "ProblemDetails" not found

We analyze loader code. We found some issues.
The arguments 'doc’ and 'path’ of the function 'resolveComponent’ in 'loader.go’ is sometimes incorrect. In such case, resolving reference is failed.
In the function 'resolveSchemaRef’, the aregumnt 'doc’ for recursive call of 'resolveSchemaRef’ must be use a value that points to the referenced document.
In these code

			var resolved SchemaRef
			componentPath, err := loader.resolveComponent(doc, ref, documentPath, &resolved)
			if err != nil {
				return err
			}
			if err := loader.resolveSchemaRef(doc, &resolved, componentPath, visited); err != nil {
				return err
			}
			component.Value = resolved.Value
			return nil
			foundPath := loader.getResolvedRefPath(ref, &resolved, documentPath, componentPath)
			documentPath = loader.documentPathForRecursiveRef(documentPath, foundPath)

We think that there should be no processing after updating the value of 'component.value' and should return to the calling function immediately.

The attached diff seems to resolve the issue, but I am not sure about the validity.
In addition, we could not generate the smallest pattern to reproduction this issue.

test-fix.diff.gz

@ShouheiNishi
Copy link
Contributor Author

We wrote test code for the variable `doc’ handling problem.

openapi3/issue638_test.go

package openapi3

import (
        "testing"

        "github.com/stretchr/testify/require"
)

func TestIssue638(t *testing.T) {
        for i := 0; i < 50; i++ {
                loader := NewLoader()
                loader.IsExternalRefsAllowed = true
                doc, err := loader.LoadFromFile("../openapi3/testdata/issue638/test1.yaml")
                require.NoError(t, err)
                require.Equal(t, "int", doc.Components.Schemas["test1d"].Value.Type)
        }
}

openapi3/testdata/issue638/test1.yaml

openapi: "3.0.0"
info:
  version: 1.0.0
  title: reference test part 1
  description: reference test part 1
components:
  schemas:
    test1a:
      $ref: "test2.yaml#/components/schemas/test2a"
    test1b:
      $ref: "#/components/schemas/test1c"
    test1c:
      type: int
    test1d:
      $ref: "test2.yaml#/components/schemas/test2b"

openapi3/testdata/issue638/test2.yaml

openapi: "3.0.0"
info:
  version: 1.0.0
  title: reference test part 2
  description: reference test part 2
components:
  schemas:
    test2a:
      type: number
    test2b:
      $ref: "test1.yaml#/components/schemas/test1b"
    test1c:
      type: string

Result

=== RUN   TestIssue638
    issue638_test.go:15:
                Error Trace:    /home/nishi/free5gc-deb/free5gc/lib/kin-openapi/openapi3/issue638_test.go:15
                Error:          Not equal:
                                expected: "int"
                                actual  : "string"

                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -int
                                +string
                Test:           TestIssue638
--- FAIL: TestIssue638 (0.00s)
FAIL
FAIL    github.com/getkin/kin-openapi/openapi3  0.011s
FAIL

I couldn't reproduce the problem unless the pathname in the argument of the function LoadFromFile is in this format.
The patch in first comment fixes this issue.

ShouheiNishi added a commit to ShouheiNishi/kin-openapi that referenced this issue Dec 13, 2022
@fenollp fenollp linked a pull request Dec 13, 2022 that will close this issue
ShouheiNishi added a commit to ShouheiNishi/kin-openapi that referenced this issue Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant