Conditions | 4 |
Total Lines | 20 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 4 |
Changes | 0 |
1 | package data |
||
17 | func (generator *integerGenerator) GenerateDataBySchema(ctx context.Context, schema *openapi3.Schema) (Data, error) { |
||
18 | 1 | minimum, maximum := generator.getMinMax(schema) |
|
19 | |||
20 | 1 | if maximum < minimum { |
|
21 | 1 | return 0, errors.WithStack(&ErrGenerationFailed{ |
|
22 | GeneratorID: "integerGenerator", |
||
23 | Message: "maximum cannot be less than minimum", |
||
24 | }) |
||
25 | } |
||
26 | 1 | if maximum == minimum { |
|
27 | 1 | return minimum, nil |
|
28 | } |
||
29 | |||
30 | 1 | value := generator.generateValueInRange(minimum, maximum) |
|
31 | |||
32 | 1 | if schema.MultipleOf != nil { |
|
33 | 1 | value -= value % int64(*schema.MultipleOf) |
|
34 | } |
||
35 | |||
36 | 1 | return value, nil |
|
37 | } |
||
71 |