-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Use qualname to disambiguate multiple components with identical names #51
Comments
the enum part is done. that leaves the serializer naming. |
Oh my, the enum approach is IMO ugly. The hashing approach will merge two enums just because they are the same, which is introducing another case of disappearing enums - the old types disappear and become one. They may have the same choices at one time version of an API, but differ in a different version of the API, and it would be better for the component name to stay stable across those changes. In addition to the merging aspect, I have enums which change choices often, and their hash would change, and client generated model filenames and class names would change each time, with flow on effects throughout the codebase. |
as you said. sry that you are dissatisfied with the solution.
i tried to go for that.
i did exactly what you suggested. choose a "stable" suffix to disambiguate instead of disappearing the enums.
the whole point of the enums is consolidating identical choices. now you want to keep them separate. can't have both ways. i'm afraid you ask for multiple things at the same time that are mutually exclusive. since the choice lists are no class objects, they have no name in itself. all you can do is use the hash of the set. the differentiation you ask for is simply not possible here.
that would introduce duplication again. suppose you have 2 distinct enums with the name
the enum resolution is supposed to be stable and comprehensible (safe/sane as you said). the suffixes are a way to resolve issues automatically. you can and should resolve the emmited conflicts via the settings: https://drf-spectacular.readthedocs.io/en/latest/faq.html#i-get-warnings-regarding-my-enum-or-my-enum-names-have-a-weird-suffix . if you explicitly name you conflicting enum sets, you won't see suffixes (and therefore names wouldn't change). |
@jayvdb any feedback on using the ENUM_NAME_OVERRIDES setting? i think most (if not all) of your collision issues can be resolved with this. i also improved the setting handling a bit. if you want to go a completely different way you can always replace the default hook with your own custom one. the also the workflow should not be that awkward because it is in line with rest of spectacular: run generation, see a warning, fix issue with annotation/hint/setting if desired. otherwise ignore and carry on. |
@tfranzel , if you dont want to have an open issue about ways to automatically generating semantically meaningful component names , close this issue. This issue is not about settings which allow the implementer to workaround deficiencies in the tool. It is great that those workarounds exist, so that people can implement it already. Pragmatism requires that. This issue is about how to correctly generate names, even in the pretense of naming conflicts by falling back to python name uniqueness. Because we can, easily in Python 3, using qualname. It used to be hell in Python 2 because qualname didnt exist so names within a module could easily clash without intensive use of I've re-run with master, and I am now not getting generated hash-based-named enums appearing in my schema. That was a no-go for me, and meant I had to revert that commit. However, this was fixed because I removed @@ -4664,7 +8027,7 @@ components:
type: string
maxLength: 128
type:
- $ref: '#/components/schemas/TypeEnum'
+ $ref: '#/components/schemas/Type6faEnum'
required:
- code
- name
@@ -5178,6 +8810,128 @@ components:
multipleOf: 0.01
maximum: 10000000000
minimum: -10000000000
+ PatchedOption:
+ type: object
+ description: Correctly map oscar fields to serializer fields.
+ properties:
+ url:
+ type: string
+ format: uri
+ readOnly: true
+ code:
+ type: string
+ pattern: ^[-a-zA-Z0-9_]+$
+ name:
+ type: string
+ maxLength: 128
+ type:
+ $ref: '#/components/schemas/Type6faEnum'
PatchedPartner:
type: object
description: Correctly map oscar fields to serializer fields.
@@ -5386,6 +9140,36 @@ components:
- productClass
- stockrecords
- url
+ ProductAttribute:
+ type: object
+ description: Correctly map oscar fields to serializer fields.
+ properties:
+ url:
+ type: string
+ format: uri
+ readOnly: true
+ productClass:
+ type: string
+ writeOnly: true
+ optionGroup:
+ allOf:
+ - $ref: '#/components/schemas/AttributeOptionGroup'
+ nullable: true
+ name:
+ type: string
+ maxLength: 128
+ code:
+ type: string
+ pattern: ^[-a-zA-Z0-9_]+$
+ maxLength: 128
+ type:
+ $ref: '#/components/schemas/Type499Enum'
+ required:
+ type: boolean
+ required:
+ - code
+ - name
+ - url
ProductAttributeValue:
type: object
description: Correctly map oscar fields to serializer fields.
@@ -5722,7 +9506,22 @@ components:
- Ms
- Dr
type: string
- TypeEnum:
+ Type499Enum:
+ enum:
+ - text
+ - integer
+ - boolean
+ - float
+ - richtext
+ - date
+ - datetime
+ - option
+ - multi_option
+ - entity
+ - file
+ - image
+ type: string
+ Type6faEnum:
enum:
- Required
- Optional
type: string
The enum values come from https://github.com/django-oscar/django-oscar/blob/61ce21e/src/oscar/apps/catalogue/abstract_models.py#L804 I see nothing in https://github.com/django-oscar/django-oscar-api/blob/master/oscarapi/serializers/admin/product.py related to the The naming of this enum can be disambiguated as follows:
Before concluding this issue is optimally solved, some analysis of the top few 'enum fields' should be done to see how they work, and ensure that optimal (or at least reasonably semantically correct) names are given to their enums. |
that is what i did with 5da017f. this may hopefully resolve at least some your enum collisions.
not a big fan of involving the model. imho it's same problem there when the choice set is reused in multiple models. i also have quite a few the ugly solution is still happening when a we have the same name with different choice sets in different components. of course component collisions are a separate topic. the enums will likely improve even a bit more when serializer component collisions are properly handled. |
there have been some more minor improvements. given the framework limitations, this is most likely as good as it gets. closing because it's long and stale. |
Mental note for #27 (comment) ;-)
The text was updated successfully, but these errors were encountered: