Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG][typescript-fetch] allOf with readOnly child parameter: incorrect request interface (missing Omit<...>) #19618

Open
5 of 6 tasks
Umdrahschua opened this issue Sep 18, 2024 · 0 comments

Comments

@Umdrahschua
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • 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

There is a POST request and the body uses allOf to combine different structs. If there is a read-only property in a struct, then the generated interface is incorrectly.

It generates:

export interface CreateClubRequest {
    personId: string;
    club?: Club;
}

but it is expected.

export interface CreateClubRequest {
    personId: string;
    club?: Omit<Club, 'name'>;
}

(By the way, it works perfectly if I change the OpenAPI file to:

...
components:
  schemas:
    club:
      properties:
        name:
          readOnly: true
          type: string
          maxLength: 255
        street:
          type: string
          maxLength: 255

)

openapi-generator version

7.9.0-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  version: 1.0.0
  title: Example
  license:
    name: MIT
servers:
  - url: http://api.example.xyz/v1
paths:
  /person/display/{personId}:
    post:
      parameters:
        - name: personId
          in: path
          required: true
          description: The id of the person to retrieve
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/club"
      operationId: createClub
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/club"
components:
  schemas:
    club:
      allOf:
        - $ref: '#/components/schemas/owner'
        - $ref: '#/components/schemas/address'

    owner:
      properties:
        name:
          readOnly: true
          type: string
          maxLength: 255

    address:
      properties:
        street:
          type: string
          maxLength: 255
Generation Details + Steps to reproduce

I simple updated modules/openapi-generator/src/test/resources/3_0/allOf-readonly.yaml and run ./generate_clients.sh from this git repository

Related issues/PRs
Suggest a fix

I tried to debug it, but I only find out, that there is some information is missing...

Looks like it is not so simple to implement read-only and write-only perfectly...

@Umdrahschua Umdrahschua changed the title [BUG] Description [BUG][typescript-fetch] allOf with readOnly child parameter: incorrect request interface (missing Omit<...>) Sep 19, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant