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

fix(license_patch): Fix bug in license patch request #50

Merged
merged 1 commit into from
May 3, 2024

Conversation

deo002
Copy link
Collaborator

@deo002 deo002 commented Apr 11, 2024

Resolves the following:

  1. When we unmarshal json, the undefined keys take zero values in structs. So, there is no way to differentiate between an undefined value and an actual zero value when it is passed in json in a PATCH request.
    Example:
    {
    "active": false,
    "text": "Lorem ipsum"
    }
    and
    {
    "text": "Lorem ipsum"
    }
    Structs of both these unmarshalled json objects will have active as false.
  2. Also, updates with struct having fields as null values won't be considered for update in database.

Signed-off-by: deo002 <oberoidearsh@gmail.com>
Copy link
Member

@GMishx GMishx left a comment

Choose a reason for hiding this comment

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

Changes looks good.

Copy link
Member

@avinal avinal left a comment

Choose a reason for hiding this comment

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

One question, rest looks good.

Comment on lines +45 to +65
type LicensePOSTRequestJSONSchema struct {
Shortname string `json:"rf_shortname" binding:"required" example:"MIT"`
Fullname string `json:"rf_fullname" binding:"required" example:"MIT License"`
Text string `json:"rf_text" binding:"required" example:"MIT License Text here"`
Url string `json:"rf_url" binding:"required" example:"https://opensource.org/licenses/MIT"`
Copyleft bool `json:"rf_copyleft" binding:"required"`
FSFfree bool `json:"rf_FSFfree" binding:"required"`
OSIapproved bool `json:"rf_OSIapproved" binding:"required"`
GPLv2compatible bool `json:"rf_GPLv2compatible" binding:"required"`
GPLv3compatible bool `json:"rf_GPLv3compatible" binding:"required"`
Notes string `json:"rf_notes" example:"This license has been superseded." binding:"required"`
Fedora string `json:"rf_Fedora" binding:"required"`
TextUpdatable bool `json:"rf_text_updatable" binding:"required"`
DetectorType int64 `json:"rf_detector_type" example:"1" binding:"required"`
Active bool `json:"rf_active" binding:"required"`
Source string `json:"rf_source" binding:"required"`
SpdxId string `json:"rf_spdx_id" binding:"required" example:"MIT"`
Risk int64 `json:"rf_risk" binding:"required"`
Flag int64 `json:"rf_flag" binding:"required" example:"1"`
Marydone bool `json:"marydone" binding:"required"`
ExternalRef datatypes.JSONType[LicenseDBSchemaExtension] `json:"external_ref" binding:"required"`
Copy link
Member

Choose a reason for hiding this comment

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

I can see binding required in all the fields. Does that mean we cannot create a license without providing all the fields?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, while creating the license all the fields are required.

@GMishx GMishx merged commit 90acd1a into fossology:main May 3, 2024
5 checks passed
@GMishx GMishx deleted the license_data_type_fix branch May 3, 2024 05:09
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