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

Rolodex.Resolve() doesn't override the description from #ref definition #262

Open
mlsmaycon opened this issue Feb 28, 2024 · 6 comments
Open
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@mlsmaycon
Copy link

mlsmaycon commented Feb 28, 2024

Hello, it seems like the Rolodex.Resolve() method doesn't override the description from #ref definition and resolving all refs.

I have the following spec example:

openapi: 3.1.0
info:
  title: Example
  version: 0.0.1
components:
  schemas:
    OSVersionCheck:
      description: Posture check for the version of operating system
      type: object
      properties:
        android:
          description: Minimum version of Android
          $ref: '#/components/schemas/MinVersionCheck'
      example:
        android:
          min_version: "13"
    MinVersionCheck:
      description: Posture check for the version of operating system
      type: object
      properties:
        min_version:
          description: Minimum acceptable version
          type: string
          example: "14.3"
      required:
        - min_version

After outputting the result I got this:

openapi: 3.1.0
info:
    title: Example
    version: 0.0.1
components:
    schemas:
        OSVersionCheck:
            description: Posture check for the version of operating system
            type: object
            properties:
                android:
                    description: Posture check for the version of operating system
                    type: object
                    properties:
                        min_version:
                            description: Minimum acceptable version
                            type: string
                            example: "14.3"
                    required:
                        - min_version
            example:
                android:
                    min_version: "13"
        MinVersionCheck:
            description: Posture check for the version of operating system
            type: object
            properties:
                min_version:
                    description: Minimum acceptable version
                    type: string
                    example: "14.3"
            required:
                - min_version

The expected output is:

...
                android:
                    description: Minimum version of Android
                    type: object
                    properties:
                        min_version:
                            description: Minimum acceptable version
                            type: string
                            example: "14.3"
                    required:
                        - min_version
...

This is the code I am using:

package main

import (
	"io/ioutil"
	"os"

	"github.com/pb33f/libopenapi/index"
	"gopkg.in/yaml.v3"
)

func main() {

	inFile, _ := ioutil.ReadFile("in.yml")

	var rootNode yaml.Node
	_ = yaml.Unmarshal(inFile, &rootNode)

	indexConfig := index.CreateClosedAPIIndexConfig()

	rolodex := index.NewRolodex(indexConfig)

	rolodex.SetRootNode(&rootNode)

	indexedErr := rolodex.IndexTheRolodex()
	if indexedErr != nil {
		panic(indexedErr)
	}

	rolodex.Resolve()

	node := rolodex.GetRootNode()

	b, e := yaml.Marshal(node)
	if e != nil {
		panic(e)
	}

	var newNode yaml.Node
	_ = yaml.Unmarshal(b, &newNode)

	os.WriteFile("out.yml", b, 0644)

}
@daveshanley
Copy link
Member

There is a known bug in the resolver that appears haphazardly when resolving async extracted refs (which is the default).

The solution (until the root cause is fixed). Is to extract references synchronously by setting the ExtractRefsSequentially boolean to true on your indexConfig

https://github.com/pb33f/libopenapi/blob/main/index/index_model.go#L149

@mlsmaycon
Copy link
Author

Hi @daveshanley, thanks for responding. I've tried the configuration, but it didn't work.

@daveshanley
Copy link
Member

Oh, sorry, I mis-read your problem.

The result you have is the expected outcome of how the resolver works. It's not performing any kind of property merging or overriding, it's simply resolving the references, literally by re-pointing the underlying node tree. It's resolving like a compiler resolves pointers, it is not going to deliver what you're looking for.

This would be a new feature.

@mlsmaycon
Copy link
Author

Got it, thanks for the feedback.

Ok, I thought it was a bug because of the way it was defined in the 3.1 Reference Object documentation.

Do you want me to open another issue as a feature request?

@daveshanley
Copy link
Member

yes please!

@daveshanley daveshanley added documentation Improvements or additions to documentation enhancement New feature or request labels Mar 6, 2024
@TristanSpeakEasy
Copy link
Contributor

This is somewhat related to this issue #90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants