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

[OmniGraph OpenAPI] Objects listed in allOf operator do not get deep merged #5641

Closed
4 tasks done
cweckesser opened this issue Jul 6, 2023 · 0 comments · Fixed by #5643
Closed
4 tasks done

[OmniGraph OpenAPI] Objects listed in allOf operator do not get deep merged #5641

cweckesser opened this issue Jul 6, 2023 · 0 comments · Fixed by #5643

Comments

@cweckesser
Copy link
Contributor

cweckesser commented Jul 6, 2023

Issue workflow progress

Progress of the issue based on the
Contributor Workflow

Make sure to fork this template and run yarn generate in the terminal.

Please make sure Mesh package versions under package.json matches yours.

  • 2. A failing test has been provided
  • 3. A local solution has been provided
  • 4. A pull request is pending review

Describe the bug

The OmniGraph-OpenAPI library cannot deep merge objects listed in an allOf operator.

For a component combining properties of different objects via the allOf keyword, if any property of these objects exists in more than one of them and this property is also an object, then these object-like overlapping properties will not be merged into one single object, combining all their different sub-properties. Instead, only the sub-properties of the last object-like overlapping property will be included in the resulting object.

A more detailed example of the issue has been added here.

To Reproduce Steps to reproduce the behavior:

  1. Using the loadGraphQLSchemaFromOpenAPI function from the @omnigraph/openapi library, load a schema containing objects listed in an allOf operator with overlapping properties (e.g.: https://github.com/cweckesser/graphql-mesh-testing/blob/main/packages/loaders/openapi/graphql/schemas/test-schema.json, here the attributes property is defined in two objects).
  2. Once the schema is loaded, either:
  • inspect it using debugging tools,
  • log it to the console or
  • launch a GraphQL server (e.g. GraphQL Yoga) and then analyze the response from the introspection query
  1. In either case, only the overlapping property of the last object listed in the allOf operator will be in the resulting schema

For an already-working example that reproduces this issue, consider the following code sandbox


Alternatively, the following repository can be checked out and then the following instructions can be followed:

  1. From the project root folder, move to the sub-directory for the OpenAPI loader: cd packages/loaders/openapi
  2. Build the project: yarn
  3. Test the schema generation by either:
  • executing unit tests: yarn test:unit
  • launching a GraphQL Yoga server and check the introspection result: yarn start

Expected behavior

The overlapping properties of objects listed in an allOf operator should be deep merged. Consider the following example:

"Person": {
	"data": {
		"allOf": [{
			"attributes": {
				"description": "Address fields",
				"properties": {
					"street_name": { "type": "string" },
					"street_number": { "type": "string" },
					"postal_code": { "type": "string" },
					"city": { "type": "string" },
					"state": { "type": "string" },
					"country": { "type": "string" }
				}
			}
		}, {
			"attributes": {
				"description": "Contact fields",
				"properties": {
					"personal_email": { "type": "string" },
					"work_email": { "type": "string" },
					"personal_phone_number": { "type": "string" },
					"work_phone_number": { "type": "string" }
				}
			}
		}]
	}
}

When processing this schema, it should be expected that the Person.data.attributes sub-property resulted in the combination of all the attributes object-properties corresponding to the objects listed in the allOf operator:

{
	"Person": {
		"data": {
			"attributes": {
				"street_name": {...},
				"street_number": {...},
				"postal_code": {...},
				"city": {...},
				"state": {...},
				"country": {...},
				"personal_email": {...},
				"work_email": {...},
				"personal_phone_number": {...},
				"work_phone_number": {...}
			}
		}
	}
}

Environment:

  • OS: macOS
  • "@omnigraph/openapi": "^0.94.6",
  • NodeJS: 16

Additional context

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 a pull request may close this issue.

1 participant