-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/5 verbruiksobjecten #31
base: master
Are you sure you want to change the base?
Conversation
dd0a11e
to
a0c408c
Compare
a0c408c
to
18ba95b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main question is about creating separate request for JSON schemas: I think it's excessive and not beneficial.
I don't see a lot of advantage of using django_json_schema_model for now, but I'm also not against it, we can use it and see how it will go
except ValidationError: | ||
raise ValidationError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand why you catch and reraise the same error here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To generalize the error message, and link it to the field.
@@ -4,6 +4,7 @@ | |||
from django.db import models | |||
from django.utils.translation import gettext_lazy as _ | |||
|
|||
from django_json_schema_model.models import JsonSchema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll put here my questions about code for django_json_schema_model.models.JsonSchema
:
- It looks like
name
field should be unique - Why do you use
Draft202012Validator
in the clean() instead of using$schema
keyword defined in the JSON schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of validate("{}", self.schema)
you mean?
I felt like Draft202012Validator.check_schema(self.schema) was cleaner and it is also what is called within jsonschema.validate
.
|
||
def validate_schema(self, schema): | ||
try: | ||
Draft202012Validator.check_schema(schema) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same question as above: Why not to use validator based on $schema
?
|
||
class JsonSchemaSerializer(serializers.ModelSerializer): | ||
|
||
schema = serializers.DictField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this line needed? Is including it in Meta
not enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spectacular will render the type of JsonField as any
in the type of dictField
as object
.
|
||
class Meta: | ||
model = JsonSchema | ||
fields = "__all__" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above: it's better to define serializer fields explicitly. For example here it's not obvious is PK included in the serializer
@@ -77,6 +79,17 @@ class ProductTypeSerializer(serializers.ModelSerializer): | |||
links = NestedLinkSerializer(many=True, read_only=True) | |||
bestanden = NestedBestandSerializer(many=True, read_only=True) | |||
|
|||
verbruiksobject_schema = JsonSchemaSerializer(read_only=True) | |||
verbruiksobject_schema_id = serializers.PrimaryKeyRelatedField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it correct that to create a producttype with json schema you need to make two requests?
- create JSON schema
- Use PK of the created schema and create a producttype with such PK
It doesn't look very convenient. Could you just make it in one request?
Moreover I don't think exposing PKs in the public API is a good idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also let's discuss JsonSchema model:
it has name
field, which you use as a filter for its endpoint. But you never expose it in the Producttypen endpoint.
So how will user know what schema name to use as a filter
I think it would be better to use Json Schema name instead of PK here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was that a schema can be linked to multiple product types so because of this, it's created with a separate endpoint and added to a producttype using its id.
I'll make the name unique and use that as the identifier within the api, but i think two requests are always needed unless it becomes a 1 to 1 relation.
18ba95b
to
d21583a
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #31 +/- ##
==========================================
- Coverage 84.92% 84.75% -0.18%
==========================================
Files 106 109 +3
Lines 2269 2355 +86
Branches 149 150 +1
==========================================
+ Hits 1927 1996 +69
- Misses 319 336 +17
Partials 23 23 ☔ View full report in Codecov by Sentry. |
After discussing with Alex I decided to remove the package and move the JsonSchema model to open producten. |
Changes