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

$ref pointing to a external file #60

Open
roselmamendes opened this issue Feb 26, 2015 · 7 comments
Open

$ref pointing to a external file #60

roselmamendes opened this issue Feb 26, 2015 · 7 comments

Comments

@roselmamendes
Copy link

I am wondering if flex accept to use $ref pointing to an external file.

In the Swagger documentation say:

parts of the definitions can be split into separate files, at the discretion of the user. This is applicable for $ref fields in the specification as follows from the JSON Schema definitions.

Calling Flex, I tried to use json specifications, like:

      schema:
        $ref: 'modelswagger.yaml#/definitions/Model'

or following the Flex specifications to reference definitions. Without "definitions" word.

      schema:
        $ref: 'modelswagger.yaml#Model'

I get this:

  • '$ref':
    • 'Unknown definition reference account_swagger.yaml#/Account'

Is this possible implement on the Flex?
Does it worth do this?

Thanks.

@pipermerriam
Copy link
Owner

I would love to have support for this. Are you interested in doing it, or
it this a feature request?

On Thu, Feb 26, 2015, 7:17 AM Roselma Mendes [email protected]
wrote:

I am wondering if flex accept to use $ref pointing to an external file.

In the Swagger documentation say:

parts of the definitions can be split into separate files, at the
discretion of the user. This is applicable for $ref fields in the
specification as follows from the JSON Schema definitions.

Calling Flex, I tried to use json specifications
http://spacetelescope.github.io/understanding-json-schema/structuring.html,
like:

  schema:
    $ref: 'modelswagger.yaml#/definitions/Model'

or following the Flex specifications to reference definitions. Without
"definitions" word.

  schema:
    $ref: 'modelswagger.yaml#Model'

I get this:

  • '$ref':
    • 'Unknown definition reference account_swagger.yaml#/Account'

Is this possible implement on the Flex?
Does it worth do this?

Thanks.


Reply to this email directly or view it on GitHub
#60.

@roselmamendes
Copy link
Author

Hey,

Thanks for your answer.
I can take a look, and see how do that. Because would be interesting for our project.

@pipermerriam
Copy link
Owner

Awesome. I look forward to it. Here are a few things that might be useful for you.

  • flex.validation.schema.LazyReferenceValidator - This class implements the actual validation of some data against a referenced schema. It will likely need to be modified, as it currently assumes that it can get the schema for a reference from the definitions defined in the local schema.
  • When validating a swagger schema, any $ref's that are encountered are tracked so that later they can be validated. see here for how this happens. The premise that all references must be present may not work for everyone's use case, but currently, flex assumes that a missing $ref is an error.
  • At the end of schema loading, all $ref values that were encountered are validated to exist. https://github.com/pipermerriam/flex/blob/master/flex/loading/definitions/__init__.py#L39 . This function is likely the best entry point to loading and validating an external reference.

@pipermerriam
Copy link
Owner

This feature is now going to be much easier to implement.

There is some research I still need to do in how to resolve what url should be used (if any) for things like this.

@Lookyan
Copy link

Lookyan commented Aug 25, 2016

Is it still not implemented?
If not, I can do this. Please point me how it would be better to implement this feature.

@pipermerriam
Copy link
Owner

This is not implemented and you have my full support in working on this if you so choose. Any implementation that actually fetches resources from an external URL makes me a little nervous but I'm not sure that concern is well founded. I think it's safe to proceed as if it isn't an issue and we can assess whether there is any security concern.

@Lookyan
Copy link

Lookyan commented Sep 22, 2016

Hi! I need a help. Is there a one place where I can patch $ref resolving with external path?
You wrote that there was a good place to implement this feature (https://github.com/pipermerriam/flex/blob/master/flex/loading/definitions/init.py) but as I can see resolve_pointer is invoked in multiple places and I don't see the way how to patch it only in one place.

May be it would be better to create a separate module for $ref resolving and invoke it from any place where it is needed?
Also I have a problem with paths, we need a relative path which will be the base path for $ref schemas to avoid big absolute paths. I need an advice how it would be better to pass it to flex validators.

Thank you!

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

No branches or pull requests

3 participants