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-fetch] namespacing the generated request object types #3695

Merged

Conversation

jgiles
Copy link
Contributor

@jgiles jgiles commented Aug 19, 2019

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.

Description of the PR

Fix #1998 by namespacing the generated request object types used in the typescript-fetch client codegen.

jgiles added 2 commits August 19, 2019 18:12
Fix OpenAPITools#1998 by namespacing the generated request object types used in the
typescript-fetch client codegen.
@auto-labeler
Copy link

auto-labeler bot commented Aug 19, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@macjohnny
Copy link
Member

cc @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @nicokoenig (2018/09) @topce (2018/10) @akehir (2019/07)

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.

this is a breaking change, so this should either be configurable or we have to wait until 5.x to include it.

@macjohnny
Copy link
Member

cc @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @nicokoenig (2018/09) @topce (2018/10) @akehir (2019/07)

@macjohnny
Copy link
Member

@jgiles thanks for your PR!

unset
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why the version is clobbered when I run the sample code re-generation. I can manually undo if necessary.

Copy link
Member

Choose a reason for hiding this comment

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

are you sure you ran mvn clean package before generating the samples? are you based on the latest master?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm based on 024f468 (master circa 2019-08-18).

If I run

mvn clean package
./bin/typescript-fetch-petstore-all.sh

on my current branch (where the .openapi-generator/VERSION files already have "unset"), no sample files are changed. If I run it on master, the .openapi-generator/VERSION files are overwritten to "unset".

FWIW, I (but no one else on my team) had this problem when running a brew-installed jar of of the old swagger-codegen, which is part of why we switched to running it in Docker... there could just be something weird in my local env.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed manually

@jgiles
Copy link
Contributor Author

jgiles commented Aug 20, 2019

@macjohnny thanks for the speedy review!

Per your suggestion, I have introduced a new CLI option for namespacing the request objects. I patterned the added option after existing options in the codegen class, let me know if adjustments are needed.

Currently, the option defaults to false so that this would be mergeable into master for inclusion in the next patch release (I'm interested in making this available as soon as possible, since the fixed issue blocks my team's migration from the old swagger-codegen). However, it might be worth considering:

  • Making the option default to true in the next minor release branch
  • Removing the option in the 5.0 major release branch

so that the fix is present by default.

@macjohnny
Copy link
Member

@jgiles thanks for the changes! I will review them soon

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 added this to the 4.1.1 milestone Aug 20, 2019
@macjohnny
Copy link
Member

@jgiles I think we can merge this and have this released in 4.1.1
if you want you could copy and adapt the existing builds and/or tests to have your feature compiled/tested by CI and prevent regressions, see e.g.

openapi-generator/pom.xml

Lines 834 to 845 in 4575b30

<profile>
<id>typescript-fetch-client-builds-with-npm-version</id>
<activation>
<property>
<name>env</name>
<value>java</value>
</property>
</activation>
<modules>
<module>samples/client/petstore/typescript-fetch/builds/with-npm-version</module>
</modules>
</profile>

https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/typescript-fetch/builds/with-npm-version/pom.xml

@macjohnny
Copy link
Member

@jgiles
Copy link
Contributor Author

jgiles commented Aug 20, 2019

I will add the Maven builds, and will check about adding company name :-)

(I'm dropping offline for a little bit though, so it will be this evening probably)

@jgiles
Copy link
Contributor Author

jgiles commented Aug 20, 2019

@macjohnny added the maven builds, fixed the version files.

@jgiles
Copy link
Contributor Author

jgiles commented Aug 21, 2019

There's a build failure in the Maven stuff. The error looks to be for a different typescript-fetch sample, but I think the new one might also have problems. There's a bit of messiness in the setup of the sample tests, I might need some help getting that bit right.

@macjohnny
Copy link
Member

@jgiles the travis-error seems unrelated, but you need to register your pom.xml here:

openapi-generator/pom.xml

Lines 834 to 845 in 4575b30

<profile>
<id>typescript-fetch-client-builds-with-npm-version</id>
<activation>
<property>
<name>env</name>
<value>java</value>
</property>
</activation>
<modules>
<module>samples/client/petstore/typescript-fetch/builds/with-npm-version</module>
</modules>
</profile>

moreover, the package.json is missing to successfully run npm install or npm run build in https://github.com/OpenAPITools/openapi-generator/tree/dddc201f05e7167651c012c55742bae0179b5b30/samples/client/petstore/typescript-fetch/builds/namespace-parameter-interfaces, so I would recommend setting the npmVersion in https://github.com/OpenAPITools/openapi-generator/blob/dddc201f05e7167651c012c55742bae0179b5b30/bin/typescript-fetch-petstore-multiple-parameters.json similar to https://github.com/OpenAPITools/openapi-generator/blob/dddc201f05e7167651c012c55742bae0179b5b30/bin/typescript-fetch-petstore-with-npm-version.json

If we don't manage to have the CI tests run, I would recommend to merge it without them, so this can be part of the next release, and add the CI tests in a separate PR.

@jgiles
Copy link
Contributor Author

jgiles commented Aug 21, 2019

Thanks @macjohnny for the pointers!

I am registering the pom.xml here: https://github.com/OpenAPITools/openapi-generator/pull/3695/files#diff-600376dffeb79835ede4a0b285078036R846

I'm now doing the codegen for CI in the same way as the with-npm-version variant, which does produce the needed package.json. Hopefully that will resolve the build issues.

@jgiles
Copy link
Contributor Author

jgiles commented Aug 21, 2019

I would also be OK merging without the CI. What needs to happen in order to merge?

@jgiles
Copy link
Contributor Author

jgiles commented Aug 21, 2019

@macjohnny also added Paxos to the list of companies using openapi-generator!

@macjohnny
Copy link
Member

I would also be OK merging without the CI. What needs to happen in order to merge?

I will merge it tomorrow if the ci build succeeds

@macjohnny
Copy link
Member

Can you please merge the most recent master into your branch? The unrelated typescript-axios build failure should be disabled

@jgiles
Copy link
Contributor Author

jgiles commented Aug 21, 2019

Merged in latest master

@jgiles
Copy link
Contributor Author

jgiles commented Aug 22, 2019

Using the "Requests" name invariably led to name conflicts between the Requests namespaces when there were multiple services (tags). This issue did reproduce in petstore - I'm not sure why CI didn't catch the compilation error.

I've updated to use the service basename as a prefix (like "PetRequests")

operations.put("namespaceParameterInterfaces", true);
operations.put("paramIfaceIndent", " ");
operations.put("paramIfaceSuffix", "");
operations.put("paramIfaceNsPrefix", "Requests.");
operations.put("paramIfaceNsPrefix", operationList.get(0).baseName + "Requests.");
Copy link
Member

Choose a reason for hiding this comment

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

maybe this has to be sanitized, but we will see later

@macjohnny macjohnny merged commit b323b0a into OpenAPITools:master Aug 22, 2019
@wing328 wing328 changed the title [typescript-fetch] Fix #1998: namespace reqs. [typescript-fetch] namespace reqs. Aug 26, 2019
@wing328 wing328 changed the title [typescript-fetch] namespace reqs. [typescript-fetch] namespacing the generated request object types Aug 26, 2019
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-fetch] Request Parameter Interfaces Conflict with remove-operation-id-prefix
2 participants