OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-fetch] allOf with readOnly child parameter: incorrect request interface (missing Omit<...>)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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...
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with modules/openapi-generator/src/test/resources/3_0/allOf-readonly.yaml and reproduce the typescript-fetch output using ./generate_clients.sh. Trace how the generator handles allOf schemas with readOnly properties; done when the generated CreateClubRequest interface uses Omit<Club, 'name'> for the request body.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100