clear and update
This commit is contained in:
parent
bcbd88d728
commit
8bae227154
|
@ -22,3 +22,4 @@
|
|||
go.work
|
||||
|
||||
/swaggers
|
||||
/res
|
||||
|
|
153
client.kt
153
client.kt
|
@ -1,153 +0,0 @@
|
|||
package client
|
||||
|
||||
import io.micronaut.http.HttpResponse
|
||||
import io.micronaut.http.annotation.*
|
||||
import io.micronaut.http.client.annotation.Client
|
||||
|
||||
@Client(value = "INPUT URL")
|
||||
interface GDSClient {
|
||||
|
||||
@Get(value = "/sales/dispatch/places")
|
||||
fun getDispatchPlaces(
|
||||
@Header authorization: String?,
|
||||
): HttpResponse<List<PlaceAVS>>
|
||||
|
||||
@Post(value = "/sales/order/{orderId}/passenger")
|
||||
fun addPassenger(
|
||||
@Header authorization: String?,
|
||||
@PathVariable orderId: Int,
|
||||
): HttpResponse<TicketAVS>
|
||||
|
||||
@Put(value = "/sales/session/open")
|
||||
fun openSession(
|
||||
@Header authorization: String?,
|
||||
): HttpResponse<SessionAVS>
|
||||
|
||||
@Get(value = "/sales/trip/{tripId}/document/types")
|
||||
fun getDocumentTypes(
|
||||
@Header authorization: String?,
|
||||
@PathVariable tripId: Int,
|
||||
): HttpResponse<List<DocTypeAVS>>
|
||||
|
||||
@Get(value = "/sales/arrival/places")
|
||||
fun getArrivalPlaces(
|
||||
@Header authorization: String?,
|
||||
): HttpResponse<List<PlaceAVS>>
|
||||
|
||||
@Put(value = "/sales/order/tickets/{ticketId}/passenger")
|
||||
fun updateTickerPassenger(
|
||||
@Header authorization: String?,
|
||||
@PathVariable ticketId: Int,
|
||||
): HttpResponse<>
|
||||
|
||||
@Get(value = "/sales/order/{orderId}")
|
||||
fun getOrder(
|
||||
@Header authorization: String?,
|
||||
@PathVariable orderId: Int,
|
||||
): HttpResponse<OrderAVS>
|
||||
|
||||
@Delete(value = "/sales/order/{orderId}")
|
||||
fun cancelOrder(
|
||||
@Header authorization: String?,
|
||||
@PathVariable orderId: Int,
|
||||
): HttpResponse<OrderAVS>
|
||||
|
||||
@Post(value = "/sales/order/{orderId}/confirm/payment/by/{payForm}")
|
||||
fun confirmPayment(
|
||||
@Header authorization: String?,
|
||||
@PathVariable orderId: Int,
|
||||
@PathVariable payForm: String,
|
||||
): HttpResponse<OrderAVS>
|
||||
|
||||
@Get(value = "/sales/ticket/series/{series}/number/{number}/return/calculation")
|
||||
fun getReturnInfo(
|
||||
@Header authorization: String?,
|
||||
@PathVariable series: String,
|
||||
@PathVariable number: String,
|
||||
): HttpResponse<TicketAVS>
|
||||
|
||||
@Get(value = "/sales/trip/{tripId}/from/station/{dispatchStationId}/to/station/{arrivalStationId}/book/{ticketCount}")
|
||||
fun bookOrder(
|
||||
@Header authorization: String?,
|
||||
@PathVariable tripId: String,
|
||||
@PathVariable dispatchStationId: String,
|
||||
@PathVariable arrivalStationId: String,
|
||||
@PathVariable ticketCount: Int,
|
||||
@PathVariable baggageCount: Int?,
|
||||
): HttpResponse<OrderAVS>
|
||||
|
||||
@Get(value = "/settings")
|
||||
fun getSettings(
|
||||
): HttpResponse<Settings>
|
||||
|
||||
@Post(value = "/auth/token")
|
||||
fun login(
|
||||
): HttpResponse<AuthDTO>
|
||||
|
||||
@Get(value = "/kassa")
|
||||
fun index(
|
||||
): HttpResponse<>
|
||||
|
||||
@Get(value = "/sales/dispatch/place/{placeId}/stations")
|
||||
fun getDispatchStations(
|
||||
@Header authorization: String?,
|
||||
@PathVariable placeId: Int,
|
||||
): HttpResponse<List<StationAVS>>
|
||||
|
||||
@Post(value = "/sales/order/{orderId}/baggage")
|
||||
fun addBaggage(
|
||||
@Header authorization: String?,
|
||||
@PathVariable orderId: Int,
|
||||
): HttpResponse<TicketAVS>
|
||||
|
||||
@Put(value = "/sales/session/close")
|
||||
fun closeSession(
|
||||
@Header authorization: String?,
|
||||
): HttpResponse<SessionAVS>
|
||||
|
||||
@Get(value = "/sales/trip/{tripId}/from/{dispatchStationId}/to/{arrivalStationId}/seats/free")
|
||||
fun getSeatsFree(
|
||||
@Header authorization: String?,
|
||||
@PathVariable tripId: Int,
|
||||
@PathVariable dispatchStationId: Int,
|
||||
@PathVariable arrivalStationId: Int,
|
||||
): HttpResponse<List<>>
|
||||
|
||||
@Get(value = "/sales/trip/{tripId}/ticket/types")
|
||||
fun getTicketTypes(
|
||||
@Header authorization: String?,
|
||||
@PathVariable tripId: String,
|
||||
): HttpResponse<List<TicketTypeAVS>>
|
||||
|
||||
@Get(value = "/countries")
|
||||
fun getCountries(
|
||||
): HttpResponse<List<CountryCode>>
|
||||
|
||||
@Get(value = "/sales/arrival/place/{placeId}/stations")
|
||||
fun getArrivalStations(
|
||||
@Header authorization: String?,
|
||||
@PathVariable placeId: Int,
|
||||
): HttpResponse<List<StationAVS>>
|
||||
|
||||
@Get(value = "/sales/dispatch/station/{dispatchStationId}/arrival/place/{arrivalPlaceId}/{date}/trips")
|
||||
fun getTrips(
|
||||
@Header authorization: String?,
|
||||
@PathVariable dispatchStationId: Int,
|
||||
@PathVariable arrivalPlaceId: Int,
|
||||
@PathVariable date: String,
|
||||
): HttpResponse<List<TripKassa>>
|
||||
|
||||
@Delete(value = "/sales/order/tickets/{ticketId}")
|
||||
fun cancelTicket(
|
||||
@Header authorization: String?,
|
||||
@PathVariable ticketId: Int,
|
||||
): HttpResponse<TicketAVS>
|
||||
|
||||
@Post(value = "/sales/ticket/{ticketId}/return")
|
||||
fun returnTicket(
|
||||
@Header authorization: String?,
|
||||
@PathVariable ticketId: Int,
|
||||
): HttpResponse<TicketAVS>
|
||||
|
||||
}
|
||||
|
50
main.go
50
main.go
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -92,11 +93,11 @@ func main() {
|
|||
|
||||
res := toMicronautKotlin(config)
|
||||
|
||||
if err := os.WriteFile("models.kt", []byte(res["models"]), 0600); err != nil {
|
||||
if err := os.WriteFile("res/models.kt", []byte(res["models"]), 0600); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile("client.kt", []byte(res["client"]), 0600); err != nil {
|
||||
if err := os.WriteFile("res/client.kt", []byte(res["client"]), 0600); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -122,11 +123,23 @@ func toMicronautKotlin(config *config) map[string]string {
|
|||
sbClient.WriteString("\n")
|
||||
sbClient.WriteString("@Client(value = \"INPUT URL\")\n")
|
||||
sbClient.WriteString("interface GDSClient {\n\n")
|
||||
for path, methods := range config.Paths {
|
||||
for method, v := range methods {
|
||||
sbClient.WriteString(fmt.Sprintf("\t@%s(value = \"%s\")\n", toMicronautKotlinMethod(method), path))
|
||||
sbClient.WriteString(fmt.Sprintf("\tfun %s(\n", v.OperationID))
|
||||
|
||||
pathKeys := getSortKeys(config.Paths)
|
||||
for _, path := range pathKeys {
|
||||
methods := config.Paths[path]
|
||||
methodKeys := getSortKeys(methods)
|
||||
for _, method := range methodKeys {
|
||||
v := methods[method]
|
||||
|
||||
if v.Summary != "" {
|
||||
sbClient.WriteString(fmt.Sprintf("\t// %s\n", v.Summary))
|
||||
}
|
||||
sbClient.WriteString(fmt.Sprintf("\t@%s(value = \"%s\")\n", toMicronautKotlinMethod(method), path))
|
||||
sbClient.WriteString(fmt.Sprintf("\tfun %s(", v.OperationID))
|
||||
|
||||
if len(v.Parameters) != 0 || v.RequestBody != nil {
|
||||
sbClient.WriteString("\n")
|
||||
}
|
||||
for _, p := range v.Parameters {
|
||||
sbClient.WriteString("\t\t")
|
||||
switch p.In {
|
||||
|
@ -139,12 +152,20 @@ func toMicronautKotlin(config *config) map[string]string {
|
|||
}
|
||||
sbClient.WriteString(fmt.Sprintf(" %s: %s,\n", p.Name, p.Schema.toKt()))
|
||||
}
|
||||
if v.RequestBody != nil {
|
||||
sbClient.WriteString(fmt.Sprintf("\t\t@Body %s: %s,\n", "body", v.RequestBody.Content.ApplicationJSON.Schema.toKt()))
|
||||
}
|
||||
if len(v.Parameters) != 0 || v.RequestBody != nil {
|
||||
sbClient.WriteString("\t")
|
||||
}
|
||||
|
||||
// todo body and test
|
||||
sbClient.WriteString(")")
|
||||
|
||||
sbClient.WriteString("\t")
|
||||
sbClient.WriteString(fmt.Sprintf("): HttpResponse<%s>\n", v.Responses.Num200.Content.ApplicationJSON.Schema.toKt()))
|
||||
sbClient.WriteString("\n")
|
||||
resp := v.Responses.Num200.Content.ApplicationJSON.Schema.toKt()
|
||||
if resp != "" {
|
||||
sbClient.WriteString(fmt.Sprintf(": HttpResponse<%s>", resp))
|
||||
}
|
||||
sbClient.WriteString("\n\n")
|
||||
}
|
||||
}
|
||||
sbClient.WriteString("}\n\n")
|
||||
|
@ -189,3 +210,12 @@ func refToName(ref string) string {
|
|||
arr := strings.Split(ref, "/")
|
||||
return arr[len(arr)-1]
|
||||
}
|
||||
|
||||
func getSortKeys[T any](m map[string]T) []string {
|
||||
keys := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
return keys
|
||||
}
|
||||
|
|
202
models.kt
202
models.kt
|
@ -1,202 +0,0 @@
|
|||
package models
|
||||
|
||||
data class CountryAVS(
|
||||
var id: String?,
|
||||
var name: String?,
|
||||
)
|
||||
|
||||
data class IdentifierDocumentAVS(
|
||||
var number: String,
|
||||
var series: String?,
|
||||
var type: DocTypeAVS,
|
||||
)
|
||||
|
||||
data class SessionAVS(
|
||||
var id: String,
|
||||
)
|
||||
|
||||
data class RegionAVS(
|
||||
var name: String?,
|
||||
var type: String?,
|
||||
var country: CountryAVS?,
|
||||
var id: String?,
|
||||
)
|
||||
|
||||
data class Settings(
|
||||
var defaultPlaceId: String,
|
||||
var defaultStationId: String,
|
||||
)
|
||||
|
||||
data class AreaAVS(
|
||||
var name: String?,
|
||||
var type: String?,
|
||||
var id: String?,
|
||||
)
|
||||
|
||||
data class AuthRequest(
|
||||
var username: String,
|
||||
var password: String,
|
||||
var ws: String,
|
||||
)
|
||||
|
||||
data class PassengerAVS(
|
||||
var passenger: PassengerPartPassengerAVS,
|
||||
var identifierDocument: IdentifierDocumentAVS,
|
||||
var benefitDocument: BenefitDocumentAVS?,
|
||||
var categoryId: Int,
|
||||
)
|
||||
|
||||
data class PassengerPartPassengerAVS(
|
||||
var citizenship: CitizenshipAVS,
|
||||
var docNum: String?,
|
||||
var docSeries: String?,
|
||||
var docTypeId: String?,
|
||||
var gender: String,
|
||||
var birthDate: String?,
|
||||
var id: Int?,
|
||||
var lastName: String,
|
||||
var middleName: String?,
|
||||
var phone: String?,
|
||||
var firstName: String,
|
||||
)
|
||||
|
||||
data class TicketCategoryAVS(
|
||||
var requiredDocTypes: List<DocumentTypeAVS>?,
|
||||
var id: String,
|
||||
var name: String,
|
||||
var price: Double,
|
||||
)
|
||||
|
||||
data class TicketTypeAVS(
|
||||
var id: String,
|
||||
var name: String,
|
||||
var requiredDocTypes: List<RequiredDocTypeAVS>?,
|
||||
)
|
||||
|
||||
data class PlaceAVS(
|
||||
var region: RegionAVS?,
|
||||
var area: AreaAVS?,
|
||||
var id: String?,
|
||||
var name: String?,
|
||||
var type: String?,
|
||||
)
|
||||
|
||||
data class StationAVS(
|
||||
var id: String?,
|
||||
var name: String?,
|
||||
var shortName: String?,
|
||||
var address: String?,
|
||||
)
|
||||
|
||||
data class BusSeatAVS(
|
||||
var id: String,
|
||||
var name: String,
|
||||
var num: Int,
|
||||
)
|
||||
|
||||
data class DeparturesKassa(
|
||||
var arrivals: List<ArrivalsAVS>,
|
||||
var place: PlaceAVS?,
|
||||
var station: StationAVS?,
|
||||
var time: String?,
|
||||
var tripId: String?,
|
||||
var priceText: String,
|
||||
)
|
||||
|
||||
data class DocTypeAVS(
|
||||
var id: String,
|
||||
var name: String,
|
||||
)
|
||||
|
||||
data class AuthDTO(
|
||||
var token: String?,
|
||||
var refreshToken: String?,
|
||||
var expireAt: Int?,
|
||||
)
|
||||
|
||||
data class OrderAVS(
|
||||
var orderId: Int,
|
||||
var tickets: List<TicketAVS>,
|
||||
var expirationTime: String?,
|
||||
var confirmError: String?,
|
||||
)
|
||||
|
||||
data class CitizenshipAVS(
|
||||
var id: String,
|
||||
var name: String,
|
||||
)
|
||||
|
||||
data class CountryCode(
|
||||
var name: String,
|
||||
var code: String,
|
||||
)
|
||||
|
||||
data class RequiredDocTypeAVS(
|
||||
var id: String,
|
||||
var name: String,
|
||||
)
|
||||
|
||||
data class TicketAVS(
|
||||
var category: TicketCategoryAVS?,
|
||||
var number: String?,
|
||||
var passenger: PassengerPartPassengerAVS?,
|
||||
var seat: BusSeatAVS?,
|
||||
var series: String?,
|
||||
var ticketClass: String,
|
||||
var benefitDocument: BenefitDocumentAVS?,
|
||||
var id: String,
|
||||
var identifierDocument: IdentifierDocumentAVS?,
|
||||
var payments: List<TicketPaymentAVS>?,
|
||||
var status: String,
|
||||
)
|
||||
|
||||
data class TripKassa(
|
||||
var bus: BusAVS?,
|
||||
var seatsText: String,
|
||||
var carrier: CarrierAVS?,
|
||||
var changeSeatAllow: Boolean?,
|
||||
var departures: List<DeparturesKassa>,
|
||||
var name: String?,
|
||||
)
|
||||
|
||||
data class BenefitDocumentAVS(
|
||||
var issuer: String?,
|
||||
var number: String,
|
||||
var series: String?,
|
||||
var type: DocTypeAVS,
|
||||
var beginDate: String?,
|
||||
var endDate: String?,
|
||||
var issueDate: String?,
|
||||
)
|
||||
|
||||
data class BusAVS(
|
||||
var capacity: Int?,
|
||||
var freeSeats: Int?,
|
||||
var info: String?,
|
||||
)
|
||||
|
||||
data class CarrierAVS(
|
||||
var inn: String?,
|
||||
var name: String?,
|
||||
)
|
||||
|
||||
data class ArrivalsAVS(
|
||||
var price: Int?,
|
||||
var station: StationAVS?,
|
||||
var time: String?,
|
||||
)
|
||||
|
||||
data class DocumentTypeAVS(
|
||||
var id: String,
|
||||
var name: String,
|
||||
)
|
||||
|
||||
data class TicketPaymentAVS(
|
||||
var amount: Double,
|
||||
var from: String?,
|
||||
var group: String,
|
||||
var id: String,
|
||||
var name: String,
|
||||
var nds: String,
|
||||
)
|
||||
|
Loading…
Reference in New Issue