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] fix: deno: type exports for isolatedModules #19484

Merged

Conversation

joscha
Copy link
Contributor

@joscha joscha commented Aug 29, 2024

When generating code with typescript that contains request objects for the deno platform the following type error is produced in the generated code:
Screenshot 2024-08-29 at 10 18 44 AM

Deno has isolatedModules enabled by default and it can not be disabled (see denoland/deno#12599 (comment)).
Thus imports that are reexported need to have the type keyword.

A similar change has been made in #826.

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/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
  • File the PR against the correct branch: master (upcoming 7.6.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the [technical committee]: @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) @davidgamero (2022/03) @mkusaka (2022/04)

@@ -16,7 +16,7 @@ export { Middleware } from './middleware{{importFileExtension}}';
export{{#platforms}}{{#deno}} type{{/deno}}{{/platforms}} { PromiseMiddleware as Middleware } from './middleware{{importFileExtension}}';
{{/useRxJS}}
{{#useObjectParameters}}
export { {{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}{{classname}}{{operationIdCamelCase}}Request, {{/operation}}Object{{classname}} as {{classname}}{{^-last}}, {{/-last}} {{/operations}}{{/apis}}{{/apiInfo}}} from './types/ObjectParamAPI{{importFileExtension}}';
export { {{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}{{#platforms}}{{#deno}}type {{/deno}}{{/platforms}}{{classname}}{{operationIdCamelCase}}Request, {{/operation}}Object{{classname}} as {{classname}}{{^-last}}, {{/-last}} {{/operations}}{{/apis}}{{/apiInfo}}} from './types/ObjectParamAPI{{importFileExtension}}';
Copy link
Contributor Author

@joscha joscha Aug 29, 2024

Choose a reason for hiding this comment

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

this is the meaningful change of this PR.

It makes sure that any re-exported request object is exported with the type keyword, e.g.

export { AuthApiXRequest, ObjectAuthApi as AuthApi } from './types/ObjectParamAPI.ts';

becomes

export { type AuthApiXRequest, ObjectAuthApi as AuthApi } from './types/ObjectParamAPI.ts';

e.g. meaning

export {
-  AuthApiXRequest,
+  type AuthApiXRequest,
   ObjectAuthApi as AuthApi
} from './types/ObjectParamAPI.ts';

An alternative, possibly more readable implementation would be to split the type exports from the classes, e.g.:

export { ObjectAuthApi as AuthApi, ObjectBlaApi as BlaApi } from './types/ObjectParamAPI.ts';
export type { AuthApiXRequest, BlaApiXRequest } from './types/ObjectParamAPI.ts';

export { RequiredError } from "./apis/baseapi.ts";

export type { PromiseMiddleware as Middleware } from './middleware.ts';
export { type PetApiAddPetRequest, type PetApiDeletePetRequest, type PetApiFindPetsByStatusRequest, type PetApiFindPetsByTagsRequest, type PetApiGetPetByIdRequest, type PetApiUpdatePetRequest, type PetApiUpdatePetWithFormRequest, type PetApiUploadFileRequest, ObjectPetApi as PetApi, type StoreApiDeleteOrderRequest, type StoreApiGetInventoryRequest, type StoreApiGetOrderByIdRequest, type StoreApiPlaceOrderRequest, ObjectStoreApi as StoreApi, type UserApiCreateUserRequest, type UserApiCreateUsersWithArrayInputRequest, type UserApiCreateUsersWithListInputRequest, type UserApiDeleteUserRequest, type UserApiGetUserByNameRequest, type UserApiLoginUserRequest, type UserApiLogoutUserRequest, type UserApiUpdateUserRequest, ObjectUserApi as UserApi } from './types/ObjectParamAPI.ts';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the meaningful change in the generated fixture. Please let me know if you prefer to introduce some newlines between the different imports/exports, which would make this a lot more readable, but also would increase the diff of this PR, because it would affect other samples as well.

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 your contribution!

@macjohnny macjohnny merged commit 1518237 into OpenAPITools:master Aug 29, 2024
15 checks passed
@wing328 wing328 added this to the 7.9.0 milestone Oct 7, 2024
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