Skip to content

Commit ca94577

Browse files
author
Tit Petric
committed
docs: mdox reformat
1 parent 3e20c55 commit ca94577

File tree

2 files changed

+42
-32
lines changed

2 files changed

+42
-32
lines changed

docs/Taskfile.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
# Running this taskfile ensures that markdowns are
2+
# consistently formatted according to mdox rules.
13
---
24
version: "3"
35

4-
# Running this taskfile ensures that markdowns are
5-
# consistently formatted according to mdox rules.
6+
vars:
7+
root:
8+
sh: git rev-parse --show-toplevel
69

710
tasks:
8-
default:
11+
fmt:
912
desc: "Run mdox to format markdowns"
1013
cmds:
1114
- mdox fmt --no-soft-wraps $(find -name '*.md')
15+
16+
deps:
17+
desc:
18+
cmds:
19+
- go install github.com/bwplotka/mdox@latest

docs/dev/apidef-oas.md

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ Make sure `json` and `bson` tags are added to the fields.
1010

1111
If an `enabled` flag is specified in the OAS contract, make sure a corresponding `disabled` or `enabled` flag is added in the classic API definition.
1212

13-
Also make sure that `disabled`/`enabled` flag toggles the feature on or off.
13+
Also make sure that `disabled`/`enabled` flag toggles the feature on or off.
1414

1515
### Why `disabled` or `enabled` in classic API definition?
1616

17-
Historically, almost every feature/middleware in Tyk is considered enabled by default when value for feature controls are non zero values.
18-
It is disabled when the feature controls are having zero values.
19-
For this reason, whenever an existing feature is migrated to OAS, and OAS has an `enabled` flag then a `disabled` flag is added to give explicit control to turn off the feature.
17+
Historically, almost every feature/middleware in Tyk is considered enabled by default when value for feature controls are non zero values. It is disabled when the feature controls are having zero values. For this reason, whenever an existing feature is migrated to OAS, and OAS has an `enabled` flag then a `disabled` flag is added to give explicit control to turn off the feature.
2018

2119
Please also make sure that the disabled flags are set to true in `APIDefinition.SetDisabledFlags()`, so that it is not enabled in OAS by default.
2220

@@ -28,27 +26,29 @@ Ensure OAS fields follow `camelCase` notation for `json` and `bson` tags.
2826

2927
For fields that are required:
3028

31-
1. Do not use `omitempty` in struct tags.
29+
1. Do not use `omitempty` in struct tags.
3230

33-
2. Do not use pointer types for required fields.
31+
2. Do not use pointer types for required fields.
3432

35-
3. Add a comment `// required` towards the end of a required field so that automation generates docs accordingly.
33+
3. Add a comment `// required` towards the end of a required field so that automation generates docs accordingly.
3634

37-
4. As a convention, we also try to add the corresponding classic API definition fields in godoc in the following format
38-
```
39-
// Tyk classic API definition: `!use_keyless`.
40-
```
41-
This might not be perfect at this moment, but we aim to keep this link so that customers find it easier to follow the docs.
35+
4. As a convention, we also try to add the corresponding classic API definition fields in godoc in the following format
36+
37+
```
38+
// Tyk classic API definition: `!use_keyless`.
39+
```
40+
41+
This might not be perfect at this moment, but we aim to keep this link so that customers find it easier to follow the docs.
4242

4343
## Handle Optional Fields
4444

4545
For optional fields:
4646

47-
1. Add the `omitempty` tag
47+
1. Add the `omitempty` tag
48+
49+
2. Use pointer types for structs.
4850

49-
2. Use pointer types for structs.
50-
51-
3. Make sure that `omitempty` tag is added for slice fields that are optional.
51+
3. Make sure that `omitempty` tag is added for slice fields that are optional.
5252

5353
## Add Go Doc Comments
5454

@@ -58,29 +58,31 @@ Add comments in Go doc format for each field to enable automated documentation g
5858

5959
Every OAS struct should follow the convention of having `Fill(apidef.APIDefinition)` and `ExtractTo(*apidef.APIDefinition)` methods:
6060

61-
`Fill` populates the struct from a classic API definition.
61+
`Fill` populates the struct from a classic API definition.
6262

63-
`ExtractTo` extracts the contents of an OAS API definition into a classic API definition.
63+
`ExtractTo` extracts the contents of an OAS API definition into a classic API definition.
6464

6565
## Implement Fill Method Pattern
6666

6767
Each `Fill` method should follow this pattern:
6868

6969
```go
7070
if u.RateLimit == nil {
71-
u.RateLimit = &RateLimit{}
71+
u.RateLimit = &RateLimit{}
7272
}
7373

7474
u.RateLimit.Fill(api)
7575
if ShouldOmit(u.RateLimit) {
76-
u.RateLimit = nil
76+
u.RateLimit = nil
7777
}
7878
```
7979

8080
This ensures the field is reset to empty when not configured in the classic API definition.
8181

8282
### Working with `VersionData`
83+
8384
A `Main` version will be provided that can be used for `Fill`.
85+
8486
```go
8587
api.VersionData.Versions[Main]
8688
```
@@ -91,17 +93,19 @@ Similarly, follow this pattern with `ExtractTo`:
9193

9294
```go
9395
if u.RateLimit == nil {
94-
u.RateLimit = &RateLimit{}
95-
defer func() {
96-
u.RateLimit = nil
97-
}()
96+
u.RateLimit = &RateLimit{}
97+
defer func() {
98+
u.RateLimit = nil
99+
}()
98100
}
99101

100102
u.RateLimit.ExtractTo(api)
101103
```
102104

103105
### Working with `VersionData`
106+
104107
There are 2 helper functions for `ExtractTo` that will help to handle `VersionData`. You can use them like this:
108+
105109
```go
106110
func (g *GlobalRequestSizeLimit) ExtractTo(api *apidef.APIDefinition) {
107111
mainVersion := requireMainVersion(api)
@@ -115,16 +119,14 @@ func (g *GlobalRequestSizeLimit) ExtractTo(api *apidef.APIDefinition) {
115119

116120
## Write Tests
117121

118-
Write tests for conversion functions. Refer to the example:
119-
https://github.com/TykTechnologies/tyk/pull/5979/files#diff-222cc254c0c6c09fa0cf50087860b837a0873e2aef3c84ec7d80b1014c149057R97
122+
Write tests for conversion functions. Refer to the example: https://github.com/TykTechnologies/tyk/pull/5979/files#diff-222cc254c0c6c09fa0cf50087860b837a0873e2aef3c84ec7d80b1014c149057R97
120123

121124
## Update TestOAS_ExtractTo_ResetAPIDefinition
122125

123126
Maintain and update the list of fields that are not OAS compatible in the `TestOAS_ExtractTo_ResetAPIDefinition` test.
124127

125128
## Update JSON Schema
126129

127-
Update the JSON schema for the `x-tyk-api-gateway` struct in:
128-
https://github.com/TykTechnologies/tyk/blob/master/apidef/oas/schema/x-tyk-api-gateway.json
130+
Update the JSON schema for the `x-tyk-api-gateway` struct in: https://github.com/TykTechnologies/tyk/blob/master/apidef/oas/schema/x-tyk-api-gateway.json
129131

130-
Ensure this schema is updated whenever the OAS API definition is modified.
132+
Ensure this schema is updated whenever the OAS API definition is modified.

0 commit comments

Comments
 (0)