api_recipes 3.0.0.beta4 → 3.0.0.beta6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +340 -107
  3. data/UPGRADING.md +197 -49
  4. data/lib/api_recipes/cli/calls.rb +27 -0
  5. data/lib/api_recipes/cli/convert/migration.rb +201 -6
  6. data/lib/api_recipes/cli/convert.rb +130 -23
  7. data/lib/api_recipes/cli/description.rb +65 -0
  8. data/lib/api_recipes/cli/import/server.rb +20 -9
  9. data/lib/api_recipes/cli/import/writer.rb +16 -4
  10. data/lib/api_recipes/cli/import.rb +23 -9
  11. data/lib/api_recipes/cli/recipes/summary.rb +7 -5
  12. data/lib/api_recipes/cli/recipes.rb +5 -2
  13. data/lib/api_recipes/cli/routes.rb +62 -7
  14. data/lib/api_recipes/cli/tags.rb +19 -0
  15. data/lib/api_recipes/cli/upgrade/fix.rb +206 -0
  16. data/lib/api_recipes/cli/upgrade/screen.rb +165 -0
  17. data/lib/api_recipes/cli/upgrade/tree_rules.rb +290 -0
  18. data/lib/api_recipes/cli/upgrade.rb +385 -63
  19. data/lib/api_recipes/cli.rb +84 -17
  20. data/lib/api_recipes/configuration.rb +17 -108
  21. data/lib/api_recipes/errors.rb +20 -3
  22. data/lib/api_recipes/internals/compiler.rb +77 -70
  23. data/lib/api_recipes/internals/context.rb +7 -2
  24. data/lib/api_recipes/internals/declaration.rb +17 -15
  25. data/lib/api_recipes/internals/definition.rb +15 -2
  26. data/lib/api_recipes/internals/level.rb +6 -1
  27. data/lib/api_recipes/internals/origins.rb +70 -0
  28. data/lib/api_recipes/internals/path_template.rb +23 -6
  29. data/lib/api_recipes/internals/recipe.rb +31 -5
  30. data/lib/api_recipes/internals/recipe_lock.rb +12 -9
  31. data/lib/api_recipes/internals/registry.rb +21 -10
  32. data/lib/api_recipes/internals/request.rb +2 -2
  33. data/lib/api_recipes/internals/template.rb +32 -2
  34. data/lib/api_recipes/response.rb +125 -6
  35. data/lib/api_recipes/version.rb +1 -1
  36. data/lib/api_recipes.rb +1 -0
  37. metadata +8 -1
data/UPGRADING.md CHANGED
@@ -1,12 +1,11 @@
1
1
  # Upgrading from 2.x to 3.0
2
2
 
3
- Version 3.0 keeps the way you use the gem: the YAML files, `ApiRecipes.configure`,
4
- `api :name` in a class and the chain
5
- `ApiRecipes.github.users.show('octocat').run` work as before. A YAML file that
6
- is valid for 2.x needs no change, apart from what part 2 describes: options and
7
- values that 2.x accepted without checking them, a placeholder in `base_url` and a
8
- `{word}` in a header value or in a path. What changes is how the gem behaves around them: it
9
- checks more, it refuses more, and a few results are different.
3
+ Version 3.0 keeps the way you use the gem: `ApiRecipes.configure`, `api :name`
4
+ in a class and the chain `ApiRecipes.github.users.show('octocat').run` work as
5
+ before. The YAML description of an API becomes a portable recipe, with the same
6
+ options and endpoints: `api_recipes convert` moves every description of a
7
+ project to one, as part 2 describes. What changes is how the gem behaves around
8
+ them: it checks more, it refuses more, and a few results are different.
10
9
 
11
10
  This guide has six parts:
12
11
 
@@ -87,21 +86,52 @@ configuration in place. Four things are worth knowing:
87
86
  - A `base_url` with a path placeholder (`:name` or `*name`) is an error. In 2.x
88
87
  it silently became a required parameter of every root endpoint. For a value
