diff --git a/http/jsonapi/generator/generate_helper.go b/http/jsonapi/generator/generate_helper.go index a76882c1f..3a548a520 100644 --- a/http/jsonapi/generator/generate_helper.go +++ b/http/jsonapi/generator/generate_helper.go @@ -67,7 +67,11 @@ func (g *typeGenerator) invoke() error { // nolint: gocyclo } case "uuid": addValidator(g.tags, "uuid") - g.stmt.String() + if g.schema.Nullable { + g.stmt.Op("*").String() + } else { + g.stmt.String() + } case "decimal": addValidator(g.tags, "matches(^(\\d*\\.)?\\d+$)") if g.isParam { @@ -76,33 +80,63 @@ func (g *typeGenerator) invoke() error { // nolint: gocyclo g.stmt.Op("*").Qual(pkgDecimal, "Decimal") } default: - g.stmt.String() + if g.schema.Nullable { + g.stmt.Op("*").String() + } else { + g.stmt.String() + } } case "integer": + removeOmitempty(g.tags) switch g.schema.Format { case "int32": - g.stmt.Int32() + if g.schema.Nullable { + g.stmt.Op("*").Int32() + } else { + g.stmt.Int32() + } default: - g.stmt.Int64() + if g.schema.Nullable { + g.stmt.Op("*").Int64() + } else { + g.stmt.Int64() + } } case "number": switch g.schema.Format { case "decimal": if g.isParam { + removeOmitempty(g.tags) g.stmt.Qual(pkgDecimal, "Decimal") } else { g.stmt.Op("*").Qual(pkgDecimal, "Decimal") } case "float": - g.stmt.Float32() + removeOmitempty(g.tags) + if g.schema.Nullable { + g.stmt.Op("*").Float32() + } else { + g.stmt.Float32() + } case "double": fallthrough default: - g.stmt.Float64() + removeOmitempty(g.tags) + if g.schema.Nullable { + g.stmt.Op("*").Float64() + } else { + g.stmt.Float64() + } } case "boolean": - g.stmt.Bool() + removeOmitempty(g.tags) + if g.schema.Nullable { + g.stmt.Op("*").Bool() + } else { + g.stmt.Bool() + } case "array": // nolint: goconst + removeOmitempty(g.tags) err := g.g.goType(g.stmt.Index(), g.schema.Items.Value, g.tags).invoke() if err != nil { return err diff --git a/http/jsonapi/generator/generate_types.go b/http/jsonapi/generator/generate_types.go index 354ba9efa..9ccb7fd80 100644 --- a/http/jsonapi/generator/generate_types.go +++ b/http/jsonapi/generator/generate_types.go @@ -6,6 +6,7 @@ package generator import ( "fmt" "sort" + "strings" "github.com/dave/jennifer/jen" "github.com/getkin/kin-openapi/openapi3" @@ -439,3 +440,12 @@ func addJSONAPITags(tags map[string]string, kind, name string) { tags["jsonapi"] = fmt.Sprintf("%s,%s,omitempty", kind, name) tags["json"] = fmt.Sprintf("%s,omitempty", name) } + +func removeOmitempty(tags map[string]string) { + if v, ok := tags["jsonapi"]; ok { + tags["jsonapi"] = strings.ReplaceAll(v, ",omitempty", "") + } + if v, ok := tags["json"]; ok { + tags["json"] = strings.ReplaceAll(v, ",omitempty", "") + } +} diff --git a/http/jsonapi/generator/internal/fueling/open-api.json b/http/jsonapi/generator/internal/fueling/open-api.json index e1e31525d..d6251082b 100644 --- a/http/jsonapi/generator/internal/fueling/open-api.json +++ b/http/jsonapi/generator/internal/fueling/open-api.json @@ -1086,11 +1086,13 @@ "longitude": { "type": "number", "format": "float", - "example": 8.425 + "example": 8.425, + "nullable": true }, "stationName": { "type": "string", - "example": "PACE Station" + "example": "PACE Station", + "nullable": true }, "address": { "type": "object", diff --git a/http/jsonapi/generator/internal/fueling/open-api_test.go b/http/jsonapi/generator/internal/fueling/open-api_test.go index b569e54e1..be1ec20ca 100644 --- a/http/jsonapi/generator/internal/fueling/open-api_test.go +++ b/http/jsonapi/generator/internal/fueling/open-api_test.go @@ -16,14 +16,14 @@ import ( type ApproachingRequest struct { ID string `jsonapi:"primary,approaching,omitempty" valid:"uuid,optional"` // Approaching ID CarFuelType string `json:"carFuelType,omitempty" jsonapi:"attr,carFuelType,omitempty" valid:"required,in(e85|ron91|ron95_e5|ron95_e10|ron98|ron98_e5|ron100|diesel|diesel_gtl|diesel_b7|lpg|cng|h2|Truck Diesel|AdBlue)"` // Fuel type of the car - ExpectedAmount float32 `json:"expectedAmount,omitempty" jsonapi:"attr,expectedAmount,omitempty" valid:"required"` // Expected amount in liters for refuel + ExpectedAmount float32 `json:"expectedAmount" jsonapi:"attr,expectedAmount" valid:"required"` // Expected amount in liters for refuel } // ApproachingResponse ... type ApproachingResponse struct { ID string `jsonapi:"primary,approaching,omitempty" valid:"uuid,optional"` // Approaching ID CarFuelType string `json:"carFuelType,omitempty" jsonapi:"attr,carFuelType,omitempty" valid:"optional,in(e85|ron91|ron95_e5|ron95_e10|ron98|ron98_e5|ron100|diesel|diesel_gtl|diesel_b7|lpg|cng|h2|Truck Diesel|AdBlue|)"` // Fuel type of the car - ExpectedAmount float32 `json:"expectedAmount,omitempty" jsonapi:"attr,expectedAmount,omitempty" valid:"optional"` // Expected amount in liters for refuel + ExpectedAmount float32 `json:"expectedAmount" jsonapi:"attr,expectedAmount" valid:"optional"` // Expected amount in liters for refuel GasStation *GasStation `json:"gasStation,omitempty" jsonapi:"relation,gasStation,omitempty" valid:"optional"` PaymentMethods []*PaymentMethod `json:"paymentMethods,omitempty" jsonapi:"relation,paymentMethods,omitempty" valid:"optional"` } @@ -33,7 +33,7 @@ type FuelPrice struct { ID string `jsonapi:"primary,fuelPrice,omitempty" valid:"optional"` // Fuel Price ID Currency Currency `json:"currency,omitempty" jsonapi:"attr,currency,omitempty" valid:"optional"` FuelType string `json:"fuelType,omitempty" jsonapi:"attr,fuelType,omitempty" valid:"optional,in(e85|ron91|ron95_e5|ron95_e10|ron98|ron98_e5|ron100|diesel|diesel_gtl|diesel_b7|lpg|cng|h2|Truck Diesel|AdBlue|)"` // Example: "ron95_e10" - Price float32 `json:"price,omitempty" jsonapi:"attr,price,omitempty" valid:"optional"` // Price in liters + Price float32 `json:"price" jsonapi:"attr,price" valid:"optional"` // Price in liters ProductName string `json:"productName,omitempty" jsonapi:"attr,productName,omitempty" valid:"optional"` // Example: "Super E10" } @@ -60,10 +60,10 @@ type GasStation struct { ID string `jsonapi:"primary,gasStation,omitempty" valid:"uuid,optional"` // Gas Station ID Address GasStationAddress `json:"address,omitempty" jsonapi:"attr,address,omitempty" valid:"optional"` Amenities []string `json:"amenities,omitempty" jsonapi:"attr,amenities,omitempty" valid:"optional"` // Example: "[restaurant]" - Latitude float32 `json:"latitude,omitempty" jsonapi:"attr,latitude,omitempty" valid:"optional"` // Example: "49.013" - Longitude float32 `json:"longitude,omitempty" jsonapi:"attr,longitude,omitempty" valid:"optional"` // Example: "8.425" + Latitude float32 `json:"latitude" jsonapi:"attr,latitude" valid:"optional"` // Example: "49.013" + Longitude *float32 `json:"longitude" jsonapi:"attr,longitude" valid:"optional"` // Example: "8.425" OpeningHours []GasStationOpeningHours `json:"openingHours,omitempty" jsonapi:"attr,openingHours,omitempty" valid:"optional"` - StationName string `json:"stationName,omitempty" jsonapi:"attr,stationName,omitempty" valid:"optional"` // Example: "PACE Station" + StationName *string `json:"stationName,omitempty" jsonapi:"attr,stationName,omitempty" valid:"optional"` // Example: "PACE Station" FuelPrices []*FuelPrice `json:"fuelPrices,omitempty" jsonapi:"relation,fuelPrices,omitempty" valid:"optional"` Pumps []*Pump `json:"pumps,omitempty" jsonapi:"relation,pumps,omitempty" valid:"optional"` } @@ -86,8 +86,8 @@ type Pump struct { // PumpResponseVAT ... type PumpResponseVAT struct { - Amount float32 `json:"amount,omitempty" jsonapi:"attr,amount,omitempty" valid:"optional"` // Example: "9.72" - Rate float32 `json:"rate,omitempty" jsonapi:"attr,rate,omitempty" valid:"optional"` // Example: "0.19" + Amount float32 `json:"amount" jsonapi:"attr,amount" valid:"optional"` // Example: "9.72" + Rate float32 `json:"rate" jsonapi:"attr,rate" valid:"optional"` // Example: "0.19" } // PumpResponse ... @@ -95,12 +95,12 @@ type PumpResponse struct { ID string `jsonapi:"primary,pump,omitempty" valid:"uuid,optional"` // Pump ID VAT PumpResponseVAT `json:"VAT,omitempty" jsonapi:"attr,VAT,omitempty" valid:"optional"` Currency Currency `json:"currency,omitempty" jsonapi:"attr,currency,omitempty" valid:"optional"` - FuelAmount float32 `json:"fuelAmount,omitempty" jsonapi:"attr,fuelAmount,omitempty" valid:"optional"` // Fuel amount in liters - FuelType string `json:"fuelType,omitempty" jsonapi:"attr,fuelType,omitempty" valid:"optional"` // Example: "ron95_e10" - Identifier string `json:"identifier,omitempty" jsonapi:"attr,identifier,omitempty" valid:"optional"` // Pump identifier - PriceIncludingVAT float32 `json:"priceIncludingVAT,omitempty" jsonapi:"attr,priceIncludingVAT,omitempty" valid:"optional"` // Example: "61.09" - PriceWithoutVAT float32 `json:"priceWithoutVAT,omitempty" jsonapi:"attr,priceWithoutVAT,omitempty" valid:"optional"` // Example: "51.37" - ProductName string `json:"productName,omitempty" jsonapi:"attr,productName,omitempty" valid:"optional"` // Example: "Super E10" + FuelAmount float32 `json:"fuelAmount" jsonapi:"attr,fuelAmount" valid:"optional"` // Fuel amount in liters + FuelType string `json:"fuelType,omitempty" jsonapi:"attr,fuelType,omitempty" valid:"optional"` // Example: "ron95_e10" + Identifier string `json:"identifier,omitempty" jsonapi:"attr,identifier,omitempty" valid:"optional"` // Pump identifier + PriceIncludingVAT float32 `json:"priceIncludingVAT" jsonapi:"attr,priceIncludingVAT" valid:"optional"` // Example: "61.09" + PriceWithoutVAT float32 `json:"priceWithoutVAT" jsonapi:"attr,priceWithoutVAT" valid:"optional"` // Example: "51.37" + ProductName string `json:"productName,omitempty" jsonapi:"attr,productName,omitempty" valid:"optional"` // Example: "Super E10" Status PumpStatus `json:"status,omitempty" jsonapi:"attr,status,omitempty" valid:"optional"` } @@ -111,12 +111,12 @@ type PumpStatus string type TransactionRequest struct { ID string `jsonapi:"primary,transaction,omitempty" valid:"uuid,optional"` // Transaction ID Currency Currency `json:"currency,omitempty" jsonapi:"attr,currency,omitempty" valid:"optional"` - FuelingAppID string `json:"fuelingAppId,omitempty" jsonapi:"attr,fuelingAppId,omitempty" valid:"required,uuid"` // Location-based App ID - Mileage int64 `json:"mileage,omitempty" jsonapi:"attr,mileage,omitempty" valid:"optional"` // Current mileage in meters - PaymentToken string `json:"paymentToken,omitempty" jsonapi:"attr,paymentToken,omitempty" valid:"required"` // Example: "f106ac99-213c-4cf7-8c1b-1e841516026b" - PriceIncludingVAT float32 `json:"priceIncludingVAT,omitempty" jsonapi:"attr,priceIncludingVAT,omitempty" valid:"optional"` // Example: "69.34" - PumpID string `json:"pumpId,omitempty" jsonapi:"attr,pumpId,omitempty" valid:"required,uuid"` // Pump ID - Vin string `json:"vin,omitempty" jsonapi:"attr,vin,omitempty" valid:"optional"` // Example: "1B3EL46R36N102271" + FuelingAppID string `json:"fuelingAppId,omitempty" jsonapi:"attr,fuelingAppId,omitempty" valid:"required,uuid"` // Location-based App ID + Mileage int64 `json:"mileage" jsonapi:"attr,mileage" valid:"optional"` // Current mileage in meters + PaymentToken string `json:"paymentToken,omitempty" jsonapi:"attr,paymentToken,omitempty" valid:"required"` // Example: "f106ac99-213c-4cf7-8c1b-1e841516026b" + PriceIncludingVAT float32 `json:"priceIncludingVAT" jsonapi:"attr,priceIncludingVAT" valid:"optional"` // Example: "69.34" + PumpID string `json:"pumpId,omitempty" jsonapi:"attr,pumpId,omitempty" valid:"required,uuid"` // Pump ID + Vin string `json:"vin,omitempty" jsonapi:"attr,vin,omitempty" valid:"optional"` // Example: "1B3EL46R36N102271" } // Currency ... @@ -375,20 +375,20 @@ type ProcessPaymentCreated struct { ID string `jsonapi:"primary,transaction,omitempty" valid:"uuid,optional"` // Transaction ID VAT ProcessPaymentCreatedVAT `json:"VAT,omitempty" jsonapi:"attr,VAT,omitempty" valid:"optional"` Currency Currency `json:"currency,omitempty" jsonapi:"attr,currency,omitempty" valid:"optional"` - FuelingAppID string `json:"fuelingAppId,omitempty" jsonapi:"attr,fuelingAppId,omitempty" valid:"optional,uuid"` // Example: "c30bce97-b732-4390-af38-1ac6b017aa4c" - GasStationID string `json:"gasStationId,omitempty" jsonapi:"attr,gasStationId,omitempty" valid:"optional,uuid"` // Example: "a6ec9bd7-cf0b-416c-b24f-9ce65ab3dfe1" - Mileage int64 `json:"mileage,omitempty" jsonapi:"attr,mileage,omitempty" valid:"optional"` // Example: "66435" - PaymentToken string `json:"paymentToken,omitempty" jsonapi:"attr,paymentToken,omitempty" valid:"optional"` // Example: "f106ac99-213c-4cf7-8c1b-1e841516026b" - PriceIncludingVAT float32 `json:"priceIncludingVAT,omitempty" jsonapi:"attr,priceIncludingVAT,omitempty" valid:"optional"` // Example: "69.34" - PriceWithoutVAT float32 `json:"priceWithoutVAT,omitempty" jsonapi:"attr,priceWithoutVAT,omitempty" valid:"optional"` // Example: "58.27" - PumpID string `json:"pumpId,omitempty" jsonapi:"attr,pumpId,omitempty" valid:"optional,uuid"` // Example: "460ffaad-a3c1-4199-b69e-63949ccda82f" - Vin string `json:"vin,omitempty" jsonapi:"attr,vin,omitempty" valid:"optional"` // Example: "1B3EL46R36N102271" + FuelingAppID string `json:"fuelingAppId,omitempty" jsonapi:"attr,fuelingAppId,omitempty" valid:"optional,uuid"` // Example: "c30bce97-b732-4390-af38-1ac6b017aa4c" + GasStationID string `json:"gasStationId,omitempty" jsonapi:"attr,gasStationId,omitempty" valid:"optional,uuid"` // Example: "a6ec9bd7-cf0b-416c-b24f-9ce65ab3dfe1" + Mileage int64 `json:"mileage" jsonapi:"attr,mileage" valid:"optional"` // Example: "66435" + PaymentToken string `json:"paymentToken,omitempty" jsonapi:"attr,paymentToken,omitempty" valid:"optional"` // Example: "f106ac99-213c-4cf7-8c1b-1e841516026b" + PriceIncludingVAT float32 `json:"priceIncludingVAT" jsonapi:"attr,priceIncludingVAT" valid:"optional"` // Example: "69.34" + PriceWithoutVAT float32 `json:"priceWithoutVAT" jsonapi:"attr,priceWithoutVAT" valid:"optional"` // Example: "58.27" + PumpID string `json:"pumpId,omitempty" jsonapi:"attr,pumpId,omitempty" valid:"optional,uuid"` // Example: "460ffaad-a3c1-4199-b69e-63949ccda82f" + Vin string `json:"vin,omitempty" jsonapi:"attr,vin,omitempty" valid:"optional"` // Example: "1B3EL46R36N102271" } // ProcessPaymentCreatedVAT ... type ProcessPaymentCreatedVAT struct { - Amount float32 `json:"amount,omitempty" jsonapi:"attr,amount,omitempty" valid:"optional"` // Example: "11.07" - Rate float32 `json:"rate,omitempty" jsonapi:"attr,rate,omitempty" valid:"optional"` // Example: "0.19" + Amount float32 `json:"amount" jsonapi:"attr,amount" valid:"optional"` // Example: "11.07" + Rate float32 `json:"rate" jsonapi:"attr,rate" valid:"optional"` // Example: "0.19" } /* diff --git a/http/jsonapi/generator/internal/pay/open-api_test.go b/http/jsonapi/generator/internal/pay/open-api_test.go index e857dc086..bd03c3a3b 100644 --- a/http/jsonapi/generator/internal/pay/open-api_test.go +++ b/http/jsonapi/generator/internal/pay/open-api_test.go @@ -105,7 +105,7 @@ type PaymentTokenCreateApplePay struct { // TransactionRequestFueling ... type TransactionRequestFueling struct { AppID string `json:"appId,omitempty" jsonapi:"attr,appId,omitempty" valid:"required,uuid"` // Location-based App ID - Mileage int64 `json:"mileage,omitempty" jsonapi:"attr,mileage,omitempty" valid:"required"` // Current mileage in meters + Mileage int64 `json:"mileage" jsonapi:"attr,mileage" valid:"required"` // Current mileage in meters PumpID string `json:"pumpId,omitempty" jsonapi:"attr,pumpId,omitempty" valid:"required,uuid"` // Pump ID Vin string `json:"vin,omitempty" jsonapi:"attr,vin,omitempty" valid:"required"` // Example: "1B3EL46R36N102271" } @@ -720,7 +720,7 @@ type DeletePaymentMethodRequest struct { // AuthorizePaymentMethodOK ... type AuthorizePaymentMethodOK struct { ID string `jsonapi:"primary,paymentToken,omitempty" valid:"uuid,optional"` // paymentToken ID (NOT the token value) - Amount float64 `json:"amount,omitempty" jsonapi:"attr,amount,omitempty" valid:"optional"` // Example: "65.49" + Amount float64 `json:"amount" jsonapi:"attr,amount" valid:"optional"` // Example: "65.49" Currency string `json:"currency,omitempty" jsonapi:"attr,currency,omitempty" valid:"optional"` // Currency as specified in ISO-4217. Value string `json:"value,omitempty" jsonapi:"attr,value,omitempty" valid:"optional"` // The actual token value. Note that the format is subject to change. Treat transparently. } @@ -763,7 +763,7 @@ func (w *authorizePaymentMethodResponseWriter) OK(data *AuthorizePaymentMethodOK // AuthorizePaymentMethodContent ... type AuthorizePaymentMethodContent struct { ID string `jsonapi:"primary,paymentToken,omitempty" valid:"uuid,optional"` // ID of the new paymentToken. - Amount float64 `json:"amount,omitempty" jsonapi:"attr,amount,omitempty" valid:"required"` // Example: "65.49" + Amount float64 `json:"amount" jsonapi:"attr,amount" valid:"required"` // Example: "65.49" Currency string `json:"currency,omitempty" jsonapi:"attr,currency,omitempty" valid:"required"` // Currency as specified in ISO-4217. } @@ -880,7 +880,7 @@ type ProcessPaymentCreatedVAT struct { // ProcessPaymentCreatedFueling ... type ProcessPaymentCreatedFueling struct { AppID string `json:"appId,omitempty" jsonapi:"attr,appId,omitempty" valid:"required,uuid"` // Example: "c30bce97-b732-4390-af38-1ac6b017aa4c" - Mileage int64 `json:"mileage,omitempty" jsonapi:"attr,mileage,omitempty" valid:"required"` // Example: "66435" + Mileage int64 `json:"mileage" jsonapi:"attr,mileage" valid:"required"` // Example: "66435" PumpID string `json:"pumpId,omitempty" jsonapi:"attr,pumpId,omitempty" valid:"required,uuid"` // Example: "460ffaad-a3c1-4199-b69e-63949ccda82f" Vin string `json:"vin,omitempty" jsonapi:"attr,vin,omitempty" valid:"required"` // Example: "1B3EL46R36N102271" } diff --git a/http/jsonapi/generator/internal/poi/open-api.json b/http/jsonapi/generator/internal/poi/open-api.json index f6983ed44..8a8b68b5c 100644 --- a/http/jsonapi/generator/internal/poi/open-api.json +++ b/http/jsonapi/generator/internal/poi/open-api.json @@ -201,7 +201,8 @@ }, "required": false, "description": "Radius in meters", - "example": 5.4 + "example": 5.4, + "nullable": true }, { "in": "query", @@ -228,7 +229,8 @@ "enum": [ true, false - ] + ], + "nullable": true }, "example": true, "description": "Reduces the opening hours rules. After compilation only rules with the action open will remain in the response." @@ -3328,7 +3330,8 @@ "type": "number", "format": "decimal", "example": 1.449, - "description": "The price at this point in time" + "description": "The price at this point in time", + "nullable": true } } } diff --git a/http/jsonapi/generator/internal/poi/open-api_test.go b/http/jsonapi/generator/internal/poi/open-api_test.go index 361afc50a..e86f1254b 100644 --- a/http/jsonapi/generator/internal/poi/open-api_test.go +++ b/http/jsonapi/generator/internal/poi/open-api_test.go @@ -158,8 +158,8 @@ type GasStation struct { Brand string `json:"brand,omitempty" jsonapi:"attr,brand,omitempty" valid:"optional"` // Example: "Total" Contact GasStationContact `json:"contact,omitempty" jsonapi:"attr,contact,omitempty" valid:"optional"` Food []string `json:"food,omitempty" jsonapi:"attr,food,omitempty" valid:"optional,in(bakery|bistro|cafe|restaurant|takeaway|)"` // Example: "[restaurant bakery]" - Latitude float32 `json:"latitude,omitempty" jsonapi:"attr,latitude,omitempty" valid:"optional"` // Example: "49.013" - Longitude float32 `json:"longitude,omitempty" jsonapi:"attr,longitude,omitempty" valid:"optional"` // Example: "8.425" + Latitude float32 `json:"latitude" jsonapi:"attr,latitude" valid:"optional"` // Example: "49.013" + Longitude float32 `json:"longitude" jsonapi:"attr,longitude" valid:"optional"` // Example: "8.425" LoyaltyPrograms []string `json:"loyaltyPrograms,omitempty" jsonapi:"attr,loyaltyPrograms,omitempty" valid:"optional,in(deutschlandCard|payback|shellClubsmart|totalClub|)"` // Example: "[payback]" OpeningHours CommonOpeningHours `json:"openingHours,omitempty" jsonapi:"attr,openingHours,omitempty" valid:"optional"` PaymentMethods []string `json:"paymentMethods,omitempty" jsonapi:"attr,paymentMethods,omitempty" valid:"optional,in(americanExpress|applyPay|aralKomfort|aviaCard|barclays|bayWaCard|cash|dinersClub|dkv|essoCard|essoVoucher|euroshell|ffCard|girocard|googlePay|hemMycard|jetCard|logPay|maestro|masterCard|novofleet|pacePay|paypal|routex|sepaDirectDebit|starFleetCard|tndCard|totalCard|uta|visa|vPay|westfalenCard|)"` // Example: "[sepaDirectDebit visa]" @@ -225,15 +225,15 @@ type LocationBasedAppsWithRefs []*LocationBasedAppWithRefs // MoveRequest Creates a new event object at lat/lng from this POI ID type MoveRequest struct { - ID string `jsonapi:"primary,movePoi,omitempty" valid:"uuid,optional"` // UUID of the POI that is going to be moved - Latitude float32 `json:"latitude,omitempty" jsonapi:"attr,latitude,omitempty" valid:"optional"` // Latitude in degrees - Longitude float32 `json:"longitude,omitempty" jsonapi:"attr,longitude,omitempty" valid:"optional"` // Longitude in degrees + ID string `jsonapi:"primary,movePoi,omitempty" valid:"uuid,optional"` // UUID of the POI that is going to be moved + Latitude float32 `json:"latitude" jsonapi:"attr,latitude" valid:"optional"` // Latitude in degrees + Longitude float32 `json:"longitude" jsonapi:"attr,longitude" valid:"optional"` // Longitude in degrees } // POI ... type POI struct { ID string `jsonapi:"primary,GasStation,omitempty" valid:"uuid,optional"` // POI ID - Active bool `json:"active,omitempty" jsonapi:"attr,active,omitempty" valid:"optional"` + Active bool `json:"active" jsonapi:"attr,active" valid:"optional"` Boundary CommonGeoJSONPolygon `json:"boundary,omitempty" jsonapi:"attr,boundary,omitempty" valid:"optional"` CountryID CommonCountryID `json:"countryId,omitempty" jsonapi:"attr,countryId,omitempty" valid:"optional"` CreatedAt *time.Time `json:"createdAt,omitempty" jsonapi:"attr,createdAt,omitempty,iso8601" valid:"optional"` @@ -275,7 +275,7 @@ type PolicyRule struct { // PolicyRulePriority ... type PolicyRulePriority struct { SourceID string `json:"sourceId,omitempty" jsonapi:"attr,sourceId,omitempty" valid:"required,uuid"` // Tracks who did last change - TimeToLive float64 `json:"timeToLive,omitempty" jsonapi:"attr,timeToLive,omitempty" valid:"optional"` // Time to live in seconds (in relation to other entries) + TimeToLive float64 `json:"timeToLive" jsonapi:"attr,timeToLive" valid:"optional"` // Time to live in seconds (in relation to other entries) } // PriceHistoryFuelPrices ... @@ -332,7 +332,7 @@ type Sources []*Source // SubscriptionConditionsFuelPrice Condition on the fuelPrice of a gas station. type SubscriptionConditionsFuelPrice struct { - Lt float64 `json:"lt,omitempty" jsonapi:"attr,lt,omitempty" valid:"optional"` /* + Lt float64 `json:"lt" jsonapi:"attr,lt" valid:"optional"` /* Fuel price is less then given amount. Amount is always given in the currency of the gas station. The units are not scaled, for `EUR`, the value 1.3 means 1 euro and 30 cents. */ } @@ -3202,7 +3202,7 @@ type GetGasStationsRequest struct { ParamFilterLongitude float32 `valid:"optional"` ParamFilterRadius float32 `valid:"optional"` ParamFilterBoundingBox []float32 `valid:"optional"` - ParamCompileOpeningHours bool `valid:"optional,in(true|false|)"` + ParamCompileOpeningHours *bool `valid:"optional,in(true|false|)"` ParamFilterSource string `valid:"optional,uuid"` } @@ -3831,7 +3831,7 @@ type GetSubscriptionsContentItem struct { // GetSubscriptionsContentConditionsFuelPrice Condition on the fuelPrice of a gas station. type GetSubscriptionsContentConditionsFuelPrice struct { - Lt float64 `json:"lt,omitempty" jsonapi:"attr,lt,omitempty" valid:"optional"` /* + Lt float64 `json:"lt" jsonapi:"attr,lt" valid:"optional"` /* Fuel price is less then given amount. Amount is always given in the currency of the gas station. The units are not scaled, for `EUR`, the value 1.3 means 1 euro and 30 cents. */ } diff --git a/maintenance/tracing/tracing.go b/maintenance/tracing/tracing.go index 5aa6553b2..edd2ac99c 100755 --- a/maintenance/tracing/tracing.go +++ b/maintenance/tracing/tracing.go @@ -76,9 +76,8 @@ type traceLogHandler struct { // Trace the service function handler execution func (h *traceLogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - var handlerSpan opentracing.Span - handlerSpan = opentracing.SpanFromContext(ctx) + handlerSpan := opentracing.SpanFromContext(ctx) handlerSpan.LogFields(olog.String("req_id", log.RequestID(r)), olog.String("path", r.URL.Path), olog.String("method", r.Method)) diff --git a/tools/testserver/main.go b/tools/testserver/main.go index f1fbeb871..d62d9bbb6 100755 --- a/tools/testserver/main.go +++ b/tools/testserver/main.go @@ -7,10 +7,11 @@ import ( "context" "encoding/json" "fmt" - "github.com/pace/bricks/http/transport" "net/http" "time" + "github.com/pace/bricks/http/transport" + "github.com/pace/bricks/maintenance/health/servicehealthcheck" "github.com/opentracing/opentracing-go" @@ -121,10 +122,10 @@ func main() { return } var doc interface{} - row.ScanDoc(&doc) + row.ScanDoc(&doc) // nolint: errcheck w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(doc) + json.NewEncoder(w).Encode(doc) // nolint: errcheck }) h.HandleFunc("/panic", func(w http.ResponseWriter, r *http.Request) { @@ -187,13 +188,13 @@ func fetchSunsetandSunrise(ctx context.Context) string { span.LogFields(olog.Float64("lat", lat), olog.Float64("lon", lon)) url := fmt.Sprintf("https://api.sunrise-sunset.org/json?lat=%f&lng=%f&date=today", lat, lon) - req, err := http.NewRequestWithContext(ctx,"GET", url, nil) + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) if err != nil { log.Fatal(err) } c := &http.Client{ - Transport: transport.NewDefaultTransportChain(), + Transport: transport.NewDefaultTransportChain(), } resp, err := c.Do(req) if err != nil { diff --git a/tools/testserver/simple/open-api.go b/tools/testserver/simple/open-api.go index d6f0cbd68..47c68981f 100644 --- a/tools/testserver/simple/open-api.go +++ b/tools/testserver/simple/open-api.go @@ -15,7 +15,7 @@ import ( GetTestHandler handles request/response marshaling and validation for Get /beta/test */ -func GetTestHandler(service Service) http.Handler { +func GetTestHandler(service GetTestHandlerService) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer errors.HandleRequest("GetTestHandler", w, r) @@ -79,22 +79,51 @@ type GetTestRequest struct { Request *http.Request `valid:"-"` } -// Service interface for all handlers -type Service interface { +// Service interface for GetTestHandler handler +type GetTestHandlerService interface { // GetTest Test GetTest(context.Context, GetTestResponseWriter, *GetTestRequest) error } +// Legacy Interface. +// Use this if you want to fully implement a service. +type Service interface { + GetTestHandlerService +} + +// GetTestHandlerWithFallbackHelper helper that checks if the given service fulfills the interface. Returns fallback handler if not, otherwise returns matching handler. +func GetTestHandlerWithFallbackHelper(service interface{}, fallback http.Handler) http.Handler { + if service, ok := service.(GetTestHandlerService); ok { + return GetTestHandler(service) + } else { + return fallback + } +} + +/* +Router implements: PACE Payment API + +Welcome to the PACE Payment API documentation. +This API is responsible for managing payment methods for users as well as authorizing payments on behalf of PACE services. +*/ +func Router(service interface{}) *mux.Router { + router := mux.NewRouter() + // Subrouter s1 - Path: /pay + s1 := router.PathPrefix("/pay").Subrouter() + s1.Methods("GET").Path("/beta/test").Name("GetTest").Handler(GetTestHandlerWithFallbackHelper(service, router.NotFoundHandler)) + return router +} + /* Router implements: PACE Payment API Welcome to the PACE Payment API documentation. This API is responsible for managing payment methods for users as well as authorizing payments on behalf of PACE services. */ -func Router(service Service) *mux.Router { +func RouterWithFallback(service interface{}, fallback http.Handler) *mux.Router { router := mux.NewRouter() // Subrouter s1 - Path: /pay s1 := router.PathPrefix("/pay").Subrouter() - s1.Methods("GET").Path("/beta/test").Handler(GetTestHandler(service)).Name("GetTest") + s1.Methods("GET").Path("/beta/test").Name("GetTest").Handler(GetTestHandlerWithFallbackHelper(service, fallback)) return router }