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

[typescript-axios] Fix model property naming #10447

Merged

Conversation

aiven-hh
Copy link
Contributor

@aiven-hh aiven-hh commented Sep 22, 2021

The property names in typescript-axios models were using formatted names instead of baseName and the template has no mapping to original baseName so this PR introduces a fix by:

  • removing MODEL_PROPERTY_NAMING option from typescript-axios generator as this was never supported
  • using baseName in model properties wrapped with '' for now to support at least all characters except '

This should fix #9524.

Also adds fake petstore example to be able verify these changes at least by eye, see samples/client/petstore/typescript-axios/builds/test-petstore/api.ts and SpecialModelName interface as an example.

In addition adds typing for options that was typed as any before.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@aiven-hh
Copy link
Contributor Author

@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02)

Copy link
Member

@macjohnny macjohnny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGtM

@macjohnny
Copy link
Member

@aiven-hh can you please resolve merge the latest master and re-generate the samples?

Disables MODEL_PROPERTY_NAMING for typescript-axios generator as this
was never supported (templates have no mapping between original property
names and formatted names). Wraps all properties in model interfaces
with '' to support most characters except ' for now. Also fixes missing
options typing that was any before.
@aiven-hh aiven-hh force-pushed the fix-typescript-axios-properties branch from 34a8637 to ef3c20b Compare September 29, 2021 08:15
@aiven-hh
Copy link
Contributor Author

Rebased, all major changes still in the first commit. New sample and ./mvnw clean package && ./bin/generate-samples.sh changes in the second commit and ./mvnw clean package && ./bin/utils/export_docs_generators.sh in the third commit.

Copy link
Member

@macjohnny macjohnny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@macjohnny macjohnny merged commit 755359c into OpenAPITools:master Oct 2, 2021
@macjohnny macjohnny added this to the 5.3.0 milestone Oct 2, 2021
@macjohnny
Copy link
Member

@aiven-hh thanks for your contribution. One minir thing: if the model property name contains a dot, it is still converted to underscore

@wing328
Copy link
Member

wing328 commented Oct 2, 2021

Looks like this breaks the build:

Run `npm audit` for details.

> typescript-fetch-test@1.0.0 build
> tsc

../../builds/with-npm-version/api.ts(287,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(331,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(372,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(414,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(451,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(490,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(542,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(594,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(949,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(982,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(1016,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(1051,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(1254,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(1290,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(1326,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(1361,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(1395,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(1439,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(1469,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
../../builds/with-npm-version/api.ts(1508,77): error TS2339: Property 'query' does not exist on type 'AxiosRequestConfig'.
npm ERR! code 2
npm ERR! path /home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/typescript-axios/tests/default
npm ERR! command failed
npm ERR! command sh -c npm install ../../builds/with-npm-version && npm run build

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/travis/.npm/_logs/2021-10-02T06_31_56_428Z-debug.log
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (npm-install) on project TypeScriptAxiosPestoreClientTests: Command execution failed. Process exited with an error: 2 (Exit value: 2) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (npm-install) on project TypeScriptAxiosPestoreClientTests: Command execution failed.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)

Ref: https://app.travis-ci.com/github/OpenAPITools/openapi-generator/builds/238968898

Can you please take a look when you've time?

@aiven-hh
Copy link
Contributor Author

aiven-hh commented Oct 2, 2021

@wing328 Hmm, the change exposed another bug in the original templates, the generated code uses options.query when axios does not actually use query for query params but params.

@aiven-hh
Copy link
Contributor Author

aiven-hh commented Oct 2, 2021

@macjohnny are you sure? If you check the original example here:

_special_model.name_:
properties:
'$special[property.name]':
type: integer
format: int64
'_special_model.name_':
type: string
and the generated sample
export interface SpecialModelName {
/**
*
* @type {number}
* @memberof SpecialModelName
*/
'$special[property.name]'?: number;
/**
*
* @type {string}
* @memberof SpecialModelName
*/
'_special_model.name_'?: string;
}
it looks fine to me.

@macjohnny
Copy link
Member

@aiven-hh would you like to provide a fix? Or should we first revert the PR?

@aiven-hh
Copy link
Contributor Author

aiven-hh commented Oct 2, 2021

Whatever you prefer, I can send the fix pr in a few minutes after I verify the fix.

@aiven-hh
Copy link
Contributor Author

aiven-hh commented Oct 2, 2021

@macjohnny the fix is now in #10512

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] [typescript-axios] [modelPropertyNaming] original config does not save name with dot delimiter
3 participants