Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Gregsdennis/improve scopes #1588

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

Merged
gregsdennis merged 4 commits into main from gregsdennis/improve-scopes
Apr 26, 2025
Merged

Gregsdennis/improve scopes #1588

gregsdennis merged 4 commits into main from gregsdennis/improve-scopes
Apr 26, 2025

Conversation

Copy link
Member

@gregsdennis gregsdennis commented Feb 25, 2025

What kind of change does this PR introduce?

clarification

Issue & Discussion References

Summary

Improve readability, definitions, and explanations of lexical and dynamic scopes.

Does this PR introduce a breaking change?

No.

There is a MUST requirement that was previously listed as undefined behavior before, but this MUST was stated in the scopes section anyway. It's just now MUST in both places.

@gregsdennis gregsdennis requested a review from a team February 25, 2025 05:31
@gregsdennis gregsdennis added this to the stable-release milestone Feb 25, 2025
Copy link
Member Author

I still have some work to do here for $dynamic*, but I'm going to wait until #1589 is done so I can rebase on that.

Copy link
Member Author

Just did a close/open to rekick the build. It had been a while and couldn't do it manually.

@gregsdennis gregsdennis moved this from Done to In Progress in Stable Release Development Apr 12, 2025
@gregsdennis gregsdennis marked this pull request as ready for review April 12, 2025 01:28
Copy link
Member Author

Reviewed the changes in #1589, and they seem to align with the rest of what I've updated here, so I'm going to leave $dynamic* as it is.

@gregsdennis gregsdennis force-pushed the gregsdennis/improve-scopes branch from 8f29265 to 767debd Compare April 12, 2025 02:05
Copy link
Member

@jdesrosiers jdesrosiers left a comment

Choose a reason for hiding this comment

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

This is an improvement, but I still really dislike the way dynamic scope is defined. I think it should be the stack of schema resources and not include subschemas. The extra complexity makes learning how dynamic references work more complicated.

Also, I desperately hope we wouldn't ever add another keyword that uses dynamic scope. My preference would be to remove this whole concept from the spec and address it only in the context of dynamic references and recommend that extension keywords not use dynamic scope.

All of that can be debated elsewhere and done as a follow up if there's consensus.

Copy link
Member

karenetheridge commented Apr 13, 2025
edited
Loading

...I still really dislike the way dynamic scope is defined. I think it should be the stack of schema resources and not include subschemas.

I agree, and this is already how we define dynamic scope (unless you're intending to change that?) -- we say elsewhere in the spec, when processing $dynamicRef [emphasis mine], "...the initial URI MUST be replaced by the URI (including the fragment) for the outermost schema resource in the dynamic scope that defines an identically named fragment with "$dynamicAnchor".

Therefore, in my implementation, the current URI is pushed to the dynamic_scope stack (the array that is searched when processing $dynamicRef) only when processing the $id keyword, not for every subschema.

I can't see any usecases for wanting other, non-resource, subschemas to be stored in the dynamic scope.

Copy link
Member Author

I've updated to use resources. (This is actually what we agreed on when @jviotti was writing his posts on scopes.)

It does raise one question, though: what if evaluation starts at a subschema? I suppose the dynamic scope is still the resource, but the evaluation path would still start from the subschema? This is how I have it now, and I could change it if we decide something else.

I desperately hope we wouldn't ever add another keyword that uses dynamic scope. - @jdesrosiers

I don't know. I think if explained properly (which is what this change is for), dynamic scopes could be utilized by others that need it. I think it's a powerful concept and it gives extensions another trick.

Copy link
Member

It does raise one question, though: what if evaluation starts at a subschema? I suppose the dynamic scope is still the resource, but the evaluation path would still start from the subschema? This is how I have it now, and I could change it if we decide something else.

This would be good to have as a test case in the test suite. Also, writing up an example of how this would work depending on which way it would be implemented would help us see which way is more "right".

Copy link
Member Author

gregsdennis commented Apr 19, 2025
edited
Loading

writing up an example of how this would work - @karenetheridge

What I'm really thinking of here is more related to what you might have in an OpenAPI description. A resource root might be the entire document, so a schema wouldn't be at the resource root.

openapi: 3.1
# ...
components:
 schemas:
 foo:
 $dynamicAnchor: root
 properties:
 bar: { $ref: "#/components/schemas/bar" }
 bar:
 $id: bar
 $dynamicAnchor: root
 properties:
 recurse: { $dymamicRef: "#root" }

Here, while evaluation starts at /components/schemas/foo, the evaluation path after a loop would look like /properties/bar/$ref/properties/recurse/$dynamicRef, and you'd be back at /components/schemas/foo.

The dynamic scopes, then, are:

  • the document
  • the bar schema
  • the document again, ...

So even though the top-level scope is the full document, the evaluation path starts in the middle of it. I think this is fine and probably expected.

jdesrosiers reacted with thumbs up emoji

@gregsdennis gregsdennis merged commit 788dcbb into main Apr 26, 2025
6 checks passed
@gregsdennis gregsdennis deleted the gregsdennis/improve-scopes branch April 26, 2025 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@jdesrosiers jdesrosiers jdesrosiers approved these changes

Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

🧹 Clarification: Scopes section could be improved

AltStyle によって変換されたページ (->オリジナル) /