getkin / kin-openapi

OpenAPI 3.0 (and Swagger v2) implementation for Go (parsing, converting, validation, and more)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Data object "API" broken moving from 0.118.0 to 0.124.0

andrewrowe-wk opened this issue · comments

Hello! Great library and very useful for me and my team. Thank you for taking the time to write and maintain it.

When updating from 0.118.0 to 0.124.0 some of our consuming code broke and I am looking for the correct remediation. For example we had some code that looked like the following:

func getType(p *openapi3.Parameter) string {
	return p.Schema.Value.Type
}

This is no longer valid with the new structure of the Schema object. When investigating, I found I could do something like this:

func getType(p *openapi3.Parameter) string {
	return p.Schema.Value.Type.Slice()[0]
}

I don't know if getting the Type at index 0 is correct, but looking at the MarshalYaml() makes me think that's the right thing to do. I see JSON schemas supports multiple types. I did not realize this. The schemas we are parsing, for now, only use a single type.

I think that's correct because Type.Is uses the type at index 0 as well. At least that's what I've been using in my PR at metio/terraform-provider-k8s#120 to update to the latest version.

commented

@andrewrowe-wk I believe it should be OK for you to take the first item of the slice. I think this issue can be closed