Skip to content

Commit a209e61

Browse files
author
Jamie Tanna
committed
docs: add an example for generate: models
1 parent ab8b9dd commit a209e61

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

examples/only-models/api.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Generate models
5+
paths:
6+
/client:
7+
get:
8+
operationId: getClient
9+
responses:
10+
200:
11+
content:
12+
application/json:
13+
schema:
14+
# NOTE that Client is generated here, because it's within #/components/schemas
15+
$ref: "#/components/schemas/Client"
16+
put:
17+
operationId: updateClient
18+
responses:
19+
400:
20+
content:
21+
application/json:
22+
# NOTE that this anonymous object is /not/ generated because it's an anonymous, but would be generated if using `generate: client`
23+
# See https://github.com/deepmap/oapi-codegen/issues/1512
24+
schema:
25+
type: object
26+
properties:
27+
code:
28+
type: string
29+
required:
30+
- code
31+
components:
32+
schemas:
33+
Client:
34+
type: object
35+
required:
36+
- name
37+
properties:
38+
name:
39+
type: string
40+
# NOTE that this is not generated by default because it's not referenced. If you want it, you need to use the following YAML configuration:
41+
#
42+
# output-options:
43+
# skip-prune: true
44+
Unreferenced:
45+
type: object
46+
required:
47+
- id
48+
properties:
49+
id:
50+
type: integer

examples/only-models/cfg.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package: onlymodels
2+
output: only-models.gen.go
3+
generate:
4+
models: true
5+
output-options:
6+
# NOTE that this is only required for the `Unreferenced` type
7+
skip-prune: true

examples/only-models/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package onlymodels
2+
3+
//go:generate go run github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -config cfg.yaml api.yaml

examples/only-models/only-models.gen.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)