Skip to content

Commit 3785db7

Browse files
committed
updated the readme, and coverage.
made a choice and reduced the code footprint
1 parent 37b2f5b commit 3785db7

File tree

3 files changed

+58
-23
lines changed

3 files changed

+58
-23
lines changed

README.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,6 @@ like our _very kind_ sponsors:
4949

5050
---
5151

52-
`libopenapi` is kinda new, so our list of notable projects that depend on `libopenapi` is small (let me know if you'd like to add your project)
53-
54-
- [github.com/daveshanley/vacuum](https://github.com/daveshanley/vacuum) - "The world's fastest and most scalable OpenAPI/Swagger linter/quality tool"
55-
- [github.com/pb33f/openapi-changes](https://github.com/pb33f/openapi-changes) - "The world's **sexiest** OpenAPI breaking changes detector"
56-
- [github.com/pb33f/wiretap](https://github.com/pb33f/wiretap) - "The world's **coolest** OpenAPI compliance analysis tool"
57-
- [github.com/danielgtaylor/restish](https://github.com/danielgtaylor/restish) - "Restish is a CLI for interacting with REST-ish HTTP APIs"
58-
- [github.com/speakeasy-api/speakeasy](https://github.com/speakeasy-api/speakeasy) - "Speakeasy CLI makes validating OpenAPI docs and generating idiomatic SDKs easy!"
59-
- [github.com/apicat/apicat](https://github.com/apicat/apicat) - "AI-powered API development tool"
60-
- [github.com/mattermost/mattermost](https://github.com/mattermost/mattermost) - "Software development lifecycle platform"
61-
- [github.com/gopher-fleece/gleece](https://github.com/gopher-fleece/gleece) - "Building and documenting REST APIs through code-first development"
62-
- Your project here?
63-
---
64-
6552
## Come chat with us
6653

6754
Need help? Have a question? Want to share your work? [Join our discord](https://discord.gg/x7VACVuEGP) and
@@ -90,6 +77,7 @@ See all the documentation at https://pb33f.io/libopenapi/
9077
- [Circular References](https://pb33f.io/libopenapi/circular-references/)
9178
- [Bundling Specs](https://pb33f.io/libopenapi/bundling/)
9279
- [What Changed / Diff Engine](https://pb33f.io/libopenapi/what-changed/)
80+
- [Overlays](https://pb33f.io/libopenapi/overlays/)
9381
- [FAQ](https://pb33f.io/libopenapi/faq/)
9482
- [About libopenapi](https://pb33f.io/libopenapi/about/)
9583
---

datamodel/low/overlay/overlay.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,12 @@ func (o *Overlay) Build(ctx context.Context, keyNode, root *yaml.Node, idx *inde
7676
o.Info = info
7777

7878
// Extract actions array
79-
actions, err := o.extractActions(ctx, root, idx)
80-
if err != nil {
81-
return err
82-
}
83-
o.Actions = actions
79+
o.Actions = o.extractActions(ctx, root, idx)
8480

8581
return nil
8682
}
8783

88-
func (o *Overlay) extractActions(ctx context.Context, root *yaml.Node, idx *index.SpecIndex) (low.NodeReference[[]low.ValueReference[*Action]], error) {
84+
func (o *Overlay) extractActions(ctx context.Context, root *yaml.Node, idx *index.SpecIndex) low.NodeReference[[]low.ValueReference[*Action]] {
8985
var result low.NodeReference[[]low.ValueReference[*Action]]
9086

9187
for i := 0; i < len(root.Content); i += 2 {
@@ -107,9 +103,7 @@ func (o *Overlay) extractActions(ctx context.Context, root *yaml.Node, idx *inde
107103
for _, actionNode := range value.Content {
108104
action := &Action{}
109105
_ = low.BuildModel(actionNode, action)
110-
if err := action.Build(ctx, nil, actionNode, idx); err != nil {
111-
return result, err
112-
}
106+
_ = action.Build(ctx, nil, actionNode, idx)
113107
actions = append(actions, low.ValueReference[*Action]{
114108
Value: action,
115109
ValueNode: actionNode,
@@ -119,7 +113,7 @@ func (o *Overlay) extractActions(ctx context.Context, root *yaml.Node, idx *inde
119113
break
120114
}
121115
}
122-
return result, nil
116+
return result
123117
}
124118

125119
// GetExtensions returns all Overlay extensions and satisfies the low.HasExtensions interface.

datamodel/low/overlay/overlay_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,56 @@ x-custom: value`
382382
hash := overlay.Hash()
383383
assert.NotEqual(t, [32]byte{}, hash)
384384
}
385+
386+
// TestOverlay_Build_InfoEmptyRef tests line 74 - error from ExtractObject when info has empty $ref
387+
func TestOverlay_Build_InfoEmptyRef(t *testing.T) {
388+
yml := `overlay: 1.0.0
389+
info:
390+
$ref: ""`
391+
392+
var node yaml.Node
393+
err := yaml.Unmarshal([]byte(yml), &node)
394+
require.NoError(t, err)
395+
396+
var overlay Overlay
397+
err = low.BuildModel(node.Content[0], &overlay)
398+
require.NoError(t, err)
399+
400+
err = overlay.Build(context.Background(), nil, node.Content[0], nil)
401+
require.Error(t, err)
402+
assert.Contains(t, err.Error(), "object extraction failed")
403+
assert.Contains(t, err.Error(), "empty")
404+
}
405+
406+
// TestOverlay_Build_OddContentLengthExtractActions tests line 93 - break on odd content length
407+
func TestOverlay_Build_OddContentLengthExtractActions(t *testing.T) {
408+
// Create an overlay WITHOUT actions - so extractActions iterates through all content
409+
yml := `overlay: 1.0.0
410+
info:
411+
title: Test
412+
version: 1.0.0`
413+
414+
var node yaml.Node
415+
err := yaml.Unmarshal([]byte(yml), &node)
416+
require.NoError(t, err)
417+
418+
// Manually corrupt the root node to have odd number of content elements
419+
// This simulates a malformed YAML structure that extractActions must handle
420+
root := node.Content[0]
421+
// Root content is: [overlay, "1.0.0", info, {...}] - 4 elements (even)
422+
// Add an orphan key to make it 5 elements (odd)
423+
root.Content = append(root.Content, &yaml.Node{
424+
Kind: yaml.ScalarNode,
425+
Value: "orphan-key",
426+
})
427+
428+
var overlay Overlay
429+
err = low.BuildModel(root, &overlay)
430+
require.NoError(t, err)
431+
432+
// This should trigger the break at line 93 due to odd content length
433+
// The loop will iterate: i=0 (overlay), i=2 (info), i=4 (orphan-key)
434+
// At i=4, i+1=5 >= len(Content)=5, so break is executed
435+
err = overlay.Build(context.Background(), nil, root, nil)
436+
require.NoError(t, err) // Build should succeed, just skip the odd element
437+
}

0 commit comments

Comments
 (0)