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

Expand schemas #15

Closed
loganvolkers opened this issue Jul 29, 2015 · 5 comments
Closed

Expand schemas #15

loganvolkers opened this issue Jul 29, 2015 · 5 comments

Comments

@loganvolkers
Copy link

It would be handy to provide an option to "expand" a schema to resolve things like allOf or oneOf.

It seems like there has already been some work put into this for the JSON-Editor project.

https://github.com/jdorn/json-editor/blob/92857220697d0e4265a1945b9a469962c340921e/src/core.js#L417

I envision this being similar to the "dereference" option.

If there is interest in this, I'd be happy to contribute a pull request, I just need some guidance on the best way to include this. I was basically going to either clone or extend the "deference" option.

@loganvolkers
Copy link
Author

Original spec from here: jdorn/json-editor#49

{
  "type": "object",
  "allOf": [
    {
      "properties": {
        "key1": {
          "type": "string"
        }
      },
      "required": ["key1"]
    },
    {
      "properties": {
        "key2": {
          "type": "string"
        }
      },
      "required": ["key2"]
    }
  ]
}

Should produce the following after it's expanded:

{
  "type": "object",
  "properties": {
    "key1": {
      "type": "string"
    },
    "key2": {
      "type": "string"
    }
  },
  "required": ["key1","key2"]
}

@JamesMessinger
Copy link
Member

Yeah, that seems like something we could do. We're in the middle of a major refactoring of Swagger Parser right now, and we're splitting all of the non-Swagger-specific logic into a seperate package called JSON Schema $Ref Parser. That's where this feature would go, since it deals solely with JSON Schema, not Swagger.

@loganvolkers
Copy link
Author

This makes a lot of sense to me. I'll keep an eye on that project.

Moved this issue there: APIDevTools/json-schema-ref-parser#1

@JamesMessinger
Copy link
Member

Cool. Thanks for moving it over.

@loganvolkers
Copy link
Author

Update on this issue to close the loop. It looks like support for composition has been added by the swagger-api/swagger-js library.

As per their test specs allOf can being used for:

For my use case, we are using allOf for composition, and since swagger-parser doesn't support resolving allOf references we've started using their Resolver class in the meantime.

Here's an example for those also stuck trying to support composition:

var Resolver = require('swagger-client/lib/resolver');
new Resolver().resolve(inputSwaggerSchema, null, function (resolvedSchema, unresolved) {
   // Use the ResolvedSchema
});

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

2 participants