Skip to content

Commit 10674f0

Browse files
feat: add indent
1 parent 20a2130 commit 10674f0

15 files changed

+661
-641
lines changed

cmd/protoc-gen-oas/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func run() error {
2020
title := set.String("title", "", "Title")
2121
description := set.String("description", "", "Description")
2222
version := set.String("version", "", "Version")
23+
indent := set.Int("indent", 2, "Indent")
2324

2425
if err := set.Parse(os.Args[1:]); err != nil {
2526
return errors.Wrap(err, "parse args")
@@ -38,6 +39,7 @@ func run() error {
3839
gen.WithSpecInfoTitle(*title),
3940
gen.WithSpecInfoDescription(*description),
4041
gen.WithSpecInfoVersion(*version),
42+
gen.WithIndent(*indent),
4143
)
4244
if err != nil {
4345
return err

example/openapi.yaml

+186-186
Original file line numberDiff line numberDiff line change
@@ -1,194 +1,194 @@
11
openapi: 3.1.0
22
info:
3-
title: Generated OpenAPI specification from proto file
4-
version: v1.0.0
3+
title: Generated OpenAPI specification from proto file
4+
version: v1.0.0
55
paths:
6-
/api/v1/items:
7-
get:
8-
operationId: getItems
9-
parameters:
10-
- name: limit
11-
in: query
12-
required: true
13-
schema:
14-
type: integer
15-
format: int32
16-
- name: offset
17-
in: query
18-
required: true
19-
schema:
20-
type: integer
21-
format: int32
22-
responses:
23-
"200":
24-
description: service.v1.Service.GetItems response
25-
content:
26-
application/json:
27-
schema:
28-
$ref: '#/components/schemas/GetItemsResponse'
29-
post:
30-
operationId: createItem
31-
requestBody:
32-
content:
33-
application/json:
34-
schema:
35-
$ref: '#/components/schemas/CreateItemRequest'
36-
required: true
37-
responses:
38-
"200":
39-
description: service.v1.Service.CreateItem response
40-
content:
41-
application/json:
42-
schema:
43-
$ref: '#/components/schemas/Item'
44-
/api/v1/items/{id}:
45-
get:
46-
operationId: getItem
47-
parameters:
48-
- name: id
49-
in: path
50-
required: true
51-
schema:
52-
type: string
53-
responses:
54-
"200":
55-
description: service.v1.Service.GetItem response
56-
content:
57-
application/json:
58-
schema:
59-
$ref: '#/components/schemas/Item'
60-
put:
61-
operationId: updateItem
62-
parameters:
63-
- name: id
64-
in: path
65-
required: true
66-
schema:
67-
type: string
68-
requestBody:
69-
content:
70-
application/json:
71-
schema:
72-
type: object
73-
properties:
74-
name:
75-
type: string
76-
type:
77-
$ref: '#/components/schemas/ItemType'
78-
required:
79-
- name
80-
- type
81-
required: true
82-
responses:
83-
"200":
84-
description: service.v1.Service.UpdateItem response
85-
content:
86-
application/json:
87-
schema:
88-
$ref: '#/components/schemas/Item'
89-
delete:
90-
operationId: deleteItem
91-
parameters:
92-
- name: id
93-
in: path
94-
required: true
95-
schema:
96-
type: string
97-
responses:
98-
"200":
99-
description: service.v1.Service.DeleteItem response
100-
content:
101-
application/json:
102-
schema:
103-
$ref: '#/components/schemas/Empty'
104-
patch:
105-
operationId: patchItem
106-
parameters:
107-
- name: id
108-
in: path
109-
required: true
110-
schema:
111-
type: string
112-
requestBody:
113-
content:
114-
application/json:
115-
schema:
116-
type: object
117-
properties:
118-
name:
119-
type: string
120-
type:
121-
$ref: '#/components/schemas/ItemType'
122-
required: true
123-
responses:
124-
"200":
125-
description: service.v1.Service.PatchItem response
126-
content:
127-
application/json:
128-
schema:
129-
$ref: '#/components/schemas/Item'
130-
components:
131-
schemas:
132-
CreateItemRequest:
133-
type: object
134-
properties:
6+
/api/v1/items:
7+
get:
8+
operationId: getItems
9+
parameters:
10+
- name: limit
11+
in: query
12+
required: true
13+
schema:
14+
type: integer
15+
format: int32
16+
- name: offset
17+
in: query
18+
required: true
19+
schema:
20+
type: integer
21+
format: int32
22+
responses:
23+
"200":
24+
description: service.v1.Service.GetItems response
25+
content:
26+
application/json:
27+
schema:
28+
$ref: '#/components/schemas/GetItemsResponse'
29+
post:
30+
operationId: createItem
31+
requestBody:
32+
content:
33+
application/json:
34+
schema:
35+
$ref: '#/components/schemas/CreateItemRequest'
36+
required: true
37+
responses:
38+
"200":
39+
description: service.v1.Service.CreateItem response
40+
content:
41+
application/json:
42+
schema:
43+
$ref: '#/components/schemas/Item'
44+
/api/v1/items/{id}:
45+
get:
46+
operationId: getItem
47+
parameters:
48+
- name: id
49+
in: path
50+
required: true
51+
schema:
52+
type: string
53+
responses:
54+
"200":
55+
description: service.v1.Service.GetItem response
56+
content:
57+
application/json:
58+
schema:
59+
$ref: '#/components/schemas/Item'
60+
put:
61+
operationId: updateItem
62+
parameters:
63+
- name: id
64+
in: path
65+
required: true
66+
schema:
67+
type: string
68+
requestBody:
69+
content:
70+
application/json:
71+
schema:
72+
type: object
73+
properties:
13574
name:
136-
type: string
137-
required:
138-
- name
139-
Empty:
140-
type: object
141-
GetItemsResponse:
142-
type: object
143-
properties:
144-
items:
145-
type: array
146-
items:
147-
$ref: '#/components/schemas/Item'
148-
totalCount:
149-
type: integer
150-
format: int32
151-
nestedItem:
152-
$ref: '#/components/schemas/GetItemsResponse.NestedItem'
153-
required:
154-
- items
155-
- totalCount
156-
GetItemsResponse.NestedItem:
157-
type: object
158-
properties:
159-
id:
160-
type: string
75+
type: string
16176
type:
162-
$ref: '#/components/schemas/ItemType'
163-
name:
164-
type: string
165-
createdAt:
166-
type: string
167-
format: date-time
168-
required:
169-
- id
170-
- type
77+
$ref: '#/components/schemas/ItemType'
78+
required:
17179
- name
172-
- createdAt
173-
Item:
174-
type: object
175-
properties:
176-
id:
177-
type: string
178-
type:
179-
$ref: '#/components/schemas/ItemType'
180-
name:
181-
type: string
182-
createdAt:
183-
type: string
184-
format: date-time
185-
required:
186-
- id
18780
- type
188-
- name
189-
- createdAt
190-
ItemType:
81+
required: true
82+
responses:
83+
"200":
84+
description: service.v1.Service.UpdateItem response
85+
content:
86+
application/json:
87+
schema:
88+
$ref: '#/components/schemas/Item'
89+
delete:
90+
operationId: deleteItem
91+
parameters:
92+
- name: id
93+
in: path
94+
required: true
95+
schema:
96+
type: string
97+
responses:
98+
"200":
99+
description: service.v1.Service.DeleteItem response
100+
content:
101+
application/json:
102+
schema:
103+
$ref: '#/components/schemas/Empty'
104+
patch:
105+
operationId: patchItem
106+
parameters:
107+
- name: id
108+
in: path
109+
required: true
110+
schema:
191111
type: string
192-
enum:
193-
- ITEM_TYPE_UNSPECIFIED
194-
- ITEM_TYPE_BASIC
112+
requestBody:
113+
content:
114+
application/json:
115+
schema:
116+
type: object
117+
properties:
118+
name:
119+
type: string
120+
type:
121+
$ref: '#/components/schemas/ItemType'
122+
required: true
123+
responses:
124+
"200":
125+
description: service.v1.Service.PatchItem response
126+
content:
127+
application/json:
128+
schema:
129+
$ref: '#/components/schemas/Item'
130+
components:
131+
schemas:
132+
CreateItemRequest:
133+
type: object
134+
properties:
135+
name:
136+
type: string
137+
required:
138+
- name
139+
Empty:
140+
type: object
141+
GetItemsResponse:
142+
type: object
143+
properties:
144+
items:
145+
type: array
146+
items:
147+
$ref: '#/components/schemas/Item'
148+
totalCount:
149+
type: integer
150+
format: int32
151+
nestedItem:
152+
$ref: '#/components/schemas/GetItemsResponse.NestedItem'
153+
required:
154+
- items
155+
- totalCount
156+
GetItemsResponse.NestedItem:
157+
type: object
158+
properties:
159+
id:
160+
type: string
161+
type:
162+
$ref: '#/components/schemas/ItemType'
163+
name:
164+
type: string
165+
createdAt:
166+
type: string
167+
format: date-time
168+
required:
169+
- id
170+
- type
171+
- name
172+
- createdAt
173+
Item:
174+
type: object
175+
properties:
176+
id:
177+
type: string
178+
type:
179+
$ref: '#/components/schemas/ItemType'
180+
name:
181+
type: string
182+
createdAt:
183+
type: string
184+
format: date-time
185+
required:
186+
- id
187+
- type
188+
- name
189+
- createdAt
190+
ItemType:
191+
type: string
192+
enum:
193+
- ITEM_TYPE_UNSPECIFIED
194+
- ITEM_TYPE_BASIC

0 commit comments

Comments
 (0)