-
Notifications
You must be signed in to change notification settings - Fork 85
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
optic capture
failing due to discriminated union represented as oneOf
with enums
#2656
Comments
optic capture
failing due to discriminated union represented as oneOf
optic capture
failing due to discriminated union represented as oneOf
with unions
optic capture
failing due to discriminated union represented as oneOf
with unionsoptic capture
failing due to discriminated union represented as oneOf
with enums
I have a PR up to fix the duplicate enum items being generated by optic capture #2659 (releasing a pre-release 0.53.22-0). I'm still trying to recreate the errors your getting and I'm not sure I understand the other 2 errors from AJV. Very weirdly I'm not getting an error with something like this (where I'd expect the duplicate enum error), both with this script and through my own Optic CLI (local AJV version is import Ajv from 'ajv/dist/2019';
const ajv = new Ajv({
allErrors: true,
validateFormats: false,
strictSchema: false,
strictTypes: false,
useDefaults: true,
});
const validator = ajv.compile(prepareSchemaForDiff(schema)); schema:
type: object
properties:
name:
type: string
enum: ['a','a','a'] I'm going to keep digging - but if you could try out the prerelease and see if that helps, and if you could check what AJV version the backstage repo is using that would be helpful! |
@niclim Thanks for looking into this! Just tried it and no longer getting the error. I wonder if it was just related to the enum definition? Seems odd though. Still getting a weird patch though,
This is definitely closer, but the enum is still being spread across both We're using 8.12.0 as the AJV version in Backstage as well. |
I just realized that I had |
Ok this looks like an issue with how we patch We'll need to fix this by looking at our patching code and choose the most relevant branch to then patch using some sort of heuristic... I think we'll need to fix something here and maybe we can use our closeness heuristic but modified for interactions rather than schemas For the meantime, I think if you manually adjust the schema to match whatever the returned value of the interaction, it should still correctly validate that the request / responses match the oneOf blocks, it'll just patch every branch of the oneOf. Not sure what interaction is causing the patch you mentioned above though |
Thanks! Sorry for the slow update here. I was able to get this working by using 'anyOf' instead of 'oneOf'. That also fixed some issues I was having with a separate AJV validator. I'll take a look and see if I can add the fix, I'd like to also add support for object access query parameters, (object[id]) and this would be a good chance to get familiar with the code base. |
Describe the bug
I'm trying to write a new spec for a Backstage plugin that uses discriminated union types rendered as
oneOf
. I'm getting an AJV validationg error where Optic is using AJV to validate its own patched schema, which I think means that the patched schema is invalid. All of the code that I outline below can be found in this PR, here. Basically, I'm trying to useoneOf
and enums to differentiate between two separate types. From what I can tell withjson-schema-to-ts
, my spec is correct, but I'm getting a few weird errors from AJV surfaced through Optic,anyOf
Full error messages below.
The types in question are,
So far, my JSON schema (YAML) looks like this,
This results in the following schema (added a
console.dir
here),optic/projects/optic/src/commands/capture/patches/patchers/shapes/diff.ts
Line 301 in 8001d02
which throws an error during AJV compilation,
Taking a look at the logs, this request causes part of the enum error by adding the "ALLOW" and "DENY" values twice. The other 2 errors I'm not sure about.
Internal optic schema diff after running the above request,
To Reproduce
See my PR here. I'm running
PORT=8001 optic capture src/schema/openapi.yaml --server-override http://localhost:8001
inplugins/permission-backend
to get the output seen above.Expected behavior
An error is not thrown and the schema validates as expected.
Details (please complete the following information):
The text was updated successfully, but these errors were encountered: