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] AllOf hierarchy produces api that doesn't compile #8000

Closed
tschmidt01 opened this issue Nov 22, 2020 · 5 comments · Fixed by #9275
Closed

[BUG] [typescript-angular] AllOf hierarchy produces api that doesn't compile #8000

tschmidt01 opened this issue Nov 22, 2020 · 5 comments · Fixed by #9275

Comments

@tschmidt01
Copy link

OpenAPI Spec

openapi: 3.0.3

info:
  title: Demo
  version: 1.0.0
  description: Demo

paths:
  /some-path:
    post:
      operationId: create
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExtendedTransferObjectRequest'
      responses:
        201:
          description: some description
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExtendedTransferObjectResponse'

components:
  schemas:
    TransferObject:
      type: object
      properties:
        id:
          type: string
          format: uuid
    ExtendedTransferObject:
      type: object
      allOf:
        - $ref: '#/components/schemas/TransferObject'
        - type: object
      required:
        - some-field
      properties:
        some-field:
          type: string
    ExtendedTransferObjectRequest:
      type: object
      allOf:
        - $ref: '#/components/schemas/ExtendedTransferObject'
        - type: object
    ExtendedTransferObjectResponse:
      type: object
      allOf:
        - $ref: '#/components/schemas/ExtendedTransferObject'
        - type: object

Generated with

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:latest generate -i /local/sample.yml -g typescript-angular -o /local/build

Results in a default.service.ts file with a invalid import statement along with unused class ExtendedTransferObject:

import { ExtendedTransferObject & object } from '../model/models';
@auto-labeler
Copy link

auto-labeler bot commented Nov 22, 2020

👍 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.

@mitsuru793
Copy link

I have the trouble, me too.
I use a template of typescript-fetch.
So, I can't use allOf.

@jon-v
Copy link

jon-v commented Jan 8, 2021

I'm also observing the same issue in typescript-fetch. As far as I can tell it seems general to all allOf constructions. It correctly generates an intersection type, but there seem to be two issues with the generated code:
1: The type intersection operator & is generated as &, which obviously doesn't compile.
2: It attempts to use the intersection type definition directly in the import statement from models.

It might be worth pointing out that the same bug is not present in typescript-axios. Issue 1 described above is not occurring there (it correctly generates &), and 2 is a non-issue because the typescript-axios client puts models and API together in one big file.

@cl1ck
Copy link

cl1ck commented Jan 8, 2021

It might be worth pointing out that the same bug is not present in typescript-axios. Issue 1 described above is not occurring there (it correctly generates &), and 2 is a non-issue because the typescript-axios client puts models and API together in one big file.

I'm using typescript-axios and have both issues with the following configuration

{
  "withSeparateModelsAndApi": true,
  "apiPackage": "api",
  "modelPackage": "model",
  "useSingleRequestParameter": true,
  "generateAliasAsModel": true
}

...and an anonymous schema for the response

      responses:
        201:
          description: some description
          content:
            application/json:
              schema:
-               $ref: '#/components/schemas/ExtendedTransferObjectResponse'
+              type: object
+              allOf:
+                - $ref: '#/components/schemas/ExtendedTransferObject'
+                - type: object

@Webjin
Copy link

Webjin commented Apr 13, 2021

Any news on this issue?

ralphpig added a commit to ralphpig/openapi-generator that referenced this issue Apr 16, 2021
`toModelImportMap` only accounts for union types and not intersection types, so I've combined those cases into `splitComposedType`. For `splitComposedType` I combined `replace(" ","").split("\\|")` and `split("( [|&] )|[<>]")` into `replace(" ","").split("[|&<>]")`.

I've added the `needToImport` check to `toModelImportMap`. This is the same check that happens in `addImport`.
macjohnny pushed a commit that referenced this issue Jun 4, 2021
`toModelImportMap` only accounts for union types and not intersection types, so I've combined those cases into `splitComposedType`. For `splitComposedType` I combined `replace(" ","").split("\\|")` and `split("( [|&] )|[<>]")` into `replace(" ","").split("[|&<>]")`.

I've added the `needToImport` check to `toModelImportMap`. This is the same check that happens in `addImport`.
tiagoblackcode added a commit to tiagoblackcode/openapi-generator that referenced this issue Oct 27, 2021
…client

The `AbstractTypeScriptClientCodegen` is very similar to the `TypeScriptClientCodegen`. However, they have been kept separate and some fixes brought to the former are not present on the latter.

This change makes  `TypescriptClientCodegen` extend from `AbstractTypeScriptClientCodegen` to re-use most of the common logic. Similar methods and CLI options were removed from `TypescriptClientCodegen`.

The `NPM_REPOSITORY` flag was kept in the typescript client, although it might be sensible to move it to the abstract client and make other typescript-based generators benefit from it.

In particular, this change fixes the issue OpenAPITools#8000 for the `typescript` generator which was merged by OpenAPITools#9275.
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.

5 participants