MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / valueWithPropagatedRef

Function valueWithPropagatedRef

pkg/codegen/merge_schemas.go:157–174  ·  view source on GitHub ↗

valueWithPropagatedRef returns a copy of ref's schema with its Properties refs rewritten when ref itself is external, and with extensions placed next to the $ref folded in (ref-side wins over value-side). This is what allows allOf members to carry per-use sibling directives without mutating the refe

(ref *openapi3.SchemaRef)

Source from the content-addressed store, hash-verified

155// allows allOf members to carry per-use sibling directives without
156// mutating the referenced schema.
157func valueWithPropagatedRef(ref *openapi3.SchemaRef) (openapi3.Schema, error) {
158 schema := *ref.Value
159 schema.Extensions = combinedSchemaExtensions(ref)
160
161 if len(ref.Ref) == 0 || ref.Ref[0] == '#' {
162 return schema, nil
163 }
164
165 pathParts := strings.Split(ref.Ref, "#")
166 if len(pathParts) < 1 || len(pathParts) > 2 {
167 return openapi3.Schema{}, fmt.Errorf("unsupported reference: %s", ref.Ref)
168 }
169 remoteComponent := pathParts[0]
170
171 propagateRemoteRefs(remoteComponent, &schema)
172
173 return schema, nil
174}
175
176// propagateRemoteRefs rewrites local "#/..." refs within a schema to be
177// qualified with the remote component path. This is needed so that when an

Callers 2

mergeSchemasFunction · 0.85
mergeAllOfFunction · 0.85

Calls 2

combinedSchemaExtensionsFunction · 0.85
propagateRemoteRefsFunction · 0.85

Tested by

no test coverage detected