Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "IsReference/GetReference" for all types in components #389

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

vkd
Copy link
Contributor

@vkd vkd commented Mar 9, 2025

I've found that methods IsReference() and GetReference() don't work as expected for all component's types except schemas.

Affected version: v0.21.8 d3dcac4e5f6f13b0c3afa736e0d449a9abe9c811.

Code example:

import (
	"github.com/pb33f/libopenapi"
	v3 "github.com/pb33f/libopenapi/datamodel/high/v3"
)

func xxx() {
	doc, _ := libopenapi.NewDocument(specRaw)
	v3Model, _ := doc.BuildV3Model()
	
	var components *v3.Components = v3Model.Model.Components
	for _, v := range components.Responses.FromOldest() {
		v.GoLow().IsReference()  // false for all objects
		v.GoLow().GetReference() // "" for all objects
	}
}

Configuration example:

components:
  responses:
    A1:
      description: "a1"
      content:
        application/json:
          schema:
            type: object
    A2:
      $ref: "#/components/responses/A1"
    A3:
      $ref: "#/components/responses/A2"

Questions:

  • datamodel/low/v3/components.go: is there anything missing or what exactly that code is doing? All unit tests are passed, but maybe I miss something.
  • datamodel/low/v3/create_document_test.go: should I adjust this test check into something else?

Copy link

codecov bot commented Mar 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.61%. Comparing base (d3dcac4) to head (c5d5771).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #389      +/-   ##
==========================================
+ Coverage   99.55%   99.61%   +0.06%     
==========================================
  Files         165      165              
  Lines       21606    21621      +15     
==========================================
+ Hits        21509    21537      +28     
+ Misses         92       79      -13     
  Partials        5        5              
Flag Coverage Δ
unittests 99.61% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Verified

This commit was signed with the committer’s verified signature.
vkd Dmitry Kutakov
@vkd vkd force-pushed the fix_is_reference_components branch from 4a83f41 to c5d5771 Compare March 9, 2025 12:34
Copy link
Member

@daveshanley daveshanley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I appreciate it.

@daveshanley daveshanley merged commit 0af9c35 into pb33f:main Mar 13, 2025
4 checks passed
@vkd vkd deleted the fix_is_reference_components branch March 14, 2025 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants