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

LoadFromFile sorts the refrenced schema in alphabetical order #926

Closed
sheikhasim opened this issue Mar 26, 2024 · 2 comments
Closed

LoadFromFile sorts the refrenced schema in alphabetical order #926

sheikhasim opened this issue Mar 26, 2024 · 2 comments

Comments

@sheikhasim
Copy link

sheikhasim commented Mar 26, 2024

I have a multi directory schema structure and using $ref to refrence in respective files.
Then i'm using the openapi3 loader to load the parent spec and using internalizeRefs to resolve $ref s.
While this works fine but the schema parameters are getting sorted in alphabetical order in the parsed schema.
example:

defined schema: 
User:
  type: object
        properties:
          username:
            type: string
          first_name:
            type: string
          last_name:
            type: string
          email:
            type: string
            format: email
          enabled:
            type: boolean
          roles:
            type: array
            items:
              $ref: "#/userRole"
          attribute_key:
            type: string`
Parsed schema : 
  User:
        properties:
          attribute_key:
            type: string
          email:
            format: email
            type: string
          enabled:
            type: boolean
          first_name:
            type: string
          last_name:
            type: string
          roles:
            items:
              $ref: '#/components/schemas/userRole'
            type: array
          username:
            type: string
func LoadOpenAPISpec(version string) (*openapi3.T, error) {

	loader := openapi3.NewLoader()
	loader.IsExternalRefsAllowed = true
	mainSpecPath := fmt.Sprintf(mainSpecPath, version)
	mainSpec, err := loader.LoadFromFile(mainSpecPath)
	if err != nil {
		return nil, err
	}

	mainSpec.InternalizeRefs(context.Background(), nil)
	println("loaded")

	return mainSpec, nil
}
@sheikhasim
Copy link
Author

Looks like whole parsed schema is being sorted alphabetically.
Any help here ?

@sheikhasim sheikhasim changed the title InternalizeRefs sorts the refrenced schema in alphabetical order LoadFromfile sorts the refrenced schema in alphabetical order Mar 26, 2024
@sheikhasim sheikhasim changed the title LoadFromfile sorts the refrenced schema in alphabetical order LoadFromFile sorts the refrenced schema in alphabetical order Mar 26, 2024
@AnatolyRugalev
Copy link
Contributor

This is a duplicate of #645

@fenollp fenollp closed this as completed Jul 5, 2024
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

No branches or pull requests

3 participants