Clean up URI resolution

rav/ref_objects_in_params
Richard van der Hoff 3 months ago
parent 44db164019
commit 62393f8760

@ -28,19 +28,18 @@ Ref: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#re
{{ $ref_value := index $schema "$ref"}} {{ $ref_value := index $schema "$ref"}}
{{ if $ref_value }} {{ if $ref_value }}
{{ $ref_url := urls.Parse $ref_value }} {{/* Resolve the ref URI relative to the path of the schema file */}}
{{ $base_uri := urls.Parse $path }}
{{ if ne $ref_url.Path "" }} {{ $ref_uri := urls.Parse $ref_value }}
{{/* Reference to a different file: load it */}} {{ $full_uri := $base_uri.ResolveReference $ref_uri }}
{{ $full_path := path.Join $path $ref_url.Path }}
{{ $without_ext := replaceRE "\\.[^\\.]*$" "" $full_path }} {{/* strip the extension, and the leading `/`, from the path */}}
{{ $pieces := split $without_ext "/" }} {{ $full_path := strings.TrimPrefix "/" (replaceRE "\\.[^\\.]*$" "" $full_uri.Path) }}
{{ $ret = index site.Data $pieces }}
{{ else }} {{ $pieces := split $full_path "/" }}
{{ $ret = $root_schema }} {{ $ret = index site.Data $pieces }}
{{ end }}
{{ if ne $ref_url.Fragment "" }} {{ if $ref_uri.Fragment }}
{{/* {{/*
Per https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#relative-references-in-uris: Per https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#relative-references-in-uris:
@ -55,7 +54,7 @@ Ref: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#re
subsequent keys as indexes. subsequent keys as indexes.
*/}} */}}
{{ $keys := split (strings.TrimPrefix "/" $ref_url.Fragment ) "/" }} {{ $keys := split (strings.TrimPrefix "/" $ref_uri.Fragment ) "/" }}
{{ $ret = index $ret $keys }} {{ $ret = index $ret $keys }}
{{ end }} {{ end }}

Loading…
Cancel
Save