Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bundler/bundler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ func TestBundleDocument_BundleBytesComposed_NestedFiles(t *testing.T) {
AllowFileReferences: true,
BasePath: "../test_specs/nested_files",
ExtractRefsSequentially: true,
Logger: slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
})),
}

bundledBytes, e := BundleBytesComposed(specBytes, config, nil)
Expand Down
12 changes: 11 additions & 1 deletion index/find_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,17 @@ func FindComponent(_ context.Context, root *yaml.Node, componentId, absoluteFile
friendlySearch = "$"
}
path, err := jsonpath.NewPath(friendlySearch, jsonpathconfig.WithPropertyNameExtension())
if path == nil || err != nil || root == nil {
if err != nil {
index.logger.Warn("[FindComponent] error creating JSON path",
"absoluteFilePath", absoluteFilePath,
"componentId", componentId,
"name", name,
"friendlySearch", friendlySearch,
"error", err.Error(),
)
return nil
}
if path == nil || root == nil {
return nil // no component found
}
res := path.Query(root)
Expand Down
20 changes: 20 additions & 0 deletions test_specs/nested_files/components/responses/4xxClientErrors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
400_unexpected_request_body:
description: Unexpected request body provided.
content:
application/json:
schema:
additionalProperties: false
properties:
message:
type: string
default: Unexpected request body provided.
403_permission_denied:
description: None or insufficient credentials provided.
content:
application/json:
schema:
additionalProperties: false
properties:
message:
type: string
default: Permission denied.
30 changes: 30 additions & 0 deletions test_specs/nested_files/openapi-bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ components:
responses:
"200":
$ref: '#/components/responses/Unspecified200'
"403":
description: None or insufficient credentials provided.
content:
application/json:
schema:
additionalProperties: false
properties:
message:
type: string
default: Permission denied.
put:
summary: TODO
description: TODO
Expand All @@ -166,3 +176,23 @@ components:
responses:
"200":
$ref: '#/components/responses/Unspecified200'
"400":
description: Unexpected request body provided.
content:
application/json:
schema:
additionalProperties: false
properties:
message:
type: string
default: Unexpected request body provided.
"403":
description: None or insufficient credentials provided.
content:
application/json:
schema:
additionalProperties: false
properties:
message:
type: string
default: Permission denied.
7 changes: 6 additions & 1 deletion test_specs/nested_files/paths/v1_Accounts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ post:
responses:
"200":
$ref: ../components/responses/Unspecified200.yaml

"403":
$ref: '../components/responses/4xxClientErrors.yaml#/403_permission_denied'
put:
summary: TODO
description: TODO
Expand All @@ -40,3 +41,7 @@ put:
responses:
"200":
$ref: ../components/responses/Unspecified200.yaml
"400":
$ref: '../components/responses/4xxClientErrors.yaml#/400_unexpected_request_body'
"403":
$ref: '../components/responses/4xxClientErrors.yaml#/403_permission_denied'
12 changes: 12 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,18 @@ func ConvertComponentIdIntoFriendlyPathSearch(id string) (string, string) {
continue
}

// If segment starts with a number
if len(segs[i]) > 0 && segs[i][0] >= '0' && segs[i][0] <= '9' {
var pluralBuilder strings.Builder
pluralBuilder.Grow(len(segs[i]) + 4)
pluralBuilder.WriteString("['")
pluralBuilder.WriteString(segs[i])
pluralBuilder.WriteString("']")
segs[i] = pluralBuilder.String()
cleaned = append(cleaned, segs[i])
continue
}

// if we have a plural parent, wrap it in quotes.
if i > 0 && segs[i-1] != "" && segs[i-1][len(segs[i-1])-1] == 's' {
if i == 2 { // ignore first segment.
Expand Down