Closed Arathy-sivan closed 3 years ago
@Arathy-sivan, could you please provide more information on how to reproduce this problem? Are you using the todo-jwt
example? Thanks.
@Arathy-sivan You probably didn't see my comment in the other issue. Please see https://loopback.io/doc/en/lb4/changelog.openapi-v3.html#breaking-changes
@Arathy-sivan You probably didn't see my comment in the other issue. Please see https://loopback.io/doc/en/lb4/changelog.openapi-v3.html#breaking-changes
Is this given to "openapi-spec.ts" file??
@Arathy-sivan please share a simple app reproducing the error, I will take a look what's going on.
@Arathy-sivan please share a simple app reproducing the error, I will take a look what's going on.
In the CredentialsRequestBody
variable, change type: string
to type: 'string'
(notice it's a "string" instead of the JavaScript primitive String)
src.zip
Just a friendly heads up, most open source company policies (mine included) disallow downloading unknown ZIP files directly due to security concerns - Please consider creating a GitHub repo that can be cloned by the developers. You can also create a separate GitHub organization just for these things so that it doesn't pollute your main GitHub account - This is what I do with https://github.com/achrinzatest and https://github.com/achrinzafork.
In the
CredentialsRequestBody
variable, changetype: string
totype: 'string'
(notice it's a "string" instead of the JavaScript primitive String)
There is no change in error when changing type
@Arathy-sivan please share the project on GitHub as mentioned by @achrinza.
You need to explicitly enforce the inference. Update the definition of your CredentialsRequestBody
's schema and explicitly type it:
...
import {SchemaObject} from '@loopback/openapi-v3';
...
const CredentialsSchema: SchemaObject = {
type: 'string',
required: [],
properties: {
login: {
type: 'string',
},
password: {
type: 'string',
minLength: 5,
},
},
};
...
const CredentialsRequestBody: SchemaObject = {
...
'application/json': {schema: CredentialsSchema},
...
};
You need to explicitly enforce the inference. Update the definition of your
CredentialsRequestBody
's schema and explicitly type it:... import {SchemaObject} from '@loopback/openapi-v3'; ... const CredentialsSchema: SchemaObject = { type: 'string', required: [], properties: { login: { type: 'string', }, password: { type: 'string', minLength: 5, }, }, }; ... const CredentialsRequestBody: SchemaObject = { ... 'application/json': {schema: CredentialsSchema}, ... };
While executing this code results the error shown below:
{
"resource": "/d:/tech/hr-be/src/controllers/ctr-users.controller.ts",
"owner": "typescript",
"code": "2345",
"severity": 8,
"message": "Argument of type 'SchemaObject' is not assignable to parameter of type 'Partial
@Arathy-sivan I haven't followed all the discussion but looking at
const CredentialsRequestBody: SchemaObject = {
...
'application/json': {schema: CredentialsSchema},
...
};
The type of CredentialsRequestBody
shouldn't be SchemaObject
, but RequestBodyObject
instead.
See an example of RequestBodyObject
in
https://github.com/strongloop/loopback-next/blob/7f764e109a23da5e03f9a0bee93ba0c7c7d21e81/packages/rest/src/__tests__/helpers.ts#L21.
My controller is
How to solve this error?