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

v3 adds generic type info to schema classes/properties/items #174

Merged
merged 41 commits into from
May 23, 2023

Conversation

spacether
Copy link
Contributor

@spacether spacether commented May 17, 2023

  • removes double underscore private prefix from apiresponse/mediatype/content classes
    • this was done to fix type hint access in vscode
  • uses generics in schemas so IDEs can see instance and property base types
    So now when models are instantiated, they will show what class they are based on
    Like so:
my_model = MyModel(some_str='a')
# my_model is type MyModel[frozendict.frozendict] in the vscode IDE
# my_model.some_str is type SomeStr[str] in the vscode IDE
  • keep the mixin classes for ide methods (needed to show possible properties)
  • make Schema generic
  • when making classes always define new so the generic can be seen
  • update properties to add the generic type
  • update ref props to add generic
  • fix UnsetAnyTypeSchema not being used in AbstractStepMessage
  • update get_item property with type
  • update get_item array with type
  • fix __new__ type checking warning for dictshemas
  • update UnsetAnyType type hints to be AnyType because it will always be true and UnsetAnyType will not
  • add __init__ method to AnyTypeSchema
  • make sure that the new method is always written for custom classes
  • update response body to be typed
  • update response content mediatype to be typed
  • update header schema to be typed
  • update header content mediatype to be typed
  • update parameter schema to be typed
  • update parameter content mediatype to be typed

Out of scope future improvement.

  • Use typing.Never in NotAnyType
  • Changing ref schemas to type aliases. This is not work because assignment needs the prop to be there
    • perhaps it would work if it was in annotations only

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/python*.
    For Windows users, please run the script in Git BASH.

@spacether spacether changed the title v3 add generic type info v3 adds generic type info May 21, 2023
@spacether spacether changed the title v3 adds generic type info v3 adds generic type info to schema classes/properties/items May 23, 2023
@spacether spacether merged commit 3f62259 into 3_0_0 May 23, 2023
@spacether spacether deleted the v3_add_generic_type_info branch May 23, 2023 00:35
spacether added a commit that referenced this pull request May 31, 2023
* Adds generic type T

* Fixes broken python test

* Fixes for vscode basic type checking

* Adds new instacne casting

* Sets ValidationMetadata new type

* Makes ValidationMetadata a dataclass, fixes type issues in _process_schema_classes

* Fixes XBase self type errors

* Makes two methods static

* Fixes IntBase as_int type error

* Fixes type error in NumberBase

* Adds needed typing.cast calls in new methods and get_new_class fn

* Fixes exponent type error

* Fixes type errors in _get_new_instance_without_conversion

* Fixes typ error in FileIO new

* Fixes type error in BytesSchema

* Fixes another type error

* Adds type ignore for _GenericAlias check and origin access

* Removes _takes_ascii usage

* Fixes septype error

* Adds __parse_isotime type fix

* Fixes more date/datetime parsing errors

* Adds missing return types

* Changes UnsetAnyType back to AnyType

* Fixes AnyType init signature

* Writes new method for all composed or anytype classes

* Removes quote from refclass definitions

* Removes a type ignore comment

* Sample regen

* Adds response body generic type to ApiResponse classes

* Refactors response content template

* Adds response content type hint

* Fixes response header passing for deserialization

* Moves content schema helper

* Adds header and parameter content type type hint

* Adds missing imports

* Adds schema types for parameters and headers

* Samples updated

* Removes frozendict base class from ValidationMetadata

* Removes __origin__ usage

* Samples regenerated

* Fixes python test
spacether added a commit that referenced this pull request Jun 8, 2023
* Adds generic type T

* Fixes broken python test

* Fixes for vscode basic type checking

* Adds new instacne casting

* Sets ValidationMetadata new type

* Makes ValidationMetadata a dataclass, fixes type issues in _process_schema_classes

* Fixes XBase self type errors

* Makes two methods static

* Fixes IntBase as_int type error

* Fixes type error in NumberBase

* Adds needed typing.cast calls in new methods and get_new_class fn

* Fixes exponent type error

* Fixes type errors in _get_new_instance_without_conversion

* Fixes typ error in FileIO new

* Fixes type error in BytesSchema

* Fixes another type error

* Adds type ignore for _GenericAlias check and origin access

* Removes _takes_ascii usage

* Fixes septype error

* Adds __parse_isotime type fix

* Fixes more date/datetime parsing errors

* Adds missing return types

* Changes UnsetAnyType back to AnyType

* Fixes AnyType init signature

* Writes new method for all composed or anytype classes

* Removes quote from refclass definitions

* Removes a type ignore comment

* Sample regen

* Adds response body generic type to ApiResponse classes

* Refactors response content template

* Adds response content type hint

* Fixes response header passing for deserialization

* Moves content schema helper

* Adds header and parameter content type type hint

* Adds missing imports

* Adds schema types for parameters and headers

* Samples updated

* Removes frozendict base class from ValidationMetadata

* Removes __origin__ usage

* Samples regenerated

* Fixes python test
spacether added a commit that referenced this pull request Aug 16, 2023
* Adds generic type T

* Fixes broken python test

* Fixes for vscode basic type checking

* Adds new instacne casting

* Sets ValidationMetadata new type

* Makes ValidationMetadata a dataclass, fixes type issues in _process_schema_classes

* Fixes XBase self type errors

* Makes two methods static

* Fixes IntBase as_int type error

* Fixes type error in NumberBase

* Adds needed typing.cast calls in new methods and get_new_class fn

* Fixes exponent type error

* Fixes type errors in _get_new_instance_without_conversion

* Fixes typ error in FileIO new

* Fixes type error in BytesSchema

* Fixes another type error

* Adds type ignore for _GenericAlias check and origin access

* Removes _takes_ascii usage

* Fixes septype error

* Adds __parse_isotime type fix

* Fixes more date/datetime parsing errors

* Adds missing return types

* Changes UnsetAnyType back to AnyType

* Fixes AnyType init signature

* Writes new method for all composed or anytype classes

* Removes quote from refclass definitions

* Removes a type ignore comment

* Sample regen

* Adds response body generic type to ApiResponse classes

* Refactors response content template

* Adds response content type hint

* Fixes response header passing for deserialization

* Moves content schema helper

* Adds header and parameter content type type hint

* Adds missing imports

* Adds schema types for parameters and headers

* Samples updated

* Removes frozendict base class from ValidationMetadata

* Removes __origin__ usage

* Samples regenerated

* Fixes python test
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.

None yet

1 participant