Skip to content

Commit

Permalink
check tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chkp-omerma committed Nov 19, 2024
1 parent fd0ceaf commit 5d3f185
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 40 deletions.
10 changes: 5 additions & 5 deletions internal/models/web-api-practice/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ type SchemaIPS struct {
}

type FileSchema struct {
ID string `json:"id,omitempty"`
Filename string `json:"name,omitempty"`
Data string `json:"data"`
Size uint64 `json:"size,omitempty"`
IsFileExist bool `json:"isFileExist,omitempty"`
ID string `json:"id,omitempty"`
Filename string `json:"name,omitempty"`
Data string `json:"data"`
//Size uint64 `json:"size,omitempty"`
//IsFileExist bool `json:"isFileExist,omitempty"`
}

type OASSchema struct {
Expand Down
20 changes: 10 additions & 10 deletions internal/resources/web-api-practice.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,16 @@ func ResourceWebAPIPractice() *schema.Resource {
Sensitive: true,
Required: true,
},
"size": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"is_file_exist": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
//"size": {
// Type: schema.TypeInt,
// Optional: true,
// Computed: true,
//},
//"is_file_exist": {
// Type: schema.TypeBool,
// Optional: true,
// Computed: true,
//},
//"oas_schema": {
// Type: schema.TypeSet,
// Computed: true,
Expand Down
32 changes: 15 additions & 17 deletions internal/resources/web-api-practice/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func CreateWebAPIPracticeInputFromResourceData(d *schema.ResourceData) (models.C
res.APIAttacks = apiAttacksSlice[0]
}

schemaValidationSlice := utils.Map(utils.MustResourceDataCollectionToSlice[map[string]any](d, "schema_validation"), mapToSchemaValidationInput)
schemaValidationSlice := utils.Map(utils.MustResourceDataCollectionToSlice[any](d, "schema_validation"), mapToSchemaValidationInput)
if len(schemaValidationSlice) > 0 {
res.SchemaValidation = schemaValidationSlice[0]
}
Expand Down Expand Up @@ -70,8 +70,6 @@ func NewWebAPIPractice(ctx context.Context, c *api.Client, input models.CreateWe
OasSchema {
data
name
size
isFileExist
}
}
}
Expand Down Expand Up @@ -166,27 +164,27 @@ func mapToAPIAttacksInput(apiAttacksMap map[string]any) models.APIAttacksInput {
// return ret
//}

func mapToSchemaValidationInput(schemaValidationFromResourceData map[string]any) models.SchemaValidationInput {
func mapToSchemaValidationInput(schemaValidationFromResourceData any) models.SchemaValidationInput {
schemaValidation, err := utils.UnmarshalAs[models.FileSchema](schemaValidationFromResourceData)
if err != nil {
fmt.Printf("Failed to convert input schema validation to FileSchema struct. Error: %+v", err)
return models.SchemaValidationInput{}
}

schemaValidation = models.NewFileSchemaEncode(schemaValidation.Filename, schemaValidation.Data)
//
// var ret models.SchemaValidationInput
//
// if schemaValidation.ID != "" {
// ret.ID = schemaValidation.ID
// }
//
// ret.OASSchema = schemaValidation.Data
//
// return ret
//}

var ret models.SchemaValidationInput

if schemaValidation.ID != "" {
ret.ID = schemaValidation.ID
return models.SchemaValidationInput{
OASSchema: schemaValidation.Data,
}

ret.OASSchema = schemaValidation.Data

return ret
}

// return models.SchemaValidationInput{
// OASSchema: schemaValidation.Data,
// }
//}
12 changes: 5 additions & 7 deletions internal/resources/web-api-practice/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ func ReadWebAPIPracticeToResourceData(practice models.WebAPIPractice, d *schema.
decodedData = string(bDecodedData)
}
schemaValidation := models.FileSchema{
ID: practice.SchemaValidation.ID,
Filename: practice.SchemaValidation.OASSchema.Name,
Data: decodedData,
Size: practice.SchemaValidation.OASSchema.Size,
IsFileExist: practice.SchemaValidation.OASSchema.IsFileExist,
ID: practice.SchemaValidation.ID,
Filename: practice.SchemaValidation.OASSchema.Name,
Data: decodedData,
//Size: practice.SchemaValidation.OASSchema.Size,
//IsFileExist: practice.SchemaValidation.OASSchema.IsFileExist,
}

//oasSchema := models.OASSchema{
Expand Down Expand Up @@ -142,8 +142,6 @@ func GetWebAPIPractice(ctx context.Context, c *api.Client, id string) (models.We
OasSchema {
data
name
size
isFileExist
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/web-api-practice/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ func parseSchemaAPIAttacks(schemaAPIAttacks any) []models.UpdateAPIAttacksInput
}

func parseSchemaValidation(validation any) []models.UpdateSchemaValidationInput {
input := utils.Map(utils.MustSchemaCollectionToSlice[map[string]any](validation), mapToSchemaValidationInput)
input := utils.Map(utils.MustSchemaCollectionToSlice[any](validation), mapToSchemaValidationInput)
return utils.Map(input, utils.MustUnmarshalAs[models.UpdateSchemaValidationInput, models.SchemaValidationInput])
}

0 comments on commit 5d3f185

Please sign in to comment.