-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
property.array generates incorrect schema #4645
Comments
@mastermunj The |
If you want to override |
Does |
Also, when I try to run migration with Migrating schemas (alter existing schema)
Cannot migrate database schema Error: Invalid type for property mobiles
at Function.ModelClass.registerProperty (/app/node_modules/loopback-datasource-juggler/lib/model-builder.js:556:13)
at ModelBuilder.defineClass [as define] (/app/node_modules/loopback-datasource-juggler/lib/model-builder.js:637:16)
at MongoDataSource.defineClass (/app/node_modules/loopback-datasource-juggler/lib/datasource.js:837:40)
at WorkshopContactPersonRepository.definePersistedModel (/app/node_modules/@loopback/repository/dist/repositories/legacy-juggler-bridge.js:113:39)
at new DefaultCrudRepository (/app/node_modules/@loopback/repository/dist/repositories/legacy-juggler-bridge.js:77:32)
at new EnhancedEntityRepository (/app/dist/repositories-base/enhanced-entity.repository.js:21:9)
at new AuditableEntityRepository (/app/dist/repositories-base/auditable-entity.repository.js:24:9)
at new WorkshopContactPersonRepository (/app/dist/repositories/workshop-contact-person.repository.js:22:9)
at /app/node_modules/@loopback/context/dist/resolver.js:50:16
at Object.transformValueOrPromise (/app/node_modules/@loopback/context/dist/value-promise.js:227:16)
at Object.instantiateClass (/app/node_modules/@loopback/context/dist/resolver.js:45:34)
at /app/node_modules/@loopback/context/dist/binding.js:433:46
at Binding._getValue (/app/node_modules/@loopback/context/dist/binding.js:319:20)
at /app/node_modules/@loopback/context/dist/binding.js:215:29
at /app/node_modules/@loopback/context/dist/resolution-session.js:72:53
at Object.tryWithFinally (/app/node_modules/@loopback/context/dist/value-promise.js:157:18) PS: error is for different attribute @property({
type: 'array',
jsonSchema: {
items: {
"type": "string",
"pattern": "^[6789][0-9]{9}$",
"minLength": 10,
"maxLength": 10
},
uniqueItems: true,
},
}) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I have created an example repo that can showcase the issue better. Please have a look at schema generated for attributes
|
Ref: Openapi Spec - Array, Unique items @mastermunj I see what you're aiming for here, an array with unique items but I'm not sure that Loopback supports this particular route to achieve it. Although you can update the schema to add
@agnes512 @hacksparrow PTAL |
@dougal83 Loopback does support this validation at rest level through ajv. The point I am trying to make here is that if I use Also, migration error states that |
From what I can gather:
Hence, the issue at hand is regarding |
see: loopbackio#4645 Signed-off-by: Rifa Achrinza <[email protected]>
see: loopbackio#4645 Signed-off-by: Rifa Achrinza <[email protected]>
see: loopbackio#4645 Signed-off-by: Rifa Achrinza <[email protected]>
@achrinza Why is this an expected behaviour? If There seems to be no way to ensure unique items right now. |
@InvictusMB Sorry for the delayed reply,
My understanding was that because the generated OpenAPI spec passed Swagger editor validation, that it would result in expected behaviour. However, it seems like that's not the case.
Could you clarify? The ORM works independently of the OpenAPI spec. Just to make sure we're on the same page, I'll need to investigate this further. |
Correct, when
The ORM depends on the same metadata from A proper fix would be to handle
should result in
|
Thanks for the breakdown, @InvictusMB. I agree with most points, though I'd like to take a different approach to fixing the issue: IIRC, properties inside Hence with that in mind, I'd like to propose to keep This applies to other properties that may have the same issue. |
I've got a similar issue, but my issue is related to open API spec generator that I've been using to validate REST requests. |
A workaround is to use |
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the |
Here is the gist of code for easy replication.
Steps to reproduce
Current Behavior
Notice the nested
items
objects created.Expected Behavior
The text was updated successfully, but these errors were encountered: