|
2 | 2 |
|
3 | 3 | package generatorexec |
4 | 4 |
|
| 5 | +import ( |
| 6 | + json "encoding/json" |
| 7 | + fmt "fmt" |
| 8 | + strconv "strconv" |
| 9 | +) |
| 10 | + |
| 11 | +type BadgeType uint |
| 12 | + |
| 13 | +const ( |
| 14 | + BadgeTypeNpm BadgeType = iota + 1 |
| 15 | + BadgeTypeMaven |
| 16 | + BadgeTypePypi |
| 17 | + BadgeTypeGo |
| 18 | +) |
| 19 | + |
| 20 | +func (b BadgeType) String() string { |
| 21 | + switch b { |
| 22 | + default: |
| 23 | + return strconv.Itoa(int(b)) |
| 24 | + case BadgeTypeNpm: |
| 25 | + return "NPM" |
| 26 | + case BadgeTypeMaven: |
| 27 | + return "MAVEN" |
| 28 | + case BadgeTypePypi: |
| 29 | + return "PYPI" |
| 30 | + case BadgeTypeGo: |
| 31 | + return "GO" |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +func (b BadgeType) MarshalJSON() ([]byte, error) { |
| 36 | + return []byte(fmt.Sprintf("%q", b.String())), nil |
| 37 | +} |
| 38 | + |
| 39 | +func (b *BadgeType) UnmarshalJSON(data []byte) error { |
| 40 | + var raw string |
| 41 | + if err := json.Unmarshal(data, &raw); err != nil { |
| 42 | + return err |
| 43 | + } |
| 44 | + switch raw { |
| 45 | + case "NPM": |
| 46 | + value := BadgeTypeNpm |
| 47 | + *b = value |
| 48 | + case "MAVEN": |
| 49 | + value := BadgeTypeMaven |
| 50 | + *b = value |
| 51 | + case "PYPI": |
| 52 | + value := BadgeTypePypi |
| 53 | + *b = value |
| 54 | + case "GO": |
| 55 | + value := BadgeTypeGo |
| 56 | + *b = value |
| 57 | + } |
| 58 | + return nil |
| 59 | +} |
| 60 | + |
5 | 61 | // The standard sections included in every generated README.md |
6 | | -type Readme struct { |
| 62 | +// |
| 63 | +// # {{title}} |
| 64 | +// {{badge}} [Fern Badge] |
| 65 | +// |
| 66 | +// {{summary}} |
| 67 | +// |
| 68 | +// ## API Documentation |
| 69 | +// |
| 70 | +// API Reference Documentation is available {{here}}. |
| 71 | +// |
| 72 | +// ## Installation |
| 73 | +// |
| 74 | +// {{installation}} |
| 75 | +// |
| 76 | +// ## Usage |
| 77 | +// |
| 78 | +// {{usage}} |
| 79 | +// |
| 80 | +// ## Async Client |
| 81 | +// |
| 82 | +// {{asyncUsage}} |
| 83 | +// |
| 84 | +// ## Environments |
| 85 | +// |
| 86 | +// {{environments}} |
| 87 | +// |
| 88 | +// ## Custom URL |
| 89 | +// |
| 90 | +// {{customUrl}} |
| 91 | +// |
| 92 | +// ## Handling Errors |
| 93 | +// |
| 94 | +// {{errors}} |
| 95 | +// |
| 96 | +// ## Advanced: Setting Timeouts |
| 97 | +// |
| 98 | +// {{timeouts}} |
| 99 | +// |
| 100 | +// ## Advanced: Request Options |
| 101 | +// |
| 102 | +// {{requestOptions}}} |
| 103 | +// |
| 104 | +// ## Beta Status |
| 105 | +// |
| 106 | +// Some info about beta status. |
| 107 | +// |
| 108 | +// ## Contributing |
| 109 | +// |
| 110 | +// Some info about contributing. |
| 111 | +type GenerateReadmeRequest struct { |
7 | 112 | // The title (e.g. Acme Python Library ...) |
8 | 113 | Title string `json:"title"` |
9 | 114 | // Badges rendered alongside the standard Fern badge |
10 | | - Badges string `json:"badges"` |
| 115 | + Badge *BadgeType `json:"badge,omitempty"` |
11 | 116 | // The summary included below the badges (e.g. The Acme Python library provides ...) |
12 | 117 | Summary string `json:"summary"` |
13 | | - // General requirements to use the SDK |
14 | | - Requirements *string `json:"requirements,omitempty"` |
| 118 | + // Each requirement is rendered as a bulleted list |
| 119 | + Requirements []string `json:"requirements,omitempty"` |
15 | 120 | // The installation steps |
16 | | - Installation string `json:"installation"` |
17 | | - // Describes how to instantiate the client (i.e. a code snippet) |
18 | | - Instantiation string `json:"instantiation"` |
19 | | - // Usage guide, extensible with Fern definition example annotations |
| 121 | + Installation *string `json:"installation,omitempty"` |
| 122 | + // Section describing how to instantiate the client (i.e. a code snippet) |
20 | 123 | Usage string `json:"usage"` |
21 | | - // The status of the SDK (e.g. beta) |
22 | | - Status string `json:"status"` |
23 | | - // The contributing guide; if not specified uses the default contributing notes |
24 | | - Contributing *string `json:"contributing,omitempty"` |
| 124 | + // Section describing how to instantiate an async client |
| 125 | + AsyncUsage *string `json:"asyncUsage,omitempty"` |
| 126 | + // Section describing how to set timeouts |
| 127 | + Timeouts *string `json:"timeouts,omitempty"` |
| 128 | + // If multiple environments, a section for how to specify multiple environments |
| 129 | + Environments *string `json:"environments,omitempty"` |
| 130 | + // Section describing how to set a custom url |
| 131 | + CustomUrl *string `json:"customUrl,omitempty"` |
| 132 | + // Section describing how to set request options |
| 133 | + RequestOptions *string `json:"requestOptions,omitempty"` |
25 | 134 | } |
0 commit comments