BuildTypes transforms all component schemas into go types
(schema *openapi3.T)
| 19 | |
| 20 | // BuildTypes transforms all component schemas into go types |
| 21 | func (g *Generator) BuildTypes(schema *openapi3.T) error { |
| 22 | schemas := schema.Components.Schemas |
| 23 | |
| 24 | // sort by key |
| 25 | keys := make([]string, 0, len(schemas)) |
| 26 | for k := range schemas { |
| 27 | keys = append(keys, k) |
| 28 | } |
| 29 | sort.Stable(sort.StringSlice(keys)) |
| 30 | |
| 31 | for _, name := range keys { |
| 32 | schemaType := schemas[name] |
| 33 | // create new type |
| 34 | name = goNameHelper(name) |
| 35 | |
| 36 | // skip jsonapi error type |
| 37 | if name == "Errors" { |
| 38 | continue |
| 39 | } |
| 40 | |
| 41 | t, ok := g.newType(name) |
| 42 | if !ok { // type already exists |
| 43 | continue |
| 44 | } |
| 45 | |
| 46 | err := g.buildType(name, t, schemaType, make(map[string]string), true) |
| 47 | if err != nil { |
| 48 | return err |
| 49 | } |
| 50 | // document type |
| 51 | g.addGoDoc(name, schemaType.Value.Description) |
| 52 | g.goSource.Add(t) |
| 53 | } |
| 54 | |
| 55 | return nil |
| 56 | } |
| 57 | |
| 58 | func (g *Generator) buildType(prefix string, stmt *jen.Statement, schema *openapi3.SchemaRef, tags map[string]string, ptr bool) error { // nolint: gocyclo |
| 59 | name := nameFromSchemaRef(schema) |
nothing calls this directly
no test coverage detected