Skip to content

fix: import breaks types (?) #2076#2201

Closed
Prthmsh7 wants to merge 2 commits intoasyncapi:masterfrom
Prthmsh7:importAnonymousSchemaXbreakstypes
Closed

fix: import breaks types (?) #2076#2201
Prthmsh7 wants to merge 2 commits intoasyncapi:masterfrom
Prthmsh7:importAnonymousSchemaXbreakstypes

Conversation

@Prthmsh7
Copy link

@Prthmsh7 Prthmsh7 commented Mar 6, 2025

Description

I tried fixing this issue #2076 by correcting how nested anonymous schemas are imported when using the --pyDantic flag. Previously, the generator produced code like:

from . import AnonymousSchema15

class AnonymousSchema13(BaseModel): 
  command: Optional[str] = Field(default=None)
  meta: Optional[AnonymousSchema15.AnonymousSchema15] = Field(default=None)

which led to runtime type errors. With this fix, the import is now explicit:

from .AnonymousSchema15 import AnonymousSchema15

class AnonymousSchema13(BaseModel): 
  command: Optional[str] = Field(default=None)
  meta: Optional[AnonymousSchema15] = Field(default=None)

This change ensures that Pydantic can properly evaluate the type hints.

Related Issue

(ref. asyncapi/cli#1485)

Checklist

  • [✅] The code follows the project's coding standards and is properly linted (npm run lint).
  • [✅] Tests have been added or updated to cover the changes.
  • [✅] Documentation has been updated to reflect the changes.
  • [✅] All tests pass successfully locally.(npm run test).
    bug-solved

Additional Notes

This is my first time working with the tests and on such a large scale, so please review the changes thoroughly

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@netlify
Copy link

netlify bot commented Mar 6, 2025

Deploy Preview for modelina canceled.

Name Link
🔨 Latest commit bce8035
🔍 Latest deploy log https://app.netlify.com/sites/modelina/deploys/67c9bb2f4cb547000840decd

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 6, 2025

@Prthmsh7 Prthmsh7 changed the title fixed [BUG] from . import AnonymousSchemaX breaks types (?) #2076 A bug fix of import AnonymousSchemaX breaks types (?) #2076 Mar 6, 2025
@jonaslagoni jonaslagoni changed the title A bug fix of import AnonymousSchemaX breaks types (?) #2076 fix: import breaks types (?) #2076 Mar 6, 2025
Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

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

Please revert your package changes as this fix should not require it 🙂

@coveralls
Copy link

Pull Request Test Coverage Report for Build 13701869542

Details

  • 5 of 7 (71.43%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.009%) to 92.388%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/generators/python/PythonDependencyManager.ts 5 7 71.43%
Totals Coverage Status
Change from base Build 13573893235: -0.009%
Covered Lines: 6480
Relevant Lines: 6876

💛 - Coveralls

@jonaslagoni jonaslagoni closed this Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants