github.com/grokify/go-ringcentral-client@v0.3.31/codegen/specs-engagevoice_v3.0.0/convert/java_to_oas3.go (about) 1 package main 2 3 import ( 4 "context" 5 "fmt" 6 "io/ioutil" 7 "strings" 8 9 oas3 "github.com/getkin/kin-openapi/openapi3" 10 "github.com/grokify/mogo/errors/errorsutil" 11 "github.com/grokify/mogo/fmt/fmtutil" 12 "github.com/grokify/mogo/os/osutil" 13 "github.com/grokify/mogo/type/stringsutil" 14 "github.com/grokify/spectrum/openapi3" 15 "github.com/grokify/spectrum/openapi3/springopenapi3" 16 "github.com/rs/zerolog/log" 17 ) 18 19 func ReadOas3Spec(file string, validate bool) (*openapi3.Spec, error) { 20 bytes, err := ioutil.ReadFile(file) 21 if err != nil { 22 return nil, errorsutil.Wrap(err, fmt.Sprintf("Filename [%v]", file)) 23 } 24 swag := &openapi3.Spec{} 25 err = swag.UnmarshalJSON(bytes) 26 if err != nil { 27 return nil, errorsutil.Wrap(err, fmt.Sprintf("Filename [%v]", file)) 28 } 29 if validate { 30 err = swag.Validate(context.Background()) 31 return swag, errorsutil.Wrap(err, fmt.Sprintf("Filename [%v]", file)) 32 } 33 return swag, nil 34 } 35 36 func main() { 37 if 1 == 1 { 38 file := "../openapi-spec_agents.json" 39 40 swag, err := ReadOas3Spec(file, true) 41 if err != nil { 42 log.Fatal().Err(err) 43 } 44 fmtutil.PrintJSON(swag) 45 panic("Z") 46 } 47 48 bytes, err := ioutil.ReadFile("_class_agent.java") 49 if err != nil { 50 log.Fatal().Err(err) 51 } 52 fmt.Println(string(bytes)) 53 lines := strings.Split(string(bytes), "\n") 54 fmtutil.PrintJSON(lines) 55 lines = stringsutil.SliceTrim(lines, " \t", true) 56 fmtutil.PrintJSON(lines) 57 //panic("Z") 58 59 columnsRaw := springopenapi3.ParseSpringCodeColumnsRaw(lines) 60 fmtutil.PrintJSON(columnsRaw) 61 62 schema := oas3.Schema{Properties: map[string]*oas3.SchemaRef{}} 63 fmtutil.PrintJSON(schema) 64 65 if 1 == 0 { 66 // line := "private Boolean userManagedByRC;" 67 line := "private Boolean userManagedByRC = false;" 68 name, prop, err := springopenapi3.ParseSpringLineToSchema(line) 69 if err != nil { 70 log.Fatal().Err(err) 71 } 72 fmt.Printf("NAME [%v]\n", name) 73 fmtutil.PrintJSON(prop) 74 panic("Z") 75 } 76 77 mss, err := springopenapi3.ParseSpringPropertyLinesSliceToSchema(columnsRaw) 78 if err != nil { 79 log.Info().Msg("S1") 80 log.Fatal().Err(err) 81 } 82 fmtutil.PrintJSON(mss) 83 84 err = osutil.WriteFileJSON("_schema_agent.json", mss, 644, "", " ") 85 if err != nil { 86 log.Fatal().Err(err) 87 } 88 fmt.Printf("WROTE [%v]\n", "_schema_agent.json") 89 90 swag2 := openapi3.Spec{ 91 Components: &oas3.Components{ 92 Schemas: map[string]*oas3.SchemaRef{ 93 "Agent": { 94 Value: &oas3.Schema{ 95 Properties: mss, 96 }, 97 }, 98 }, 99 }, 100 } 101 fmtutil.PrintJSON(swag2) 102 swagFile := "_openapi-spec_agents_models.json" 103 err = osutil.WriteFileJSON(swagFile, swag2, 0644, "", " ") 104 if err != nil { 105 log.Fatal().Err(err) 106 } 107 fmt.Printf("WROTE [%v]\n", swagFile) 108 109 fmt.Println("DONE") 110 }