89
88
  that changes, declare a [variable](README.md#variables) and write `{name}`.
90
- - A word in braces, such as `{id}`, in a value of `default_headers` is now a
91
- variable, and one that is not declared is an error. To send that text as it
92
- is, declare a variable whose default is the text and use the variable:
89
+ - A word in braces, such as `{id}`, in a value of `default_headers` or of
90
+ `default_params`, in the `base_url` or in the `path` of an endpoint is now a
91
+ variable, which a request asks a value for. In 2.x it was sent as text.
92
+ `api_recipes convert` keeps it text: it writes `\{id}` in a path and in the
93
+ `base_url`, and for a header or a parameter it declares a variable whose
94
+ default is the text and uses the variable, as in
93
95
  `variables: { template: { default: '{id}' } }` with the header value
94
96
  `'{template}'`. Braces around anything else, such as a JSON value, are sent
95
- as they are.
96
- - A word in braces in the `path` of an endpoint, such as `/items/{id}`, is now a
97
- variable too, and one that is not declared is an error. In 2.x the braces were
98
- sent as text. If you meant a value that changes at every call, write a
99
- placeholder, `/items/:id`. To keep the braces as text, write `\{id}`.
100
- - A file that is missing, empty, not valid YAML or not valid UTF-8 raises
101
- `ApiRecipes::RecipeFileError`, which names the file. Files are read with
102
- `YAML.safe_load`: plain values, symbols and aliases are accepted, and nothing
103
- else. A file called `something.recipe.yml` is refused: it is a portable
104
- recipe, and goes in `recipes_paths`.
97
+ as they are. In a path, if you meant a value that changes at every call,
98
+ write a placeholder, `/items/:id`. In the `base_url` and in a `path`, a
99
+ word in braces with a star, `{*id}`, is a variable too, whose value spans
100
+ several segments: `api_recipes convert` writes `\{*id}`, whether the file
101
+ declares `id` or not.
102
+ - A recipe that is missing, not valid YAML, not valid UTF-8 or not a recipe
103
+ raises `ApiRecipes::RecipeFileError`, which names the file. A recipe is
104
+ plain YAML: anchors, aliases, tags and the merge key are refused.
105
+
106
+ ### An API is described by a portable recipe
107
+
108
+ 2.x loaded the files of `apis_files_paths`: YAML that the gem evaluated with
109
+ ERB. 3.0 loads only portable recipes, files called `NAME.recipe.yml` that
110
+ hold data and no code, and `apis_configs`. Assigning `apis_files_paths` raises
111
+ `ApiRecipes::Error`, and the message names the command to run:
112
+
113
+ $ bundle exec api_recipes convert
114
+
115
+ In the root of the project, with no argument, it moves every API that a file
116
+ describes to a recipe in `config/api_recipes`, one after the other:
117
+
118
+ - what an `<%= ... %>` tag gave becomes a variable of the recipe, and the code
119
+ of the tag moves, as it is written, to `config.values` in the file that
120
+ calls `ApiRecipes.configure`; in the `base_url` and in a `path` it is a
121
+ `{*name}`, which keeps the slashes inside the value as 2.x did, while a
122
+ value that starts or ends with a slash, has two in a row or is empty raises
123
+ `ApiRecipes::InvalidVariable`: set `API_PREFIX=api/v1`, not `/api/v1`;
124
+ - `config.recipes_paths` is added, and `config.apis_files_paths` goes with the
125
+ last description;
126
+ - the old file is deleted, and every change is listed.
127
+
128
+ `api_recipes upgrade`, run without arguments in the root of the project,
129
+ offers the same move on a terminal, one API at a time, and shows the files it
130
+ creates, edits and deletes before it asks. A file
131
+ where ERB decides the structure, with `<% if %>` or a tag that gives a name,
132
+ cannot be converted by the command: it says so, and that description is
133
+ rewritten by hand as a recipe. The whole of what `convert` does is in the
134
+ README, under "From a file of your project".
105
135
 
106
136
  ### A class with its own destination needs its own credential
107
137
 
@@ -114,7 +144,8 @@ own raises:
114
144
  ```
115
145
  api 'github': the credential is bound to "https://api.github.com" but the request goes to
116
146
  "https://ent.example.test". Set the credential at the level that changes the destination,
117
- or set it to nil to send none
147
+ or set it to nil to send none, or name that origin in credential_origins, next to the
148
+ credential in config.values
118
149
  ```
119
150
 
120
151
  Give the credential where the class declares the API:
@@ -126,6 +157,10 @@ class EnterpriseClient
126
157
  end
127
158
  ```
128
159
 
160
+ When the credential of the application is meant for that origin too, name the
161
+ origin with `credential_origins` in `config.values` instead (see
162
+ "Authorization" in the README).
163
+
129
164
  ### Credentials are given when the application starts
130
165
 
131
166
  In 2.x the usual line was `ApiRecipes.github.authorization = '...'`, and code
@@ -253,7 +288,8 @@ ApiRecipes.github.users.show('a/b').url.to_s
253
288
 
254
289
  - **Values you encoded yourself.** Remove the encoding (`ERB::Util.url_encode`,
255
290
  `CGI.escape`): `%2F` would be sent as `%252F`. The gem logs a warning, once for
256
- each endpoint, when a value looks already encoded.
291
+ each endpoint, when a value looks already encoded. A value that the API gave
292
+ already encoded, such as an id it returned in that form, is given as it is.
257
293
  - **A `/` in a value** that was used to cover several segments is now `%2F`. Write
258
294
  the placeholder with a `*` instead: each segment is encoded and the slashes stay.
259
295
  The gem logs a warning, once for each endpoint, when a value contains a `/`.
@@ -319,13 +355,6 @@ the nearest, then in the API, and takes the first value it finds. Look at the
319
355
  endpoints that set one of them and also contain other endpoints: those now
320
356
  find it there. `ok_code` is read only on its endpoint.
321
357
 
322
- ### `apis_configs` after the files
323
-
324
- In 2.x, assigning `apis_configs` after `apis_files_paths` discarded what the
325
- files had loaded. Now every source is used, in the order they were assigned, and a
326
- later source replaces an API with the same name. If you assigned `apis_configs` to
327
- get rid of the files, do not assign the files.
328
-
329
358
  ### Endpoints named like a method
330
359
 
331
360
  An endpoint called `with`, `definition`, `authorization`, `basic_auth` or `variables`
@@ -347,6 +376,33 @@ to the other host. Cookies that a server sets during a chain of redirects are no
347
376
  carried to the next hop any more (they were with http.rb 5). A page that sets a
348
377
  cookie and redirects to itself now ends in the redirect-loop error of http.rb.
349
378
 
379
+ ### `response.data` on an empty body, and on one it cannot read
380
+
381
+ In 2.x `data` passed on whatever http.rb or the JSON parser raised, also for a
382
+ response with no body. Now an empty body gives `nil`, and a body that cannot be
383
+ read (no `Content-Type`, a type that is not JSON, JSON that is not valid) raises
384
+ `ApiRecipes::UnreadableResponse`, whose message never contains the body. The
385
+ body is still on the response:
386
+
387
+ ```ruby
388
+ begin
389
+ response.data
390
+ rescue ApiRecipes::UnreadableResponse => e
391
+ e.response.body.to_s
392
+ end
393
+ ```
394
+
395
+ A `rescue HTTP::Error` or a `rescue JSON::ParserError` written around `data`
396
+ no longer catches it. The same holds around `fill`, and around a `run` whose
397
+ `verify_with` method reads `data`. Timeouts and connection errors are still
398
+ errors of http.rb. Code that reads a key of `data` after a call that can answer
399
+ without a body gets `nil`: check `response.data.nil?` first.
400
+
401
+ `response.parse` is no longer the method of http.rb. It reads the body as
402
+ `data` does, with the type it is given: `nil` for an empty body,
403
+ `ApiRecipes::UnreadableResponse` for one it cannot read. The method of http.rb
404
+ is `response.original_response.parse`.
405
+
350
406
  ### `fill`
351
407
 
352
408
  `fill` calls only public writers. It used to call private ones, and it swallowed
@@ -362,7 +418,8 @@ classes. In 3.0 `Route` and `Settings` are gone, so a top-level `Route` or
362
418
  `Settings` of yours is found again. `Error`, `Internals`, `VERSION` and the new
363
419
  error classes (`ConfigurationError`, `CredentialOriginMismatch`,
364
420
  `InvalidCredential`, `InvalidPathParameter`, `InvalidUrl`, `InvalidVariable`,
365
- `MissingVariable`, `RecipeFileError`, `UnknownEndpoint`) are new, and hide a
421
+ `MissingVariable`, `RecipeFileError`, `UnknownEndpoint`, `UnreadableResponse`)
422
+ are new, and hide a
366
423
  top-level constant of yours with the same name. Inside the classes that include
367
424
  `ApiRecipes`, write it with a leading `::`, for example `::Error`. The
368
425
  [README](README.md#good-to-know) lists all the names.
@@ -379,7 +436,8 @@ top-level constant of yours with the same name. Inside the classes that include
379
436
  `auth: { type: 'query' }`.
380
437
  - `response.request` was removed, because the request holds the credentials that
381
438
  were sent. `response.uri` and the other readers stay, and the http.rb response
382
- is still `response.original_response`.
439
+ is still `response.original_response`. `response.flush` returns the response of
440
+ the gem, not the one of http.rb.
383
441
  - `response.to_s` returns the body, as the http.rb response does. In 2.x it was
384
442
  the default text of the object.
385
443
  - A redirect to a host with non-ASCII characters needs the `addressable` gem;
@@ -427,8 +485,9 @@ You can adopt these when you are ready. The [README](README.md) describes each o
427
485
  `protocol`, `port`, `timeout`, `on_bad_code`, `mime_type`, `verb` and
428
486
  `ok_code`, with values given at any of those levels.
429
487
  - **`default_params`**: query parameters sent with every request, as
430
- `default_headers` does for headers. Both can be written on an endpoint, for
431
- that endpoint and the ones below it.
488
+ `default_headers` does for headers. Both can be written on an endpoint: a
489
+ request looks for them on its endpoint, then on each endpoint that contains
490
+ it, then on the API.
432
491
  - **`resource`**: `resource: true` on an endpoint adds `show`, `create`,
433
492
  `update`, `replace` and `delete` under it.
434
493
  - **`auth`**: says where the credential goes: the `Authorization` header, a header
@@ -452,7 +511,8 @@ You can adopt these when you are ready. The [README](README.md) describes each o
452
511
 
453
512
  - Path parameters are encoded, and `nil`, empty, `.` and `..` are refused.
454
513
  - Variables are checked where they end up: host, path or header.
455
- - A credential is sent only to the origin it was set for, and a value with a
514
+ - A credential is sent only to the origin it was set for, or to one that the
515
+ application names for it with `credential_origins`, and a value with a
456
516
  control character is refused.
457
517
  - Redirects to another origin drop the credentials and cookies.
458
518
  - Logs, error messages of the gem and `inspect` never show a credential, a
@@ -460,7 +520,8 @@ You can adopt these when you are ready. The [README](README.md) describes each o
460
520
  `definition` hide the values of `default_headers`.
461
521
  - An API, an endpoint, a response and a definition refuse `Marshal.dump` and
462
522
  `YAML.dump`; the first three refuse JSON too.
463
- - Configuration files are read with `YAML.safe_load`.
523
+ - A recipe is read as plain YAML, without anchors, aliases or tags, and is
524
+ never evaluated with ERB.
464
525
 
465
526
  What stays with your application:
466
527
 
@@ -469,14 +530,17 @@ What stays with your application:
469
530
  host). Check it against a list of hosts you know.
470
531
  - `response.original_response` is the raw http.rb response and gives access to the
471
532
  request that was sent, headers included. Do not log or serialize it.
472
- - ERB in a configuration file runs code: load only files you trust.
533
+ - The gem evaluates no ERB. `api_recipes upgrade --erb` and
534
+ `api_recipes routes --erb` do, on the files of a 2.x project that you name:
535
+ that runs the code in them.
473
536
 
474
537
  See [Security in the README](README.md#security) for the same list in its place.
475
538
 
476
539
  ## The `api_recipes upgrade` command
477
540
 
478
- The gem installs a command that looks for the changes of this guide. It never
479
- changes a file. Run it in the root of your project, with no argument:
541
+ The gem installs a command that looks for the changes of this guide. It changes
542
+ a file only when you say yes to a change it shows you. Run it in the root of
543
+ your project, with no argument:
480
544
 
481
545
  $ bundle exec api_recipes upgrade
482
546
 
@@ -489,11 +553,25 @@ It finds by itself what to check, and says what it checked:
489
553
  `[breaks]`; a line that deserves a look because its result changes is marked
490
554
  `[check]`: a manual encoding of a path parameter, a bare `rescue`, `follow:`,
491
555
  `response.request`, the removed `Hash` and `Array` methods.
556
+ - **What a line alone does not tell.** The command also reads each Ruby file
557
+ as a tree, without running it, and finds: a credential assigned in the body
558
+ of a class, through a variable, over two lines or with `send`; a credential
559
+ that is not text; `api :format` and the other names that are already
560
+ methods; a class that gives an API its own `host`, `protocol` or `port`
561
+ and no credential; `apis_configs` assigned after the files; a block passed
562
+ to `run` whose value is used; `request`, `to_s` and `respond_to?` called on
563
+ what `run` returned, whatever the variable is called; and `Error`,
564
+ `VERSION` or the name of an error of the gem written alone in a class that
565
+ includes `ApiRecipes`. A file that is not valid Ruby is read line by line
566
+ only.
492
567
  - **The files that describe an API**: the YAML files (`.yml`, `.yaml`, also
493
568
  followed by `.erb`) where a name has `endpoints`, each with its options or
494
569
  with none, and the files called `NAME.recipe.yml`. Those under `spec`, `test`
495
570
  and `features` are fixtures and are left out. Each is checked with the rules
496
- of 3.0 (marked `[config]`).
571
+ of 3.0 (marked `[config]`). Two changes that give no error are marked
572
+ `[check]`: `timeout`, `on_bad_code`, `mime_type` or `verify_with` set on an
573
+ endpoint whose inner endpoints do not set it, which now find it there, and
574
+ an endpoint whose name is a method of the object that would have it.
497
575
  - **Less noise.** A bare `rescue` or a call to `CGI.escape` is in every
498
576
  application. The checks that also match code that has nothing to do with the
499
577
  gem are applied only to the files whose code names `ApiRecipes` or calls one
@@ -518,22 +596,28 @@ It finds by itself what to check, and says what it checked:
518
596
  only what it is sure of: one whole expression, with no `if`, `unless`,
519
597
  `rescue`, `and` or `or` after it, on a line that is always run.
520
598
 
521
- ```
522
- app/client.rb:5: [breaks] endpoint.route was removed: use response.fill or endpoint.definition
523
- app/client.rb:6: [check] a bare rescue now catches ApiRecipes errors too
524
- config/apis/github.yml: [config] github: unknown option 'hots'
599
+ What needs an answer comes last, where the terminal stops: what was checked,
600
+ the changes the command cannot find, the findings, and what to do.
525
601
 
602
+ ```
526
603
  Checked 214 Ruby files, 6 of them use api_recipes
527
604
  Checked 2 configuration files: config/apis/billing.yml, config/apis/github.yml
528
605
  app/models/shop.rb:4: declares the api 'shopify', and no configuration file found here describes it
529
606
  config/apis/billing.yml: 2 values come from ERB and were not checked
530
607
 
608
+ What this command cannot find
609
+ (the list of the changes that a search in the text cannot find)
610
+
611
+ app/client.rb:5: [breaks] endpoint.route was removed: use response.fill or endpoint.definition
612
+ app/client.rb:6: [check] a bare rescue now catches ApiRecipes errors too
613
+ config/apis/github.yml: [config] github: unknown option 'hots'
614
+
531
615
  Code to paste
532
616
 
533
617
  In config/initializers/api_recipes.rb, replace the block of ApiRecipes.configure (lines 1 to 3) with:
534
618
 
535
619
  ApiRecipes.configure do |config|
536
- config.apis_files_paths = Dir['config/apis/*.yml']
620
+ config.recipes_paths = Dir['config/api_recipes/*.recipe.yml']
537
621
  config.values = {
538
622
  github: { authorization: "Bearer #{ENV['GITHUB_TOKEN']}" }
539
623
  }
@@ -541,10 +625,74 @@ In config/initializers/api_recipes.rb, replace the block of ApiRecipes.configure
541
625
 
542
626
  Then remove the lines that gave these values: config/initializers/github.rb:1
543
627
 
544
- (the list of what the command cannot find)
545
-
546
628
  3 findings
629
+
630
+ What to do now
631
+ 1. Fix the 1 line marked breaks: that code stops working, and each line says what to use instead
632
+ 2. Correct what is marked config (1): each is a problem in a file that describes an api
633
+ 3. Read the 1 line marked check: the result changes, and only you can tell whether the code still does what it should. A check line is reported at every run
634
+ 4. Go through what this command cannot find: look in the code for the changes that concern the project
635
+ 5. Run this command again: go on when only check lines that you have read are left
636
+ 6. Start the application and run its tests: ApiRecipes.configure checks the whole configuration when it loads, also what an ERB tag gives, and lists every problem at once
637
+ ```
638
+
639
+ **On a terminal the command offers to make the changes it is sure of**, one
640
+ at a time. Today they are the values that a line gave when the application
641
+ started: `ApiRecipes.print_urls = ...` moves into the block of
642
+ `ApiRecipes.configure`, and the credentials assigned on `ApiRecipes.NAME`
643
+ become `config.values`. For a `rescue` that names no class, or
644
+ `StandardError`, it offers to put before it `rescue ApiRecipes::Error` with a
645
+ `raise`, which is what 2.x did: the errors of the gem go on to the code that
646
+ called. Answer no when that rescue should handle them from now on. Each change
647
+ is shown as a diff of the files it touches, and is made only when you answer
648
+ `y` or `yes`:
649
+
547
650
  ```
651
+ Move print_urls into the block of ApiRecipes.configure
652
+
653
+ config/initializers/api_recipes.rb:1
654
+ ApiRecipes.configure do |config|
655
+ config.recipes_paths = Dir['config/api_recipes/*.recipe.yml']
656
+ + config.print_urls = true
657
+ end
658
+ - ApiRecipes.print_urls = true
659
+
660
+ Make this change? [y/N]
661
+ ```
662
+
663
+ - A change is all the files it needs or none: the line that gave the value
664
+ is taken out together with the line that is added.
665
+ - It touches only files that git has committed as they are now, so that
666
+ `git diff` shows the change and `git checkout` undoes it. Otherwise the
667
+ command says why, and gives the code to paste as before. A file saved while
668
+ the question waits is not written over: the command says so and writes
669
+ nothing. A file whose lines end with CR LF is left to you.
670
+ - A line is taken out only when it is the assignment and nothing else, and
671
+ the value reads nothing that only that place has: a local variable, an
672
+ instance variable, a method of the file, `__FILE__`. A value given after
673
+ other code that may prepare it, as a `require` or `Dotenv.load`, is left to
674
+ you: in the file of the block when that code comes between the block and the
675
+ line, in another file when that file holds any other code, because it runs
676
+ at another time. So are two credentials for one API, for which the code to
677
+ paste gives neither and says to choose, and a block of `configure` that the
678
+ command cannot read whole or that already assigns the value.
679
+ - A rescue is changed only in a file that names the gem. A change you refuse
680
+ stays among the findings, with its code to paste. A `rescue` that comes
681
+ after one that catches the errors of the gem first (`ApiRecipes::Error`,
682
+ `StandardError`, `Exception`, or one that names no class) is not a finding.
683
+ - Given files or folders to check, the command moves no API to a recipe and
684
+ does not take `apis_files_paths` out: it does not know the rest of the
685
+ project. Run it without arguments in the root of the project for those.
686
+ - It asks only when it reads the answers from a terminal and shows the
687
+ results on one. Away from a terminal, as in a CI or with the results sent
688
+ to a file, and with `--no-code`, the command asks nothing and changes
689
+ nothing.
690
+
691
+ The steps at the end are those of what was found: a kind of finding that is
692
+ not there has no step. On a terminal the same results are shown in sections,
693
+ with a colour for each kind of finding and lines that fit the width of the
694
+ window. Away from a terminal, as in a CI or through a pipe, and with
695
+ `NO_COLOR` set, the text is the one above, with no colours.
548
696
 
549
697
  The line about `api :shopify` is said of a declaration in the code when no file
550
698
  found in the project describes that API and the code never assigns
@@ -557,9 +705,9 @@ file.
557
705
 
558
706
  $ api_recipes upgrade app lib --config config/apis/github.yml
559
707
 
560
- The command then prints the list of changes that a search in the text
561
- cannot find, which you check by hand (this guide has the details of each), and a
562
- summary line: `Nothing to change`, `1 finding` or `N findings`. When it found
708
+ The list of the changes that a search in the text cannot find is the same at
709
+ every run: you check them by hand, and this guide has the details of each. The
710
+ summary line is `Nothing to change`, `1 finding` or `N findings`. When it found
563
711
  no description of an API it says so instead of `Nothing to change`. The summary
564
712
  line is left out when there is no finding and something could not be read.
565
713
 
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ApiRecipes
4
+ module CLI
5
+ # How each endpoint of an api is called in Ruby, after the name of the
6
+ # api: `.repos.issues(owner, repo).create`. It is what `routes` lists,
7
+ # made from the compiled tree, so that a comment that shows it is true
8
+ # when it is written.
9
+ module Calls
10
+ # What a call is made of: names of endpoints and of the parameters of
11
+ # their paths, and what joins them. Anything else is not written.
12
+ NAMES = /\A[\w.?!(), \[\]:"-]+\z/
13
+
14
+ # { names of the endpoint, from the api down => the call } for every
15
+ # endpoint that can be called.
16
+ def self.of(definition, level = definition.endpoints, names = [], steps = '', found = {})
17
+ level.each_value do |node|
18
+ here = names + [node.name.to_s]
19
+ call = "#{steps}#{Internals::Definition.step(node.name, node.path_params, names.empty?)}"
20
+ found[here] = call if node.route? && call.match?(NAMES)
21
+ of(definition, node.endpoints, here, call, found)
22
+ end
23
+ found
24
+ end
25
+ end
26
+ end
27
+ end