formalize reference locations in the OpenAPI document schema #4262
                  
                    
                      karenetheridge
                    
                  
                
                  started this conversation in
                Enhancements
              
            Replies: 1 comment 1 reply
-
| 
         For folks less familiar with JSON Schema, heres how declaring plain name fragments could look in the two relevant drafts: For OAS 3.1): $schema: https://json-schema.org/draft/2020-12/schema
$defs:
  path-item:
    $anchor: PathItemFor OAS 3.0: $schema: "https://json-schema.org/draft-04/schema#"
definitions:
  PathItem:
    id: "#PathItem"Note that the JSON Pointers are different in the two schemas (partially   | 
  
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In my implementation I take note of the reference location of various entities while parsing an openapi document -- e.g. when following a
$refin the schema that points to#/$defs/parameter-or-referenceI make a note of the data location (in the openapi document being parsed) that this is a location of a parameter entity. This builds up a registry of location -> entity type maps, which I make use of at runtime when resolving a$refin the openapi document -- e.g. when validating an HTTP request against the openapi description, and I am processing a parameter object in the description, if I see a$refto something that I expect is a parameter object, when resolving this reference I check in the entity registry to confirm that the target of the reference is indeed a parameter (and if not, this constitutes a runtime error). [I also have plans to check all$reftargets at parse time, at least for those pointing to the local document, as part of an extra linting step, but haven't implemented this yet.]This means I am dependent on the name of the references in the openapi schema. Everything is using the same naming convention of
#/$defs/foo-or-referenceand#/$defs/fooin the schema definitions, but theoretically this could change at any time as there are no guarantees as to how the schema is constructed. Therefore it would be useful to formalize some of these locations and use$anchors in these definitions, and make use of the plain-name fragment form in the$refs, and document their use, so we are free to move things around in the schema while still preserving a name that can be relied upon by implementors.ref. https://open-api.slack.com/archives/C06A0RPNPGE/p1734458650755389
Beta Was this translation helpful? Give feedback.
All reactions