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][typescript-angular] oneOf and anyOf generates incorrect model for primitive types #4130

Closed
snebjorn opened this issue Oct 11, 2019 · 5 comments · Fixed by #4341
Closed

Comments

@snebjorn
Copy link
Contributor

Description

Using oneOf or anyOf will generate a model with incorrect imports and wrong types.

import { boolean } from "./boolean";
import { Number } from "./number";
import { string } from "./string";
import { array } from "./array";
import { integer } from "./integer";
import { object } from "./object";

export interface Foo {
  id?: string;
  xxx?: Number | string | boolean | array | object | integer;
  yyy?: Number | string | boolean | array | object | integer;
}
  • All the imports are incorrect. None of them should be imported.
  • Number is incorrect. It's number and it should not be imported.
  • integer is incorrect. It's number and should be merged with number. It should not be imported.
  • array is incorrect. It's Array<T> or T[]. So in this example it should have been Array<string> or string[]. It should not be imported.

The expected model is:

// no imports

export interface Foo {
  id?: string;
  xxx?: number | string | boolean | string[] | object;
  yyy?: number | string | boolean | string[] | object;
}
openapi-generator version

openapi-generator v4.1.3

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Foo
  version: '0001'
  description: The description
paths:
  /FooSet:
    get:
      summary: Get entities from FooSet
      responses:
        '200':
          description: Retrieved entities
          content:
            application/json:
              schema:
                type: object
                properties:
                  value:
                    type: array
                    items:
                      $ref: '#/components/schemas/NAMESPACE.Foo'
components:
  schemas:
    NAMESPACE.Foo:
      type: object
      properties:
        id:
          type: string
        xxx:
          anyOf:
            - type: string
            - type: number
            - type: boolean
            - type: array
              items:
                type: string
            - type: object
            - type: integer
        yyy:
          oneOf:
            - type: string
            - type: number
            - type: boolean
            - type: array
              items:
                type: string
            - type: object
            - type: integer
      title: Foo
Command line used for generation

npx openapi-generator generate -g typescript-angular -i openapi.yaml-o out/test

Steps to reproduce

Generate a typescript client using the above yaml.

Related issues/PRs

There appears to be a lot of issues related to oneOf and anyOf. But couldn't find any specifically about this.

@auto-labeler
Copy link

auto-labeler bot commented Oct 11, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

macjohnny pushed a commit that referenced this issue Oct 31, 2019
… primitive types (#4341)

* [typescript-angular] Fix importMapping;

#3149

* [typescript] Fix oneOf/anyOf/allOf;

#4130

* [typescript] remove unneeded mapping

#3149

* [typescript] fix import paths and export

#3149
@HighSoftWare96
Copy link

This actually happened another time....
I'm generating a schema like this:

// ... schema
          schema: {
            oneOf: [
              { type: 'integer', format: 'int32' },
              { type: 'string' }
            ]
          }

And the generated SDK imports something like this:

import {string | number} from 'models/models';

image
Any thoughts on this? This is a blocking issue...

@macjohnny
Copy link
Member

@HighSoftWare96 would you like to give it a try and find a fix for this?

@HighSoftWare96
Copy link

I don't know even where I should start... Maybe someone more competent about this can try

@tz1010
Copy link

tz1010 commented Apr 29, 2022

It's still not working for typescript-angular generator 🤔 Is this a general issue related to the generator?
AnyOf for an array type is generating this with the latest beta version:

import { number } from './number';
import { boolean } from './boolean';
import { string } from './string';

export interface SomeClass { 
    group: Array<string | number | boolean>;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants