propagateRemoteRefs rewrites local "#/..." refs within a schema to be qualified with the remote component path. This is needed so that when an external schema is flattened via allOf, nested type references (array items, additionalProperties, sub-object properties) retain their external qualification
(remoteComponent string, schema *openapi3.Schema)
| 179 | // additionalProperties, sub-object properties) retain their external |
| 180 | // qualification. See https://github.com/oapi-codegen/oapi-codegen/issues/2288 |
| 181 | func propagateRemoteRefs(remoteComponent string, schema *openapi3.Schema) { |
| 182 | for _, value := range schema.Properties { |
| 183 | if len(value.Ref) > 0 && value.Ref[0] == '#' { |
| 184 | value.Ref = remoteComponent + value.Ref |
| 185 | } else if value.Value != nil { |
| 186 | propagateRemoteRefs(remoteComponent, value.Value) |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | if schema.Items != nil { |
| 191 | if len(schema.Items.Ref) > 0 && schema.Items.Ref[0] == '#' { |
| 192 | schema.Items.Ref = remoteComponent + schema.Items.Ref |
| 193 | } else if schema.Items.Value != nil { |
| 194 | propagateRemoteRefs(remoteComponent, schema.Items.Value) |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | if schema.AdditionalProperties.Schema != nil { |
| 199 | ap := schema.AdditionalProperties.Schema |
| 200 | if len(ap.Ref) > 0 && ap.Ref[0] == '#' { |
| 201 | ap.Ref = remoteComponent + ap.Ref |
| 202 | } else if ap.Value != nil { |
| 203 | propagateRemoteRefs(remoteComponent, ap.Value) |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | for _, list := range [][]*openapi3.SchemaRef{schema.AllOf, schema.AnyOf, schema.OneOf} { |
| 208 | for _, ref := range list { |
| 209 | if len(ref.Ref) > 0 && ref.Ref[0] == '#' { |
| 210 | ref.Ref = remoteComponent + ref.Ref |
| 211 | } else if ref.Value != nil { |
| 212 | propagateRemoteRefs(remoteComponent, ref.Value) |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | if schema.Not != nil { |
| 218 | if len(schema.Not.Ref) > 0 && schema.Not.Ref[0] == '#' { |
| 219 | schema.Not.Ref = remoteComponent + schema.Not.Ref |
| 220 | } else if schema.Not.Value != nil { |
| 221 | propagateRemoteRefs(remoteComponent, schema.Not.Value) |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | func mergeAllOf(allOf []*openapi3.SchemaRef, seenSchemaRef map[string]bool) (openapi3.Schema, error) { |
| 227 | var schema openapi3.Schema |
no outgoing calls
no test coverage detected