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

[Bug] Error with arrays and ValidatorFunctions #2

Closed
BastiOfBerlin opened this issue Dec 17, 2018 · 5 comments · Fixed by #10
Closed

[Bug] Error with arrays and ValidatorFunctions #2

BastiOfBerlin opened this issue Dec 17, 2018 · 5 comments · Fixed by #10
Assignees
Labels
bug Something isn't working

Comments

@BastiOfBerlin
Copy link
Contributor

Hi,

I've got a 'People' model which is simply an array of persons:

People:
  type: array
  items:
    $ref: "#/components/schemas/Person"

This generates export const PeopleValidators: {[K in keyof People]: Array<ValidatorFn>} = { };, which results in the following transpilation error:

ERROR in src/app/core/generated/api/model/people.ts(30,14): error TS2322: Type '{}' is not assignable to type '{ [x: number]: ValidatorFn[]; length: ValidatorFn[]; toString: ValidatorFn[]; toLocaleString: ValidatorFn[]; pop: ValidatorFn[]; push: ValidatorFn[]; concat: ValidatorFn[]; join: ValidatorFn[]; reverse: ValidatorFn[]; ... 21 more ...; includes: ValidatorFn[]; }'. Property 'length' is missing in type '{}'.

I don't know if simply assigning null instead of empty object conflicts with the form-control-factory, so I didn't try..

I assume that this error will occur with every object that doesn't have own properties.

@malaupa
Copy link
Collaborator

malaupa commented Dec 18, 2018

Hopefully, we will have a look at this before Xmas. This should be fixed.

@malaupa malaupa added the bug Something isn't working label Dec 18, 2018
@malaupa malaupa self-assigned this Dec 18, 2018
@malaupa
Copy link
Collaborator

malaupa commented Dec 18, 2018

@BastiOfBerlin could you please test, if the fix works for your problem?

@BastiOfBerlin
Copy link
Contributor Author

Interestingly, the issue seemed to have vanished by using the newer generator as the problematic people.ts isn't generated at all. Instead, the API service implements the return type directly as Observable<Array>.

But to answer your question: I fiddled around and cherry-picked your fix into the old 1.2.0 release and YES, making the validator property optional worked just fine!

@cogidoo
Copy link
Collaborator

cogidoo commented Dec 18, 2018

This bug is indeed solved with 3.3.4 of openapitools-generator (see #1296).

@malaupa
Copy link
Collaborator

malaupa commented Dec 18, 2018

@cogidoo regardless the fix of the generator, we should merge. I think it should be possible to create a factory only with a fewer count of properties and their validators. Does the optional flag break something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants