You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The ajv validator used by Optic counts a schema's id property as the schema $id. When it validates a schema it throws an error if schema ids aren't unique. That's perfect for schema validation, but it's problematic when working in OpenAPI examples which could legitimately have the same id property.
If a de-referenced schema has the same example and the Optic standard includes example verification, then optic diff and optic diff-all fail with the error reference <the id property value in the schema's example> resolves to more than one schema.
I worked around this by disabling example validation in my Optic standard, but I'd like to turn it back on so Optic can continue to report example accuracy.
To Reproduce
Given an OpenAPI spec that includes duplicate examples by way of a shared model (see the comments in the YAML snippet for more information):
openapi: 3.0.3x-optic-url: <snip>x-optic-standard: <snip> # The standard includes example validationinfo:
title: My no-op API servicedescription: It doesn't do anything!version: "1.0"servers:
- url: http://localhost:3000tags:
- name: no-opdescription: The operation is intentionally not executablepaths:
/models:
get:
operationId: GetModelssummary: Get all common modelsdescription: A non-existent endpoint that returns model references so linters can validate model schemastags: [no-op]responses:
'200':
description: OKrequestBody:
content:
application/json:
schema:
anyOf:
- type: objectnullable: true
- type: objectproperties:
link:
anyOf:
# A Link is oneOf a LinkExternal or a LinkInternal. This creates duplicate examples # when the spec is de-referenced.
- $ref: https://backmarket.github.io/api-models/Link.yaml
- type: objectnullable: trueexample: {}linkExternal:
anyOf:
- $ref: https://backmarket.github.io/api-models/LinkExternal.yaml
- type: objectnullable: trueexample: {}linkInternal:
anyOf:
# Note that this schema has an example whose `id` property is "3". This means# that two examples with an id of "3" exist in the de-referenced spec.
- $ref: https://backmarket.github.io/api-models/LinkInternal.yaml
- type: objectnullable: trueexample: {}
Run optic diff[-all] on this specification and receive the error reference '3' resolves to more than one schema.
Expected behavior
Optic should validate the example matches the schema but allow for example id fields with the same value.
Screenshots
n/a
Details (please complete the following information):
OS and version: Ubuntu 20.04.6 LTS, kernel: 5.15.0-1039-aws, architecture: x86_64
Optic version: 0.53.15
NodeJS version: 20.10.0, via by the cimg/node:lts container
Additional context
Spectral encountered the same problem and introduced a workaround earlier this year to absorb these errors when they're found in schema examples. See stoplightio/spectral#2081 for discussion on the issue. It looks the same as what I see with Optic.
Thanks for looking, y'all. ❤️ Please let me know what you think.
The text was updated successfully, but these errors were encountered:
Hi @klaude - thanks for the detailed issue! I've released a new version that includes this fix (similar to what spectral implemented) in 0.53.19 and I believe that this should fix the issue with example rulesets
Hey howdy, Optic folks! 👋
Describe the bug
The ajv validator used by Optic counts a schema's
id
property as the schema$id
. When it validates a schema it throws an error if schema ids aren't unique. That's perfect for schema validation, but it's problematic when working in OpenAPI examples which could legitimately have the sameid
property.If a de-referenced schema has the same example and the Optic standard includes example verification, then
optic diff
andoptic diff-all
fail with the errorreference <the id property value in the schema's example> resolves to more than one schema
.I worked around this by disabling example validation in my Optic standard, but I'd like to turn it back on so Optic can continue to report example accuracy.
To Reproduce
Given an OpenAPI spec that includes duplicate examples by way of a shared model (see the comments in the YAML snippet for more information):
Run
optic diff[-all]
on this specification and receive the errorreference '3' resolves to more than one schema
.Expected behavior
Optic should validate the example matches the schema but allow for example
id
fields with the same value.Screenshots
n/a
Details (please complete the following information):
Additional context
Spectral encountered the same problem and introduced a workaround earlier this year to absorb these errors when they're found in schema examples. See stoplightio/spectral#2081 for discussion on the issue. It looks the same as what I see with Optic.
Thanks for looking, y'all. ❤️ Please let me know what you think.
The text was updated successfully, but these errors were encountered: