question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bundle references into definitions

See original GitHub issue

Let’s say we have a schema that has external references to another schema’s definitions:

foo.json

{
  "definitions": {
    "foo": {
      "properties": {
        "a": {
          "$ref": "./bar.json#/definitions/bar"
        },
        "b": {
          "$ref": "./bar.json#/definitions/bar"
        },
        "c": {
          "$ref": "./bar.json#/definitions/bar"
        }
      }
    }
  }
}

bar.json

{
  "definitions": {
    "bar": {
      "properties": {
        "a": {
          "type": "string"
        },
        "b": {
          "type": "number",
          "maximum": 20
        }
      }
    }
  }
}

When using parser.bundle('foo.json') to bundle the external references, this is the resulting schema:

{
  "definitions": {
    "foo": {
      "properties": {
        "a": {
          "properties": {
            "a": {
              "type": "string"
            },
            "b": {
              "type": "number",
              "maximum": 20
            }
          }
        },
        "b": {
          "$ref": "#/definitions/foo/properties/a"
        },
        "c": {
          "$ref": "#/definitions/foo/properties/a"
        }
      }
    }
  }
}

While this is a valid schema, it seems more straightforward to copy the definition for bar into definitions, especially if it is referenced in multiple places:

{
  "definitions": {
    "foo": {
      "properties": {
        "a": {
          "$ref": "#/definitions/bar"
        },
        "b": {
          "$ref": "#/definitions/bar"
        },
        "c": {
          "$ref": "#/definitions/bar"
        }
      }
    },
    "bar": {
      "properties": {
        "a": {
          "type": "string"
        },
        "b": {
          "type": "number",
          "maximum": 20
        }
      }
    }
  }
}

Can this be done somehow?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
aaronschwartzcommented, Aug 27, 2018

This ability is super helpful for creating files that are used by other class generator tools.

Are there any plans to have an option to create the shared definition entries automatically?

When maintaining multiple files, it’s kind of hard to remember/enforce that the definition entry is created along with the other references. And if those references ever change you need to make sure to go update the definition entry as well.

2reactions
JamesMessingercommented, Feb 26, 2018

You can accomplish this by referencing bar in the definitions section, like this:

{
  "definitions": {
    "foo": {
      "properties": {
        "a": {
          "$ref": "./bar.json#/definitions/bar"
        },
        "b": {
          "$ref": "./bar.json#/definitions/bar"
        },
        "c": {
          "$ref": "./bar.json#/definitions/bar"
        }
      }
    }
  },
  "bar": {
    "$ref": "./bar.json#/definitions/bar" 
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bundle Definition & Meaning - Merriam-Webster
1 · to make into a bundle. bundle the magazines together ; 2 · to hustle or hurry unceremoniously. bundled the children off...
Read more >
bundle - WordReference.com Dictionary of English
an item wrapped for carrying; package:He brought in a few bundles from the car. ; a large amount of something; a lot of:He's...
Read more >
Bundle definition and meaning | Collins English Dictionary
1. a number of things tied, wrapped, or otherwise held together · 2. a package or parcel · 3. a bunch, collection, or...
Read more >
Bundle - definition of bundle by The Free Dictionary
1. a number of things or a quantity of material gathered or loosely bound together: a bundle of sticks. · 2. something wrapped...
Read more >
BUNDLE resources - IBM
A BUNDLE resource defines a CICS bundle, a unit of deployment for an application. A bundle is a collection of CICS resources, artifacts,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found