Skip to content

Commit 770b265

Browse files
author
Phil Sturgeon
committed
Aiming at 30 minutes, adding annotationbashing
1 parent 954cdfa commit 770b265

File tree

14 files changed

+166
-7
lines changed

14 files changed

+166
-7
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

content/api-descriptions-as-production-code/layout.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,25 @@
3030
<div class="slides">{{{slides}}}</div>
3131
<div id="crashy-footer" class="footer">
3232
<span class="element">stoplight.io</span>
33+
<span class="element">phil.tech/speaking</span>
3334
<span class="element">@philsturgeon</span>
34-
<span class="element">#ApiCityConf</span>
3535
</div>
3636
</div>
3737

3838
<script src="{{{base}}}/js/reveal.js"></script>
3939

4040
<style>
41+
.slides {
42+
height:100%;
43+
width:100%;
44+
}
45+
46+
.caption {
47+
bottom:0px;
48+
right:0px;
49+
position:absolute;
50+
}
51+
4152
.footer {
4253
position: absolute;
4354
display: table;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
reveal-md source.md --template=layout.html -w

content/api-descriptions-as-production-code/source.md

Lines changed: 153 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ revealOptions:
2020

2121
---
2222

23-
🌍 offset.earth 🌏
23+
<!-- .slide: data-background="img/offset-earth.png" -->
2424

2525
---
2626

@@ -35,6 +35,7 @@ revealOptions:
3535
1. Why are there no editors? <!-- .element: class="fragment" -->
3636
1. How/when do we create documentation? <!-- .element: class="fragment" -->
3737
1. How/when do we create mocks? <!-- .element: class="fragment" -->
38+
1. How can we enforce style guides for docs? <!-- .element: class="fragment" -->
3839
1. How do we keep code and docs in sync? <!-- .element: class="fragment" -->
3940

4041
---
@@ -43,13 +44,11 @@ revealOptions:
4344

4445
---
4546

46-
<img src="img/logo.dark.png" style="border:0; background:transparent;box-shadow:0">
47+
<!-- .slide: data-background="img/workflow2.jpeg" data-background-size="contain" data-background-color="#fff" -->
4748

4849
---
4950

50-
**Design First or Code First?**
51-
52-
Design First <!-- .element: class="fragment" -->
51+
<img src="img/logo.dark.png" style="border:0; background:transparent;box-shadow:0">
5352

5453
---
5554

@@ -61,6 +60,85 @@ https://openapi.tools <!-- .element: class="fragment" -->
6160

6261
---
6362

63+
<!-- .slide: data-background="img/tools.png" data-background-size="contain" -->
64+
65+
---
66+
67+
**Design First or Code First?**
68+
69+
---
70+
71+
```java
72+
class UserController {
73+
@OpenApi(
74+
path = "/users",
75+
method = HttpMethod.POST,
76+
// ...
77+
)
78+
public static void createUser(Context ctx) {
79+
// ...
80+
}
81+
}
82+
```
83+
84+
---
85+
86+
```php
87+
/**
88+
* @OA\Get(path="/2.0/users/{username}",
89+
* operationId="getUserByName",
90+
* @OA\Parameter(name="username",
91+
* in="path",
92+
* required=true,
93+
* description=Explaining all about the username parameter
94+
* @OA\Schema(type="string")
95+
* ),
96+
* @OA\Response(response="200",
97+
* description="The User",
98+
* @OA\JsonContent(ref="#/components/schemas/user"),
99+
* @OA\Link(link="userRepositories", ref="#/components/links/UserRepositories")
100+
* )
101+
* )
102+
*/
103+
public function getUserByName($username, $newparam)
104+
{
105+
}
106+
```
107+
108+
---
109+
110+
> Code comments are just facts waiting to become lies.
111+
112+
_<small>Vinai Kopp, A talk at #MM18IT</small>_
113+
114+
---
115+
116+
<!-- .slide: data-background="img/code-comments.jpg" data-background-size="contain" -->
117+
118+
---
119+
120+
<!-- .slide: data-background="img/wf-1.png" data-background-size="contain" data-background-color="#eee" -->
121+
122+
---
123+
124+
<!-- .slide: data-background="img/wf-2.png" data-background-size="contain" data-background-color="#eee" -->
125+
126+
---
127+
128+
<!-- .slide: data-background="img/wf-3.png" data-background-size="contain" data-background-color="#eee" -->
129+
130+
---
131+
132+
<!-- .slide: data-background="img/lifecycle.png" data-background-size="contain" data-background-color="#eee" -->
133+
134+
---
135+
136+
> While OpenAPI is great for describing APIs, ... **it's definitely not a great experience to write OpenAPI documents from scratch**.
137+
138+
_<small>Sebastien Armand, "Making OpenAPI Bearable With Your Own DSL"</small>_
139+
140+
---
141+
64142
**Why are there no editors?**
65143

66144
https://stoplight.io/studio <!-- .element: class="fragment" -->
@@ -69,18 +147,28 @@ https://stoplight.io/studio <!-- .element: class="fragment" -->
69147

70148
<!-- .slide: data-background="img/studio.png" data-background-size="contain" data-background-color="#000" -->
71149

150+
<!-- TODO Add file system image -->
151+
72152
---
73153

74154
<!-- .slide: data-background="img/studio-adv.png" data-background-size="contain" data-background-color="#000" -->
75155

76156
---
77157

158+
<!-- .slide: data-background="img/studio-md.png" data-background-size="contain" data-background-color="#fff" -->
159+
160+
---
161+
78162
**How/when do we create documentation?**
79163

80164
https://stoplight.io/docs <!-- .element: class="fragment" -->
81165

82166
---
83167

168+
<!-- .slide: data-background="img/docs.png" data-background-size="contain" data-background-color="#fff" -->
169+
170+
---
171+
84172
**How/when do we create mocks?**
85173

86174
Studio has a mock server built right in 🙌 <!-- .element: class="fragment" -->
@@ -209,7 +297,7 @@ config.middleware.use Committee::Middleware::RequestValidation,
209297
210298
- **Ruby:** [committee](https://github.com/interagent/committee)
211299
- **PHP:** [openapi-psr7-validator](https://github.com/lezhnev74/openapi-psr7-validator)
212-
- **NodeJS:** [fastify](https://github.com/fastify/fastify/blob/master/docs/Validation-and-Serialization.md) or [express-ajv-swagger-validation](https://github.com/Zooz/express-ajv-swagger-validation) <small><sup>Name change pending</sup></small>
300+
- **NodeJS:** [fastify](https://github.com/fastify/fastify/blob/master/docs/Validation-and-Serialization.md) or [express-ajv-swagger-validation](https://github.com/Zooz/express-ajv-swagger-validation)
213301
- **Python:** [connexion](https://github.com/zalando/connexion)
214302
- **Mojolicious:** [Mojolicious](https://metacpan.org/pod/Mojolicious::Plugin::OpenAPI)
215303
@@ -253,6 +341,19 @@ Your test suite can use the descriptions to prove the responses work properly
253341

254342
---
255343

344+
```rb
345+
JsonMatchers.schema_root = "reference/example-api/models"
346+
347+
it 'should conform to user schema' do
348+
get "/users/#{subject.id}"
349+
expect(response).to match_json_schema('user')
350+
end
351+
```
352+
353+
<small>https://apisyouwonthate.com/blog/writing-documentation-via-contract-testing</small>
354+
355+
---
356+
256357
## Request Validation at Gateway
257358

258359
Can't find a middleware?
@@ -357,6 +458,52 @@ validate(userSchema, { ...input, email: 123 );
357458
358459
---
359460
461+
**How can we enforce style guides for docs?**
462+
463+
https://stoplight.io/spectral <!-- .element: class="fragment" -->
464+
465+
---
466+
467+
```yaml
468+
rules:
469+
schema-names-pascal-case:
470+
description: Schema names MUST be written in PascalCase
471+
message: '{{property}} is not PascalCase: {{error}}'
472+
recommended: true
473+
type: style
474+
given: '$.components.schemas.*~'
475+
then:
476+
function: pattern
477+
functionOptions:
478+
match: '^[A-Z][a-zA-Z0-9]*$'
479+
```
480+
481+
---
482+
483+
<!-- .slide: data-background="img/studio-spectral.png" data-background-size="contain" -->
484+
485+
---
486+
487+
**Reference Company-Wide Style Guides**
488+
489+
```yaml
490+
extends:
491+
- "https://api.acme.com/style-guide.yml"
492+
```
493+
494+
---
495+
496+
- Editor (Studio, VS Code coming...)
497+
- CLI
498+
- Git Hooks
499+
- Continuous Integration
500+
501+
---
502+
503+
Consistent APIs = ⏰ 💰 🥳
504+
505+
---
506+
360507
<span style="font-size: 60pt">apisyouwonthate.com</span>
361508
362509
Join our [Slack](http://slack.apisyouwonthate.com/)

0 commit comments

Comments
 (0)