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

Custom protocol support #587

Closed
raman-kananovich opened this issue Mar 29, 2021 · 10 comments · Fixed by #739 · 4 remaining pull requests
Closed

Custom protocol support #587

raman-kananovich opened this issue Mar 29, 2021 · 10 comments · Fixed by #739 · 4 remaining pull requests
Labels

Comments

@raman-kananovich
Copy link

I want to use this library to work via a custom protocol that is based on a pub/sub mechanism.

It would be great to expose new versions of the parseOpenRPCDocument which accepts custom URI getters/resolvers.

Proposed functionality usage example
const parseOpenRPCDocument = makeCustomProtocolParseOpenRPCDocument(fetchCustomProtocol, resolveReferenceCustomProtocol);

Could you please provide your opinion regarding my proposal?

If it looks OK for you I can implement it and create a pull request.

@zcstarr
Copy link
Member

zcstarr commented Mar 31, 2021

@BelfordZ should weigh in here. It seems like you might want something like

const parseOpenRpcDocument = makeBaseParseOpenRPCDocument(customProtcolHandler: (string)=>Promise<OpenRPC>)
parseOpenRpcDocument("custom://someotherprotocol", {dereference: mycustomRefHandler})

Then makeCustomParseOpenRPCDocument and the parseOpenRPCDocument can share the same logic.

Where parseOpenRPCDocument looks like it does now essentially except instead of returning the function it returns a call to makeBaseParseOpenRPCDocument with the appropriate handler.

function async makeParseOpenRpcDocument(...) {

   const stringParseOpenRPC = makeBaseParseOpenRPCDocument((s)=>Promse.resolve(s))
   const jsonParseOpenRPC =  makeBaseParseOpenRPCDocument((s)=>Promse.resolve(JSON.parse(s as string)))
   const urlParseOpenRPC = makeBaseParseOpenRPCDocument(fetchSchemaUrl)
   const fileParseOpenRPC = makeBaseParseOpenRPCDocument(readSchemaFromFile)
   
   return parseOpenRPCDocument ... {
   ....
    if (typeof schema !== "string") {
      return stringParseOpenRPC(schema)
    } else if (isJson(schema as string)) {
      return  jsonParseOpenRPC(schema)
    } else if (isUrl(schema as string)) {
      return urlParseOpenRPC(schema)
    } else {
      return fileParseOpenRPC(schema)
    }
    ....

Then signature for makeParseOpenRPCDocument remains the same, but you have a way to access lower level functionality.

@raman-kananovich
Copy link
Author

@zcstarr, thank you! This API covers my needs completely.

How do you think if I can start its implementation?

@zcstarr
Copy link
Member

zcstarr commented Apr 1, 2021

@raman-kananovich you might actually do this as a stop gap , while we think over if the api change belongs inside schema-utils or not. You can start with the custom protocol and just deref the document then pass the dereffed document into to parseOpenRPCDocument.

We think https://github.com/json-schema-tools/reference-resolver and
https://github.com/json-schema-tools/referencer would be good places to start.

Inside the reference-resolver you'll need a PR here for your protocol would be immensely useful. Regardless about the api change, you'll need this logic in order to handle the custom protocol dereferencing. I'd start there.

@raman-kananovich
Copy link
Author

@zcstarr, thank you! As you have proposed I am starting from reference-resolver.

@raman-kananovich
Copy link
Author

Hello @zcstarr, could you please help me with the question regarding signing CLA? Can you provide a link to the instruction on how to do it. I have tried to google this topic, but the answers are different.

@zcstarr
Copy link
Member

zcstarr commented Apr 13, 2021

@raman-kananovich don't worry about it, there is no CLA, that portion of the contributing.md is stale.

@raman-kananovich
Copy link
Author

@zcstarr, thank you!

@raman-kananovich
Copy link
Author

I have created a pull request to reference-reolver. I hope that I have done it in the right way.

@zcstarr, could you please take a look at my PR json-schema-tools/reference-resolver#146 ?

@stale
Copy link

stale bot commented Jun 16, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 16, 2021
@stale stale bot closed this as completed Jun 26, 2021
@shanejonas shanejonas reopened this Aug 4, 2021
@stale stale bot removed the stale label Aug 4, 2021
zcstarr added a commit that referenced this issue Sep 24, 2021
This feature exposes two separate entry points for creating a resolver,
one using the makeCustomResolver() option and another for advanced
users that want more or need more control over the resolution process,
which allows users to extend the resolver class if needed.

fixes #587
zcstarr added a commit that referenced this issue Sep 24, 2021
This feature exposes two separate entry points for creating a resolver,
one using the makeCustomResolver() option and another for advanced
users that want more or need more control over the resolution process,
which allows users to extend the resolver class if needed.

fixes #587
openrpc-bastion added a commit that referenced this issue Sep 24, 2021
# [1.16.0](1.15.0...1.16.0) (2021-09-24)

### Bug Fixes

* node version bump ([5f92ca3](5f92ca3))
* version bump ([fd86502](fd86502))

### Features

* expose an option to support custom resolver resolution. ([103f022](103f022)), closes [#587](#587)
@openrpc-bastion
Copy link
Member

🎉 This issue has been resolved in version 1.16.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment