kin-openapi
kin-openapi copied to clipboard
LoadFromFile sorts the refrenced schema in alphabetical order
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
}
Looks like whole parsed schema is being sorted alphabetically. Any help here ?
This is a duplicate of https://github.com/getkin/kin-openapi/issues/645