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

Added filtering for dereferenced nodes #142

Closed

Conversation

AndrzejTSH
Copy link

Ability to filter which schema can be dereferenced by checking its contents.

Usage

    const refParser = require("json-schema-ref-parser");

    refParser.dereference(originalJsonSchemaObj, {
        // dereference the following schemas: model properties, path & query parameters
        dereference: {
            filter: (value) => {
                return ['query', 'path'].includes(value.in)
                    || ['string', 'array', 'integer', 'number', 'boolean'].includes(value.type);
            }
        }
    }).then((schemaDerefed) => {
        // ...
    });

Effect

Before:

      "AccountDepositPaytrailInitRequest": {
        "type": "object",
        "properties": {
          "amount": {
            "$ref": "#/components/schemas/Record/properties/amount"
          },
          "itemName": {
            "$ref": "#/components/schemas/ItemSearchResult/properties/name"
          },
          "userId": {
            "$ref": "#/components/schemas/UserRearchResult/properties/id"
          }
        },
        "required": [
          "amount",
          "itemName"
        ]
      },

After:

      "AccountDepositPaytrailInitRequest": {
        "type": "object",
        "properties": {
          "amount": {
            "type": "integer",
            "description": "Money amount.",
            "example": 17500
          },
          "itemName": {
            "type": "string",
            "description": "Technical name of the product (item).",
            "minLength": 1,
            "maxLength": 128,
            "example": "EXERCISE_EMONEY"
          },
          "userId": {
            "type": "integer",
            "description": "User identifier.",
            "readOnly": true,
            "minimum": 1,
            "example": 1
          }
        },
        "required": [
          "amount",
          "itemName"
        ]
      }

@coveralls
Copy link

coveralls commented Nov 12, 2019

Pull Request Test Coverage Report for Build 368

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 92.768%

Totals Coverage Status
Change from base Build 364: 0.1%
Covered Lines: 7381
Relevant Lines: 7788

💛 - Coveralls

@AndrzejTSH AndrzejTSH closed this Nov 12, 2019
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.

None yet

2 participants