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

[cli] register main schemas using dataValidator.addSchema(<service>Schema) #2993

Closed
miguelrk opened this issue Jan 18, 2023 · 1 comment · Fixed by #2997
Closed

[cli] register main schemas using dataValidator.addSchema(<service>Schema) #2993

miguelrk opened this issue Jan 18, 2023 · 1 comment · Fixed by #2997

Comments

@miguelrk
Copy link

TLDR: CLI should be udpated to register main schemas using dataValidator.addSchema(<service>Schema) to be able to use Type.Ref(<service>Schema)

Relevant thread

Steps to reproduce

I'm getting the same Error MissingRefError: can't resolve reference User from id Message when using user: Type.Ref(userSchema) for the following:

const userSchema = Type.Object({
    // ...
  }, { $id: 'User', additionalProperties: false }
)
const messageSchema = Type.Object({
    userId: Type.String(),
    user: Type.Ref(userSchema)
  }, { $id: 'Message', additionalProperties: false }
)

Expected behavior

Main schemas (and all others: data, patch and query) should be registered using ajv's addSchema()

Actual behavior

I have tried the following for user instead of Type.Ref(userSchema) to no success:

// throws "Error: reference "User" resolves to more than one schema
user: userSchema
// throws "MissingRefError"
user: Type.Ref(userSchema, { $id: 'User' })
// does not work
user: Type.Ref(userSchema, { $schema: 'User' })

System configuration

"@feathersjs/adapter-commons": "^5.0.0-pre.35",
"@feathersjs/authentication": "^5.0.0-pre.35",
"@feathersjs/authentication-client": "^5.0.0-pre.35",
"@feathersjs/authentication-oauth": "^5.0.0-pre.35",
"@feathersjs/configuration": "^5.0.0-pre.35",
"@feathersjs/errors": "^5.0.0-pre.35",
"@feathersjs/express": "^5.0.0-pre.35",
"@feathersjs/feathers": "^5.0.0-pre.35",
"@feathersjs/mongodb": "^5.0.0-pre.35",
"@feathersjs/schema": "^5.0.0-pre.35",
"@feathersjs/socketio": "^5.0.0-pre.35",
"@feathersjs/transport-commons": "^5.0.0-pre.35",
"@feathersjs/typebox": "^5.0.0-pre.35",
@miguelrk
Copy link
Author

For reference, adding dataValidator.addSchema(<service>Schema) right after declaring <service>Schema gets it working. For example:

// user.schema.ts
const userSchema = Type.Object({
    // ...
  }, { $id: 'User', additionalProperties: false }
)
dataValidator.addSchema(userSchema) // ADD THIS LINE HERE

// message.schema.ts
import { userSchema } from "../users/user.schema"

const messageSchema = Type.Object({
    userId: Type.String(),
    user: Type.Ref(userSchema)
  }, { $id: 'Message', additionalProperties: false }
)

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