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] Loses type information when having method that returns different schemas depending on accept-type #20163

Open
4 tasks
HerrDerb opened this issue Nov 22, 2024 · 0 comments

Comments

@HerrDerb
Copy link

HerrDerb commented Nov 22, 2024

Bug Report Checklist

  • [x ] Have you provided a full/minimal spec to reproduce the issue?
  • [x ] Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When having a definition for an endpoint that return different schemas, depending on the accept header, the typescript-angular generator library generates a method that does take either one of the accept headers but only return one type.

public getTenantHealth(tenantId: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/light+json' | 'application/json'}): Observable<TenantHealthLight>;

If application/json is defined as accept header, the method should return a TenantHealth

openapi-generator version

"@openapitools/openapi-generator-cli": "2.15.3"

OpenAPI declaration file content or url
---
openapi: 3.0.3
info:
  title: Reproducer
  description: Reproducer fro overloaeded get method
  version: unspecified
paths:
  /portal/tenant-health/{tenantId}:
    get:
      tags:
      - Tenant health Api
      summary: Get health status for a specific tenant
      description: Get Tenant Health
      operationId: getTenantHealth
      parameters:
      - name: tenantId
        in: path
        required: true
        schema:
          type: string
      responses:
        "200":
          description: OK
          content:
            application/light+json:
              schema:
                $ref: "#/components/schemas/TenantHealthLight"
            application/json:
              schema:
                $ref: "#/components/schemas/TenantHealth"
        "401":
          description: Not Authorized
        "403":
          description: Not Allowed
      security:
      - SecurityScheme: []
components:
  schemas:
    HealthStatus:
      enum:
      - UP
      - DOWN
      type: string
    TenantHealth:
      required:
      - tenant
      - status
      type: object
      properties:
        tenant:
          type: string
        status:
          $ref: "#/components/schemas/HealthStatus"
    TenantHealthLight:
      required:
      - tenant
      type: object
      properties:
        tenant:
          type: string
  securitySchemes:
    SecurityScheme:
      type: openIdConnect
      description: Authentication
      openIdConnectUrl: https://openId
Generation Details

openapi-generator-cli generate -i openapi/api.yaml -g typescript-angular -o generated-sources/openapi/api

Steps to reproduce

Simply generate

Suggest a fix

Generate a typescript method, for each acceptType/schema if there are multiple
E.g. for given spec:

public getTenantHealthTenantHealthLight(tenantId: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/light+json'}): Observable<TenantHealthLight>;
public getTenantHealthTenantHealth(tenantId: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?:  'application/json'}): Observable<TenantHealth>;
@HerrDerb HerrDerb changed the title [BUG] [Typescript-angular] [BUG] [Typescript-angular] Loses type information when having method that returns different schemas depending on accept-type Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant