Skip to content

typescript-jquery: Update to work with Typescript strict mode #3969

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

Merged
merged 2 commits into from
Oct 21, 2019

Conversation

janjongboom
Copy link
Contributor

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @nicokoenig @topce @akehir

Description of the PR

When compiling an API generated using the typescript-jquery generator against Typescript 3.6.2 in strict mode there are a number of issues with the generated code.

  • defaultExtraJQueryAjaxSettings is of type JQueryAjaxSettings | undefined but is set to null (valid in normal mode, not valid in strict mode).
  • In extendObj hasOwnProperty is called on objB. But objB is not guaranteed to be an object as it inherits from unknown type T1.
  • Properties in the Configuration class are marked as string, but have no initializer, thus giving false safety when consuming this class (values could be undefined too).

This PR adds some small guards around these issues.

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.

Thanks for the PR

*/
public addPet(body: models.Pet, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQuery.Promise<
public addPet(pet: models.Pet, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQuery.Promise<
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed.

@@ -39,7 +39,7 @@ export class PetApi {

private extendObj<T1, T2 extends T1>(objA: T2, objB: T2): T1|T2 {
for (let key in objB) {
if (objB.hasOwnProperty(key)) {
if (objB[key]) {
Copy link
Member

Choose a reason for hiding this comment

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

where does this change come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm... That should not be there, something went wrong with rebasing. Will repush.

@janjongboom
Copy link
Contributor Author

@macjohnny Pushed changes as requested.

@@ -0,0 +1,26 @@
/**
* OpenAPI Petstore
Copy link
Member

Choose a reason for hiding this comment

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

Please delete this file


export interface InlineObject {
/**
* Updated name of the pet
Copy link
Member

Choose a reason for hiding this comment

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

Please delete this file


import * as models from './models';

export interface InlineObject1 {
Copy link
Member

Choose a reason for hiding this comment

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

Please delete this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@macjohnny Removed and re-pushed. However, these were generated by the tool, so interesting to see where they'd come from.

Copy link
Member

Choose a reason for hiding this comment

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

these files are generated with the bin/openapi3/typescript-fetch-petstore-all.sh command. the output is supposed to be the same as with bin/typescript-fetch-petstore-all.sh, but it isn't, so it needs to be addressed in a separate issue.

Copy link
Member

Choose a reason for hiding this comment

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

CI currently checks against the output of bin/typescript-fetch-petstore-all.sh

@wing328 wing328 modified the milestones: 4.1.3, 4.2.0 Oct 4, 2019
@janjongboom
Copy link
Contributor Author

Rebased and pushed to restart tests.

@@ -0,0 +1,26 @@
/**
Copy link
Member

Choose a reason for hiding this comment

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

please delete this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@macjohnny I'm not sure where these come from, but the file is referenced in https://github.com/OpenAPITools/openapi-generator/pull/3969/files/c99fcd7b5936800b4ef0d38e92ebd27dc86fadcb#diff-969fc1a4f92fd269b7aac842f2049bb7R15 as well. This is just the output of the build step.

*/
public async addPet (body: Pet, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> {
Copy link
Member

Choose a reason for hiding this comment

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

this is unrelated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to above. Apparently something was landed earlier but the samples weren't updated (generated by the build script). I'm happy to revert this file back to master but shouldn't samples always be reflective of the latest version of the tool?

Copy link
Member

Choose a reason for hiding this comment

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

I will update your branch with the correct samples

@macjohnny
Copy link
Member

@janjongboom I cleaned the samples in your branch. By the way: no need to re-base, PRs are squashed.

@janjongboom
Copy link
Contributor Author

@macjohnny OK, thanks!

@macjohnny macjohnny merged commit 1052eba into OpenAPITools:master Oct 21, 2019
@wing328
Copy link
Member

wing328 commented Oct 31, 2019

@janjongboom thanks for the PR, which has been included in v4.2.0 release: https://twitter.com/oas_generator/status/1189824932345069569

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.

3 participants