OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Typescript] Body property is named with the type name

Open
#7,886 4 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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?
Description

See examples below

openapi-generator version

5.0.0-SNAPSHOT but I have the bug since the 5.0.0beta docker image.

OpenAPI declaration file content or url
openapi: 3.0.0
info:
    title: entity-manager
    version: unknown
paths:
    /companies/defaults:
        post:
            parameters: []
            responses:
                '200':
                    description: Ok
                    content:
                        application/json:
                            schema:
                                type: object
                                properties:
                                    status: {type: string, enum: [success]}
                                    program: {type: string}
                                    version: {type: string}
                                    datetime: {type: string}
                                    code: {type: number}
                                    message: {type: string}
                                required:
                                    - status
                                    - program
                                    - version
                                    - datetime
                                    - message
            tags:
                - Company
            requestBody:
                required: true
                content:
                    application/json:
                        schema:
                            $ref: '#/components/schemas/Partial__roleId-string--resourceGroupIds-string-Array--__'
            operationId: set-company-defaults
components:
    schemas:
        Partial__roleId-string--resourceGroupIds-string-Array--__:
            type: object
            properties:
                roleId:
                    type: string
                resourceGroupIds:
                    type: array
                    items:
                        type: string

Generation Details
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:latest generate \
            --additional-properties=useSingleRequestParameter=true,enumPropertyNaming=UPPERCASE \
            -i /local/swagger.yaml \
            -g typescript-axios \
            -o /local/client

Results in:

/**
 * Request parameters for setCompanyDefaults operation in CompanyApi.
 * @export
 * @interface CompanyApiSetCompanyDefaultsRequest
 */
export interface CompanyApiSetCompanyDefaultsRequest {
    /**
     * 
     * @type {PartialRoleIdStringResourceGroupIdsStringArray}
     * @memberof CompanyApiSetCompanyDefaults
     */
    readonly partialRoleIdStringResourceGroupIdsStringArray: PartialRoleIdStringResourceGroupIdsStringArray
}

/**
 * CompanyApi - object-oriented interface
 * @export
 * @class CompanyApi
 * @extends {BaseAPI}
 */
export class CompanyApi extends BaseAPI {
    /**
     * 
     * @param {CompanyApiSetCompanyDefaultsRequest} requestParameters Request parameters.
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof CompanyApi
     */
    public setCompanyDefaults(requestParameters: CompanyApiSetCompanyDefaultsRequest, options?: any) {
        return CompanyApiFp(this.configuration).setCompanyDefaults(requestParameters.partialRoleIdStringResourceGroupIdsStringArray, options).then((request) => request(this.axios, this.basePath));
    }
}

Where we can see we have CompanyApiSetCompanyDefaultsRequest.partialRoleIdStringResourceGroupIdsStringArray instead of CompanyApiSetCompanyDefaultsRequest.body.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with swagger.yaml and the provided Docker command using the typescript-axios generator. Inspect the generated CompanyApi request parameter and trace why the request-body property uses the schema-derived name; done means it is exposed as body while preserving the generated request handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.