Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion cmd/laas/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2493,6 +2493,9 @@ const docTemplate = `{
"datatypes.JSONType-models_LicenseDBSchemaExtension": {
"type": "object"
},
"datatypes.JSONType-models_ObligationSchemaExtension": {
"type": "object"
},
"models.APICollection": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -2848,7 +2851,15 @@ const docTemplate = `{
}
},
"models.LicenseDBSchemaExtension": {
"type": "object"
"type": "object",
"properties": {
"license_explanation": {
"type": "string"
},
"license_suffix": {
"type": "string"
}
}
},
"models.LicenseError": {
"type": "object",
Expand Down Expand Up @@ -3129,6 +3140,9 @@ const docTemplate = `{
"comment": {
"type": "string"
},
"externalRef": {
"$ref": "#/definitions/datatypes.JSONType-models_ObligationSchemaExtension"
},
"id": {
"type": "string"
},
Expand Down Expand Up @@ -3217,6 +3231,9 @@ const docTemplate = `{
"comment": {
"type": "string"
},
"external_ref": {
"$ref": "#/definitions/models.ObligationSchemaExtension"
},
"license_ids": {
"type": "array",
"items": {
Expand Down Expand Up @@ -3413,6 +3430,9 @@ const docTemplate = `{
"comment": {
"type": "string"
},
"external_ref": {
"$ref": "#/definitions/models.ObligationSchemaExtension"
},
"id": {
"type": "string",
"example": "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"
Expand Down Expand Up @@ -3445,6 +3465,17 @@ const docTemplate = `{
}
}
},
"models.ObligationSchemaExtension": {
"type": "object",
"properties": {
"obligation_explanation": {
"type": "string"
},
"obligation_suffix": {
"type": "string"
}
}
},
"models.ObligationType": {
"type": "object",
"required": [
Expand Down Expand Up @@ -3495,6 +3526,10 @@ const docTemplate = `{
"comment": {
"type": "string"
},
"external_ref": {
"type": "object",
"additionalProperties": true
},
"license_ids": {
"type": "array",
"items": {
Expand Down
37 changes: 36 additions & 1 deletion cmd/laas/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2486,6 +2486,9 @@
"datatypes.JSONType-models_LicenseDBSchemaExtension": {
"type": "object"
},
"datatypes.JSONType-models_ObligationSchemaExtension": {
"type": "object"
},
"models.APICollection": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -2841,7 +2844,15 @@
}
},
"models.LicenseDBSchemaExtension": {
"type": "object"
"type": "object",
"properties": {
"license_explanation": {
"type": "string"
},
"license_suffix": {
"type": "string"
}
}
},
"models.LicenseError": {
"type": "object",
Expand Down Expand Up @@ -3122,6 +3133,9 @@
"comment": {
"type": "string"
},
"externalRef": {
"$ref": "#/definitions/datatypes.JSONType-models_ObligationSchemaExtension"
},
"id": {
"type": "string"
},
Expand Down Expand Up @@ -3210,6 +3224,9 @@
"comment": {
"type": "string"
},
"external_ref": {
"$ref": "#/definitions/models.ObligationSchemaExtension"
},
"license_ids": {
"type": "array",
"items": {
Expand Down Expand Up @@ -3406,6 +3423,9 @@
"comment": {
"type": "string"
},
"external_ref": {
"$ref": "#/definitions/models.ObligationSchemaExtension"
},
"id": {
"type": "string",
"example": "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"
Expand Down Expand Up @@ -3438,6 +3458,17 @@
}
}
},
"models.ObligationSchemaExtension": {
"type": "object",
"properties": {
"obligation_explanation": {
"type": "string"
},
"obligation_suffix": {
"type": "string"
}
}
},
"models.ObligationType": {
"type": "object",
"required": [
Expand Down Expand Up @@ -3488,6 +3519,10 @@
"comment": {
"type": "string"
},
"external_ref": {
"type": "object",
"additionalProperties": true
},
"license_ids": {
"type": "array",
"items": {
Expand Down
23 changes: 23 additions & 0 deletions cmd/laas/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ basePath: /api/v1
definitions:
datatypes.JSONType-models_LicenseDBSchemaExtension:
type: object
datatypes.JSONType-models_ObligationSchemaExtension:
type: object
models.APICollection:
properties:
authenticated:
Expand Down Expand Up @@ -250,6 +252,11 @@ definitions:
type: string
type: object
models.LicenseDBSchemaExtension:
properties:
license_explanation:
type: string
license_suffix:
type: string
type: object
models.LicenseError:
properties:
Expand Down Expand Up @@ -448,6 +455,8 @@ definitions:
$ref: '#/definitions/models.ObligationClassification'
comment:
type: string
externalRef:
$ref: '#/definitions/datatypes.JSONType-models_ObligationSchemaExtension'
id:
type: string
licenses:
Expand Down Expand Up @@ -503,6 +512,8 @@ definitions:
type: string
comment:
type: string
external_ref:
$ref: '#/definitions/models.ObligationSchemaExtension'
license_ids:
example:
- f81d4fae-7dec-11d0-a765-00a0c91e6bf6
Expand Down Expand Up @@ -640,6 +651,8 @@ definitions:
type: string
comment:
type: string
external_ref:
$ref: '#/definitions/models.ObligationSchemaExtension'
id:
example: f81d4fae-7dec-11d0-a765-00a0c91e6bf6
type: string
Expand Down Expand Up @@ -670,6 +683,13 @@ definitions:
- topic
- type
type: object
models.ObligationSchemaExtension:
properties:
obligation_explanation:
type: string
obligation_suffix:
type: string
type: object
models.ObligationType:
properties:
type:
Expand Down Expand Up @@ -702,6 +722,9 @@ definitions:
type: string
comment:
type: string
external_ref:
additionalProperties: true
type: object
license_ids:
example:
- f81d4fae-7dec-11d0-a765-00a0c91e6bf6
Expand Down
45 changes: 37 additions & 8 deletions cmd/laas/gen_external_ref_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@ type ExternalRefFields struct {
Fields []ExternalRefFieldMetaData `yaml:"fields"`
}

type ExternalRefYAML struct {
License ExternalRefFields `yaml:"license"`
Obligation ExternalRefFields `yaml:"obligation"`
}

func main() {
externalRefFields := ExternalRefFields{}
externalRefYAML := ExternalRefYAML{}

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

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

// REUSE-IgnoreStart

var fields []jen.Code
var licenseFields, obligationFields []jen.Code

for _, f := range externalRefFields.Fields {
for _, f := range externalRefYAML.License.Fields {
field := jen.Id(f.StructFieldName).Op("*")
if f.StructFieldName == "" {
err = errors.New("field struct_field_name is missing in external_ref_fields.yaml")
Expand All @@ -77,11 +82,35 @@ func main() {
log.Fatalf("Failed to instantiate json schema for external ref in license: %v", err)
return
}
field = field.Tag(map[string]string{"json": fmt.Sprintf("%s,omitempty", f.Name), "swaggerignore": "true"})
fields = append(fields, field)
field = field.Tag(map[string]string{"json": fmt.Sprintf("%s,omitempty", f.Name)})
licenseFields = append(licenseFields, field)
}

f.Type().Id("LicenseDBSchemaExtension").Struct(fields...)
f.Save(PATH_EXTERNAL_REF_STRUCT_FILE)
f.Type().Id("LicenseDBSchemaExtension").Struct(licenseFields...)

for _, f := range externalRefYAML.Obligation.Fields {
field := jen.Id(f.StructFieldName).Op("*")
if f.StructFieldName == "" {
err = errors.New("field struct_field_name is missing in external_ref_fields.yaml")
}
switch f.Type {
case "boolean":
field = field.Bool()
case "string":
field = field.String()
case "int":
field = field.Int64()
default:
err = fmt.Errorf("type %s in external_ref_fields.yaml is not supported", f.Type)
}
if err != nil {
log.Fatalf("Failed to instantiate json schema for external ref in license: %v", err)
return
}
field = field.Tag(map[string]string{"json": fmt.Sprintf("%s,omitempty", f.Name)})
obligationFields = append(obligationFields, field)
}

f.Type().Id("ObligationSchemaExtension").Struct(obligationFields...)
f.Save(PATH_EXTERNAL_REF_STRUCT_FILE)
}
42 changes: 29 additions & 13 deletions external_ref_fields.example.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
# SPDX-License-Identifier: GPL-2.0-only
# SPDX-FileCopyrightText: FOSSology contributors

fields:
- name: "license_suffix"
type: "string"
struct_field_name: "LicenseSuffix"
label: "License Suffix"
formComponentPath: "../components/dynamic/inputField"
componentType: "input"
- name: "license_explanation"
type: "string"
struct_field_name: "LicenseExplanation"
label: "License Explanation"
formComponentPath: "../components/dynamic/inputField"
componentType: "input"
license:
fields:
- name: "license_suffix"
type: "string"
struct_field_name: "LicenseSuffix"
label: "License Suffix"
formComponentPath: "../components/dynamic/inputField"
componentType: "input"
- name: "license_explanation"
type: "string"
struct_field_name: "LicenseExplanation"
label: "License Explanation"
formComponentPath: "../components/dynamic/inputField"
componentType: "input"

obligation:
fields:
- name: "obligation_suffix"
type: "string"
struct_field_name: "ObligationSuffix"
label: "Obligation Suffix"
formComponentPath: "../components/dynamic/inputField"
componentType: "input"
- name: "obligation_explanation"
type: "string"
struct_field_name: "ObligationExplanation"
label: "Obligation Explanation"
formComponentPath: "../components/dynamic/inputField"
componentType: "input"
Loading
Loading