Skip to content

An openapi "client" is failing to decode json-pointer-encoded strings #576

@ericpromislow

Description

@ericpromislow

A user of an extension for Rancher was reporting that it was showing in the Rancher UI as installed, but wasn't returning
any output. Rancher uses a module called steve as a shim between the UI and a kubernetes server.

During startup. after I installed the component, I saw that steve was failing to load all the schemas, specifically with the error message

SchemaError(github.com/kubewarden/sbomscanner/api/storage/v1alpha1.ContainerRef.imageRef):
   unknown model in reference: "github.com~1kubewarden~1sbomscanner~1api~1storage~1v1alpha1.ImageRef"

There is a model for github.com/kubewarden/sbomscanner/api/storage/v1alpha1.ContainerRef.imageRef in the definitions section of the openapi/v2 doc that this code uses, but not one with the tildes.

Today I learned about json-pointer, which makes sense. Otherwise a ref string like "definitions/github.com/kubewarden/sbomscanner/api/storage/v1alpha1.ContainerRef.imageRef" would be ambiguous: is it pointing first at the top-level definitions section, then a sub-section called "github.com", etc.?

Openapi/v2 clients deal with this by decoding these reference strings, converting instances of ~1 to / and ~0 to ~.

The code at

reference := strings.TrimPrefix(s.GetXRef(), "#/definitions/")
if _, ok := d.models[reference]; !ok {
return nil, newSchemaError(path, "unknown model in reference: %q", reference)
}
isn't doing that -- it's taking reference strings and trying to use them immediately as keys into the definitions section.

PR coming up...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions