Skip to content

Support the use of special chars in json pointers#36

Open
shenie wants to merge 2 commits intocvent:masterfrom
shenie:master
Open

Support the use of special chars in json pointers#36
shenie wants to merge 2 commits intocvent:masterfrom
shenie:master

Conversation

@shenie
Copy link

@shenie shenie commented Mar 4, 2020

Based on spec https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-04

You should be able to use ~1 for slash, which we need due to the way we
split api swagger files.

So I hope we can add support for it.

EDIT

I started at https://swagger.io/docs/specification/using-ref/ which says

The value of $ref uses the JSON Reference notation,

that takes me to https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03 and in section 4 it links to JSON-Pointer

which is how I arrived at https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-04

@shenie
Copy link
Author

shenie commented Mar 19, 2020

Hi @jcurtis / @bojand

Could you guys please have a look at this PR?

And if it’s all good it wound be great to release a new version.

Thanks

@shenie
Copy link
Author

shenie commented Mar 19, 2020

@kobik I noticed you had a related change (#28).

I was curious on your 2c on my PR here.

@Wim-van-der-Veen
Copy link

Wim-van-der-Veen commented Jul 3, 2020

I fixed this issue by changing code in lib/utils.ts:83 and further to

    if ( key.search('~0|~1|%[0-9A-Fa-f]2')>-1 ) {

      // WV 20200702 as according to spec 'https://swagger.io/docs/specification/using-ref' --> escape characters
      key = key.replace( /~1/g, '/' ).replace( /~0/g, '~' );

      // WV 20200702 necessary hack, following spec 'https://swagger.io/docs/specification/using-ref/' --> $ref Syntax ( and RFC 3986 )
      key = key.replace( /%7B/g, '{' ).replace( /%7D/g, '}' );

    }
    return value[key];
  }, schema);

The first replacement line handle the specified ~0 and ~1 special codes, the second replacement line handles the url-encoding for { and }, which is a hack as shown, but does what I need right now

Pls update master accordingly, so the dependants will install correctly

@kobik
Copy link
Contributor

kobik commented Jul 3, 2020

Don't you want to use decodeURIComponent instead?

@Wim-van-der-Veen
Copy link

Don't you want to use decodeURIComponent instead?

it's being used in the openapi-validator-middleware, so the choice is not up to me

@shenie
Copy link
Author

shenie commented Jul 5, 2020

I've included the changes from @Wim-van-der-Veen

Does anyone know the owner of the repo to help give this PR a little nudge?

@sjworkuid
Copy link

Any update on this issue?
We're using oas-tools which has this lib as a dependency.

shenie added 2 commits July 13, 2021 11:55
Based on spec https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-04

You should be able to use ~1 for slash, which we need due to the way we
split api swagger files.

So I hope we can add support for it.
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.

4 participants