Skip to content

Commit 2fb3624

Browse files
committed
feat(externalref): Add external ref to obligations
Signed-off-by: deo002 <[email protected]>
1 parent 3169bfa commit 2fb3624

File tree

9 files changed

+352
-56
lines changed

9 files changed

+352
-56
lines changed

cmd/laas/docs/docs.go

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2475,6 +2475,9 @@ const docTemplate = `{
24752475
"datatypes.JSONType-models_LicenseDBSchemaExtension": {
24762476
"type": "object"
24772477
},
2478+
"datatypes.JSONType-models_ObligationSchemaExtension": {
2479+
"type": "object"
2480+
},
24782481
"models.APICollection": {
24792482
"type": "object",
24802483
"properties": {
@@ -2825,7 +2828,54 @@ const docTemplate = `{
28252828
}
28262829
},
28272830
"models.LicenseDBSchemaExtension": {
2828-
"type": "object"
2831+
"type": "object",
2832+
"properties": {
2833+
"ack_text": {
2834+
"type": "string"
2835+
},
2836+
"acknowledgement": {
2837+
"type": "boolean"
2838+
},
2839+
"advertising_restrictions": {
2840+
"type": "boolean"
2841+
},
2842+
"non_commercial": {
2843+
"type": "boolean"
2844+
},
2845+
"osadl_link": {
2846+
"type": "string"
2847+
},
2848+
"other_license_name": {
2849+
"type": "string"
2850+
},
2851+
"patent_left": {
2852+
"type": "boolean"
2853+
},
2854+
"print_on_data_carrier": {
2855+
"type": "boolean"
2856+
},
2857+
"prohibited": {
2858+
"type": "boolean"
2859+
},
2860+
"ref_component": {
2861+
"type": "string"
2862+
},
2863+
"reviewed": {
2864+
"type": "boolean"
2865+
},
2866+
"scancode_link": {
2867+
"type": "string"
2868+
},
2869+
"source_code_available": {
2870+
"type": "boolean"
2871+
},
2872+
"spdx_link": {
2873+
"type": "string"
2874+
},
2875+
"tldr_link": {
2876+
"type": "string"
2877+
}
2878+
}
28292879
},
28302880
"models.LicenseError": {
28312881
"type": "object",
@@ -3089,6 +3139,9 @@ const docTemplate = `{
30893139
"comment": {
30903140
"type": "string"
30913141
},
3142+
"externalRef": {
3143+
"$ref": "#/definitions/datatypes.JSONType-models_ObligationSchemaExtension"
3144+
},
30923145
"id": {
30933146
"type": "integer"
30943147
},
@@ -3184,6 +3237,9 @@ const docTemplate = `{
31843237
"comment": {
31853238
"type": "string"
31863239
},
3240+
"external_ref": {
3241+
"$ref": "#/definitions/models.ObligationSchemaExtension"
3242+
},
31873243
"modifications": {
31883244
"type": "boolean",
31893245
"example": true
@@ -3324,6 +3380,17 @@ const docTemplate = `{
33243380
}
33253381
}
33263382
},
3383+
"models.ObligationSchemaExtension": {
3384+
"type": "object",
3385+
"properties": {
3386+
"obligation_explanation": {
3387+
"type": "string"
3388+
},
3389+
"obligation_suffix": {
3390+
"type": "string"
3391+
}
3392+
}
3393+
},
33273394
"models.ObligationType": {
33283395
"type": "object",
33293396
"required": [
@@ -3371,6 +3438,10 @@ const docTemplate = `{
33713438
"comment": {
33723439
"type": "string"
33733440
},
3441+
"external_ref": {
3442+
"type": "object",
3443+
"additionalProperties": true
3444+
},
33743445
"modifications": {
33753446
"type": "boolean",
33763447
"example": true

cmd/laas/docs/swagger.json

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,9 @@
24682468
"datatypes.JSONType-models_LicenseDBSchemaExtension": {
24692469
"type": "object"
24702470
},
2471+
"datatypes.JSONType-models_ObligationSchemaExtension": {
2472+
"type": "object"
2473+
},
24712474
"models.APICollection": {
24722475
"type": "object",
24732476
"properties": {
@@ -2818,7 +2821,54 @@
28182821
}
28192822
},
28202823
"models.LicenseDBSchemaExtension": {
2821-
"type": "object"
2824+
"type": "object",
2825+
"properties": {
2826+
"ack_text": {
2827+
"type": "string"
2828+
},
2829+
"acknowledgement": {
2830+
"type": "boolean"
2831+
},
2832+
"advertising_restrictions": {
2833+
"type": "boolean"
2834+
},
2835+
"non_commercial": {
2836+
"type": "boolean"
2837+
},
2838+
"osadl_link": {
2839+
"type": "string"
2840+
},
2841+
"other_license_name": {
2842+
"type": "string"
2843+
},
2844+
"patent_left": {
2845+
"type": "boolean"
2846+
},
2847+
"print_on_data_carrier": {
2848+
"type": "boolean"
2849+
},
2850+
"prohibited": {
2851+
"type": "boolean"
2852+
},
2853+
"ref_component": {
2854+
"type": "string"
2855+
},
2856+
"reviewed": {
2857+
"type": "boolean"
2858+
},
2859+
"scancode_link": {
2860+
"type": "string"
2861+
},
2862+
"source_code_available": {
2863+
"type": "boolean"
2864+
},
2865+
"spdx_link": {
2866+
"type": "string"
2867+
},
2868+
"tldr_link": {
2869+
"type": "string"
2870+
}
2871+
}
28222872
},
28232873
"models.LicenseError": {
28242874
"type": "object",
@@ -3082,6 +3132,9 @@
30823132
"comment": {
30833133
"type": "string"
30843134
},
3135+
"externalRef": {
3136+
"$ref": "#/definitions/datatypes.JSONType-models_ObligationSchemaExtension"
3137+
},
30853138
"id": {
30863139
"type": "integer"
30873140
},
@@ -3177,6 +3230,9 @@
31773230
"comment": {
31783231
"type": "string"
31793232
},
3233+
"external_ref": {
3234+
"$ref": "#/definitions/models.ObligationSchemaExtension"
3235+
},
31803236
"modifications": {
31813237
"type": "boolean",
31823238
"example": true
@@ -3317,6 +3373,17 @@
33173373
}
33183374
}
33193375
},
3376+
"models.ObligationSchemaExtension": {
3377+
"type": "object",
3378+
"properties": {
3379+
"obligation_explanation": {
3380+
"type": "string"
3381+
},
3382+
"obligation_suffix": {
3383+
"type": "string"
3384+
}
3385+
}
3386+
},
33203387
"models.ObligationType": {
33213388
"type": "object",
33223389
"required": [
@@ -3364,6 +3431,10 @@
33643431
"comment": {
33653432
"type": "string"
33663433
},
3434+
"external_ref": {
3435+
"type": "object",
3436+
"additionalProperties": true
3437+
},
33673438
"modifications": {
33683439
"type": "boolean",
33693440
"example": true

cmd/laas/docs/swagger.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ basePath: /api/v1
22
definitions:
33
datatypes.JSONType-models_LicenseDBSchemaExtension:
44
type: object
5+
datatypes.JSONType-models_ObligationSchemaExtension:
6+
type: object
57
models.APICollection:
68
properties:
79
authenticated:
@@ -245,6 +247,37 @@ definitions:
245247
type: integer
246248
type: object
247249
models.LicenseDBSchemaExtension:
250+
properties:
251+
ack_text:
252+
type: string
253+
acknowledgement:
254+
type: boolean
255+
advertising_restrictions:
256+
type: boolean
257+
non_commercial:
258+
type: boolean
259+
osadl_link:
260+
type: string
261+
other_license_name:
262+
type: string
263+
patent_left:
264+
type: boolean
265+
print_on_data_carrier:
266+
type: boolean
267+
prohibited:
268+
type: boolean
269+
ref_component:
270+
type: string
271+
reviewed:
272+
type: boolean
273+
scancode_link:
274+
type: string
275+
source_code_available:
276+
type: boolean
277+
spdx_link:
278+
type: string
279+
tldr_link:
280+
type: string
248281
type: object
249282
models.LicenseError:
250283
properties:
@@ -431,6 +464,8 @@ definitions:
431464
$ref: '#/definitions/models.ObligationClassification'
432465
comment:
433466
type: string
467+
externalRef:
468+
$ref: '#/definitions/datatypes.JSONType-models_ObligationSchemaExtension'
434469
id:
435470
type: integer
436471
licenses:
@@ -490,6 +525,8 @@ definitions:
490525
type: string
491526
comment:
492527
type: string
528+
external_ref:
529+
$ref: '#/definitions/models.ObligationSchemaExtension'
493530
modifications:
494531
example: true
495532
type: boolean
@@ -595,6 +632,13 @@ definitions:
595632
example: 200
596633
type: integer
597634
type: object
635+
models.ObligationSchemaExtension:
636+
properties:
637+
obligation_explanation:
638+
type: string
639+
obligation_suffix:
640+
type: string
641+
type: object
598642
models.ObligationType:
599643
properties:
600644
type:
@@ -627,6 +671,9 @@ definitions:
627671
type: string
628672
comment:
629673
type: string
674+
external_ref:
675+
additionalProperties: true
676+
type: object
630677
modifications:
631678
example: true
632679
type: boolean

cmd/laas/gen_external_ref_schema.go

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,20 @@ type ExternalRefFields struct {
3636
Fields []ExternalRefFieldMetaData `yaml:"fields"`
3737
}
3838

39+
type ExternalRefYAML struct {
40+
License ExternalRefFields `yaml:"license"`
41+
Obligation ExternalRefFields `yaml:"obligation"`
42+
}
43+
3944
func main() {
40-
externalRefFields := ExternalRefFields{}
45+
externalRefYAML := ExternalRefYAML{}
4146

4247
fieldsMetadata, err := os.ReadFile(PATH_EXTERNAL_REF_CONFIG_FILE)
4348
if err != nil {
4449
log.Fatalf("Failed to instantiate json schema for external ref in license: %v", err)
4550
}
4651

47-
err = yaml.Unmarshal(fieldsMetadata, &externalRefFields)
52+
err = yaml.Unmarshal(fieldsMetadata, &externalRefYAML)
4853
if err != nil {
4954
log.Fatalf("Failed to instantiate json schema for external ref in license: %v", err)
5055
}
@@ -56,9 +61,34 @@ func main() {
5661

5762
// REUSE-IgnoreStart
5863

59-
var fields []jen.Code
64+
var licenseFields, obligationFields []jen.Code
65+
66+
for _, f := range externalRefYAML.License.Fields {
67+
field := jen.Id(f.StructFieldName).Op("*")
68+
if f.StructFieldName == "" {
69+
err = errors.New("field struct_field_name is missing in external_ref_fields.yaml")
70+
}
71+
switch f.Type {
72+
case "boolean":
73+
field = field.Bool()
74+
case "string":
75+
field = field.String()
76+
case "int":
77+
field = field.Int64()
78+
default:
79+
err = fmt.Errorf("type %s in external_ref_fields.yaml is not supported", f.Type)
80+
}
81+
if err != nil {
82+
log.Fatalf("Failed to instantiate json schema for external ref in license: %v", err)
83+
return
84+
}
85+
field = field.Tag(map[string]string{"json": fmt.Sprintf("%s,omitempty", f.Name)})
86+
licenseFields = append(licenseFields, field)
87+
}
88+
89+
f.Type().Id("LicenseDBSchemaExtension").Struct(licenseFields...)
6090

61-
for _, f := range externalRefFields.Fields {
91+
for _, f := range externalRefYAML.Obligation.Fields {
6292
field := jen.Id(f.StructFieldName).Op("*")
6393
if f.StructFieldName == "" {
6494
err = errors.New("field struct_field_name is missing in external_ref_fields.yaml")
@@ -77,11 +107,11 @@ func main() {
77107
log.Fatalf("Failed to instantiate json schema for external ref in license: %v", err)
78108
return
79109
}
80-
field = field.Tag(map[string]string{"json": fmt.Sprintf("%s,omitempty", f.Name), "swaggerignore": "true"})
81-
fields = append(fields, field)
110+
field = field.Tag(map[string]string{"json": fmt.Sprintf("%s,omitempty", f.Name)})
111+
obligationFields = append(obligationFields, field)
82112
}
83113

84-
f.Type().Id("LicenseDBSchemaExtension").Struct(fields...)
114+
f.Type().Id("ObligationSchemaExtension").Struct(obligationFields...)
85115
f.Save(PATH_EXTERNAL_REF_STRUCT_FILE)
86116

87117
}

0 commit comments

Comments
 (0)