kin-openapi icon indicating copy to clipboard operation
kin-openapi copied to clipboard

LoadFromFile sorts the refrenced schema in alphabetical order

Open sheikhasim opened this issue 1 year ago • 1 comments
trafficstars

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 avatar Mar 26 '24 04:03 sheikhasim

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

sheikhasim avatar Mar 26 '24 06:03 sheikhasim

This is a duplicate of https://github.com/getkin/kin-openapi/issues/645

AnatolyRugalev avatar Jul 04 '24 12:07 AnatolyRugalev