Skip to content

chore: implement test cases for types of References in an OpenApi document #2352

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

MaggieKimani1
Copy link
Contributor

  • Adds test cases for types of references contained in an OpenApi document as covered in this spec
  • Partial - doesn't cover all the cases

@MaggieKimani1 MaggieKimani1 requested a review from a team as a code owner May 14, 2025 08:25
@MaggieKimani1 MaggieKimani1 marked this pull request as draft May 15, 2025 15:54
@MaggieKimani1 MaggieKimani1 marked this pull request as ready for review May 15, 2025 15:54
Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

Here are a couple of comments to help move things along.
What I've done:

  • high level review of the code.
  • review of the samples that are present.

(before reading the spec to come with the freshest eyes possible into that)

What I have not done:

  • check against the spec for missing samples.
  • deep review of the code.

- 'null'
properties:
b:
$ref: '#/properties/b'
Copy link
Member

Choose a reason for hiding this comment

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

This one looks invalid to me.
If I go back up one "schema level", I'm within the b schema definition, (L12), and there's no b property there. Am I reading it wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm getting it the same way, but this is the same example given in the spec and Safia's example.
So in your opinion the JSON pointer should be #/a/properties/b since a has a b property defined within it?

Maybe @darrelmiller can offer more insight?

Copy link
Member

Choose a reason for hiding this comment

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

@MaggieKimani1 @baywet You don't "go back up one schema level". You go back up until you reach a "JSON Schema Resource". This is either a schema with a $Id, the root of the document, or in the case of OpenAPI to the component schema. In this case "a" is the JSON Schema Resource which is effectively the root document as far as JSON Schema is concerned. The label "a" is outside of the JSON Schema Resource which is why it is not part of the $ref.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for clarifying. I made a similar comment on the spec side PR. I think that "routine" should be explicitly called out there as it's not "broadly known"

var propName = pathSegments[0];
if (schema.Properties != null && schema.Properties.TryGetValue(propName, out var propSchema))
return ResolveSubSchema(propSchema, [.. pathSegments.Skip(1)]);
break;
Copy link
Member

Choose a reason for hiding this comment

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

no need for a break after a return

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The break is necessary here to provide a clean exit during execution in case the condition in the if statement doesn't pass

Copy link
Member

Choose a reason for hiding this comment

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

sorry, my earlier comment was unclear. Could you not leverage a when in the case? and clean all of this up in the process?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's wrong with using the current approach?

Copy link
Member

Choose a reason for hiding this comment

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

you can treat that comment as nitpicking. when usually provides better readability IMHO

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
53.3% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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.

3 participants