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

Resolving nested allOf keywords #2557

Open
char0n opened this issue May 26, 2022 · 0 comments
Open

Resolving nested allOf keywords #2557

char0n opened this issue May 26, 2022 · 0 comments
Assignees

Comments

@char0n
Copy link
Member

char0n commented May 26, 2022

When resolving subtree with nested allOf keywords, allOf and $ref keywords are not resolved on all places.

The problem manifests only when resolution is done on subtree of the definition (not the whole one). In 99% cases the resolution of subtree works, but on some definitions which are written in a certain way, nested JSON Schema objects within the subtree are untouched by resolution and allOf + $ref is not processed/traversed at all. This creates multitude of side effects which manifests like errors.

OAS definition to reproduce - str.yaml

# OpenAPI version identifier - required for OpenAPI 3.0 domains
openapi: 3.0.3

#######################
# Optional info section
#######################

info:
  title: Steps To Reproduce
  version: 2.0.0

components:
  schemas:
    schemaStub1: {
      type: object
    }


    shippingInstructionRequest:
      type: object
      allOf:
        - $ref: '#/components/schemas/shippingInstructionShallow'
        - $ref: '#/components/schemas/shippingInstructionDeep'


    shippingInstructionShallow:
      type: object
      allOf:
        - type: object
          properties:
            amendToTransportDocument:
              allOf:
                - $ref: '#/components/schemas/schemaStub1'

    shippingInstructionDeep:
      type: object
      allOf:
        - type: object
          properties:
            placeOfIssue:
              allOf:
                - $ref: '#/components/schemas/schemaStub1'

    shippingInstructionResponse:
      type: object
      allOf:
        - $ref: '#/components/schemas/shippingInstructionRequest'

    transportDocument:
      allOf:
        - properties:
            shippingInstruction:
              allOf:
                - $ref: '#/components/schemas/shippingInstructionResponse'

Failing JavaScript test:

const fs = require('fs');
const yaml = require('js-yaml');
const { inspect } = require('util');

const yamlObj = yaml.load(fs.readFileSync('./str.yaml'));
const { default: SwaggerClient } = require('swagger-client');

(async () => {
  const result = await SwaggerClient.resolveSubtree(
    yamlObj,
    ['components', 'schemas', 'transportDocument'],
    { returnEntireTree: true }
  );
  console.log(inspect(result, { showHidden: true, depth: null }));
})();

Expected result can be seen by running following code:

const fs = require('fs');
const yaml = require('js-yaml');
const { inspect } = require('util');

const yamlObj = yaml.load(fs.readFileSync('./str.yaml'));
const { default: SwaggerClient } = require('swagger-client');

(async () => {
  const result = await SwaggerClient.resolve({ spec: yamlObj });
  console.log(inspect(result, { showHidden: true, depth: null }));
})();
@char0n char0n self-assigned this May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant