api_recipes 3.0.0.beta4 → 3.0.0.beta5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0758e23f654ba318829b6a64cc4fce5f2241efb5f1d872348d7b8d45d31f9684'
4
- data.tar.gz: 4612f273b0cd8e76d7f9a96e9ed5c3577995fec08065f22678cf01da4dde8331
3
+ metadata.gz: 57bcc9de8b80033015cc0a780f9d59a9d4eb4a31206d47d142302b81d039ff01
4
+ data.tar.gz: b03292e718ae4ad4a967270aa6eda834ce67221bb972a7afa9936bfcfed57a0e
5
5
  SHA512:
6
- metadata.gz: a1ceeb393133583bd1645545a1e211f7ddbc8342e23947a2dbeed7483714c8f8d3363edfdac420520a1d2c70fd44d31ad7e73996c89061fb2e396c06733670d3
7
- data.tar.gz: 0fed2e2602edd6f233ce07b5f7f54ee535c9a1a432928abd152e6ab27509e766b81ea2677dd3bf25ea311d9e70e28aba814b38c1377a9e14b78c75484f644e9f
6
+ metadata.gz: 93456b96e48047dea08bf1703a80144a38323278a1ab27add7e0dd7d2d00500b1a25fcb5e09707e398d48295b8ed92e41ab42712ad78cf72cd9f120f50f95999
7
+ data.tar.gz: 97c8c52a08d74b1edb22ca0314ef66ea746dfe7355275f3ca49d152278a2b23d0674247f39e6acd0055092c2990cf10ed65868528658b7bd813fe43b7ea54d7a
data/README.md CHANGED
@@ -69,10 +69,15 @@ Or install it directly:
69
69
 
70
70
  ## Quick start
71
71
 
72
- **1. Describe the API** in a YAML file, for example `config/apis/github.yml`:
72
+ **1. Describe the API** in a recipe, a YAML file called after the API, for
73
+ example `config/api_recipes/github.recipe.yml`:
73
74
 
74
75
  ```yaml
75
76
  github:
77
+ recipe:
78
+ name: github
79
+ version: 1.0.0
80
+ format: 1
76
81
  host: api.github.com
77
82
  endpoints:
78
83
  users: # GET /users
@@ -89,7 +94,7 @@ github:
89
94
  require 'api_recipes'
90
95
 
91
96
  ApiRecipes.configure do |config|
92
- config.apis_files_paths = ['config/apis/github.yml']
97
+ config.recipes_paths = Dir['config/api_recipes/*.recipe.yml']
93
98
  end
94
99
  ```
95
100
 
@@ -296,8 +301,10 @@ All options are listed in the [options reference](#options-reference).
296
301
  ### Headers and parameters sent with every request
297
302
 
298
303
  `default_headers` are sent with every request, and `default_params` are added
299
- to every query string. Both can also be written on an endpoint: there they hold
300
- for that endpoint and for the ones below it, on top of those of the API.
304
+ to every query string. Both can also be written on an endpoint. A request
305
+ looks for them up the tree: on its endpoint, then on each endpoint that
306
+ contains it, then on the API, and sends what it finds, the nearest winning
307
+ for a name written more than once.
301
308
 
302
309
  ```yaml
303
310
  billing:
@@ -349,8 +356,10 @@ of an endpoint, the value of a header or of a parameter sent with every
349
356
  request, or in one of the options that are read when a request is sent:
350
357
  `protocol`, `port`, `timeout`, `on_bad_code`, `mime_type`, `verb` and
351
358
  `ok_code`. Use it for what changes from one account or one environment to the
352
- next, such as the address of a shop. Declare the variables of the API, with an
353
- optional `default` and `description`:
359
+ next, such as the address of a shop. Every `{name}` that the API uses is one of
360
+ its variables. Declare a variable under `variables` to give it a `default` or a
361
+ `description`; one with neither needs no declaration, and a value must be
362
+ given to it:
354
363
 
355
364
  ```yaml
356
365
  shopify:
@@ -359,8 +368,6 @@ shopify:
359
368
  description: the part of the shop address before .myshopify.com
360
369
  api_version:
361
370
  default: '2026-10'
362
- location:
363
- description: the id of the location this client works for
364
371
  host: '{shop}.myshopify.com'
365
372
  base_url: admin/api/{api_version}
366
373
  auth:
@@ -372,6 +379,8 @@ shopify:
372
379
  path: /locations/{location}/inventory_levels
373
380
  ```
374
381
 
382
+ Here `location` is a variable too, with no default.
383
+
375
384
  A variable without a value and without a default raises
376
385
  `ApiRecipes::MissingVariable` as soon as it is needed: when the chain reaches
377
386
  the `base_url` or the path that uses it, and at the latest when the request is
@@ -426,8 +435,8 @@ store.shopify.products.url.to_s
426
435
  ```
427
436
 
428
437
  The options that a class gives to `api` can use the variables of the API, as in
429
- `api :shopify, host: '{shop}.staging.example.test'`. When an API exists only in
430
- a class, the names given in `variables:` are its variables, so each one gets a
438
+ `api :shopify, host: '{shop}.staging.example.test'`, and new ones: a `{name}`
439
+ they use is a variable of the API for that class. `variables:` gives them a
431
440
  value there, and an object or `with` can give another:
432
441
 
433
442
  ```ruby
@@ -522,8 +531,11 @@ In a parameter it is encoded like every value of a query string. Anything else
522
531
  raises `ApiRecipes::InvalidVariable`.
523
532
  A word in braces that is not a variable is written `\{word}` in a path and in
524
533
  a `base_url`.
525
- A name that the API does not declare raises `ApiRecipes::ConfigurationError` at
526
- every level, so a misspelled name is never ignored.
534
+ A value given for a name that the API neither declares nor uses raises
535
+ `ApiRecipes::ConfigurationError` at every level, so a name misspelled in your
536
+ code is never ignored. A `{name}` misspelled in the description is a variable
537
+ with no default: the first request that needs it raises
538
+ `ApiRecipes::MissingVariable`, which names it.
527
539
  `variables` without an assignment returns the values of the level you call it
528
540
  on: those of `config.values` on `ApiRecipes.shopify`, those given to `api` on a
529
541
  class, those assigned on an object. On an object, assigning `nil` clears them,
@@ -533,39 +545,52 @@ and a default declared in the file applies again.
533
545
 
534
546
  Configure ApiRecipes once, when your application starts.
535
547
 
536
- ### From YAML files
548
+ ### From recipes
537
549
 
538
550
  ```ruby
539
551
  ApiRecipes.configure do |config|
540
- config.apis_files_paths = ['config/apis/github.yml', 'config/apis/billing.yml']
552
+ config.recipes_paths = Dir['config/api_recipes/*.recipe.yml']
553
+ config.values = {
554
+ billing: { variables: { billing_host: ENV.fetch('BILLING_HOST', 'billing.example.com') } }
555
+ }
541
556
  end
542
557
  ```
543
558
 
544
- A file can describe one API or several. If two files describe the same API, the
545
- later one replaces the earlier one entirely. The same holds for the sources
546
- together: they are applied in the order they are assigned, so assigning
547
- `apis_configs` after `apis_files_paths` lets the Hash replace the file.
548
-
549
- A file that is missing, empty, not valid YAML or not valid UTF-8 raises
550
- `ApiRecipes::RecipeFileError`, which names the file. A file called
551
- `something.recipe.yml` is a [portable recipe](#portable-recipes) and goes in
552
- `recipes_paths`, where it is never evaluated with ERB: here it is refused,
553
- unless `recipes_paths` has it too, in which case it is left to `recipes_paths`.
554
- So one pattern, such as `config/apis/*.yml*`, can match both kinds of file in
555
- one folder.
556
-
557
- Files are evaluated with ERB before being parsed, so values can come from the
558
- environment:
559
+ A recipe is a file called `NAME.recipe.yml` that describes the API called
560
+ `NAME`, with the key `recipe` that gives its name, its version and the format.
561
+ It holds data and no code: it is never evaluated with ERB, and `<%` anywhere in
562
+ it is an error. What changes from one environment to another is a
563
+ [variable](#variables), and the application gives its value with
564
+ `config.values`:
559
565
 
560
566
  ```yaml
561
567
  billing:
562
- host: <%= ENV.fetch('BILLING_HOST', 'billing.example.com') %>
563
- timeout: <%= ENV.fetch('BILLING_TIMEOUT', 3) %>
568
+ recipe:
569
+ name: billing
570
+ version: 1.0.0
571
+ format: 1
572
+ variables:
573
+ billing_host:
574
+ default: billing.example.com
575
+ host: '{billing_host}'
564
576
  endpoints:
565
577
  invoices:
566
578
  ```
567
579
 
568
- Only files you wrote and trust should be loaded: ERB runs the Ruby code in them.
580
+ A recipe you write in your project is loaded as it is written, and you change
581
+ it as any other file. One that you took from a repository with
582
+ `api_recipes install` is also compared with `recipes.lock`: see
583
+ [Portable recipes](#portable-recipes). The rules of the format are under
584
+ [Writing a portable recipe](#writing-a-portable-recipe), and
585
+ `api_recipes check FILE` says whether a file follows them.
586
+
587
+ A file that is missing, not valid YAML, not valid UTF-8 or not a recipe raises
588
+ `ApiRecipes::RecipeFileError`, which names the file.
589
+
590
+ 2.x loaded YAML files evaluated with ERB through `apis_files_paths`. That
591
+ option was removed: assigning it raises `ApiRecipes::Error`, and
592
+ `api_recipes convert` moves those files to recipes. See
593
+ [From a file of your project](#from-a-file-of-your-project).
569
594
 
570
595
  ### From a Hash
571
596
 
@@ -592,11 +617,11 @@ configuration stays active.
592
617
  When an API publishes an OpenAPI description, the `api_recipes` command writes
593
618
  the recipe for you:
594
619
 
595
- $ api_recipes import openapi.yml --name github --output config/apis/github.yml
620
+ $ api_recipes import openapi.yml --name github --output config/api_recipes/github.recipe.yml
596
621
 
597
622
  The description is read once, when you run the command. Your application never
598
- reads it: it loads the recipe, which is a file like the ones above, and you can
599
- read it, trim it and rename things in it. These operations
623
+ reads it: it loads the recipe, which is a file like the ones above, complete with its
624
+ `recipe` key, and you can read it, trim it and rename things in it. These operations
600
625
 
601
626
  ```
602
627
  GET /users
@@ -613,6 +638,10 @@ become this recipe:
613
638
  ```
614
639
  # Generated by api_recipes import from GitHub 1.0
615
640
  github:
641
+ recipe:
642
+ name: github
643
+ version: 1.0.0
644
+ format: 1
616
645
  host: api.github.com
617
646
  endpoints:
618
647
  users: # GET /users (users/list)
@@ -652,12 +681,24 @@ github:
652
681
 
653
682
  | Option | Meaning |
654
683
  | --- | --- |
655
- | `--name NAME` | the name of the API in the recipe. Default: the title of the description, in lower case with `_` |
684
+ | `--name NAME` | the name of the API and of the recipe: lowercase letters, digits and `_`. Default: the title of the description, in lower case with `_` |
685
+ | `--version VERSION` | the version of the recipe. Default: `1.0.0` |
656
686
  | `--only GLOB` | only the paths that match; can be repeated. `*` also crosses `/`: `--only 'repos/*'` |
657
687
  | `--except GLOB` | leaves out the paths that match; can be repeated |
658
688
  | `--server N` | which entry of `servers` gives the address, counted from 0. Default: the first |
689
+ | `--calls` | writes under each endpoint how it is called in Ruby |
659
690
  | `--output FILE` | writes the recipe in FILE, which must not exist, instead of on STDOUT |
660
691
 
692
+ With `--calls`, who reads the recipe sees the call beside the request it
693
+ sends. The call starts after the name of the API, as in `github.users.show('octocat')`:
694
+
695
+ users: # GET /users (users/list)
696
+ # .users
697
+ endpoints:
698
+ show: # GET /users/{username} (users/get-by-username)
699
+ # .users.show(username)
700
+ path: "/:username"
701
+
661
702
  The input is one local file, YAML or JSON, OpenAPI 3.0 or 3.1. Warnings and a
662
703
  summary go to STDERR, so the recipe can be redirected. The command exits with 1
663
704
  when the description cannot be imported and with 2 when the arguments are wrong.
@@ -667,6 +708,7 @@ when the description cannot be imported and with 2 when the arguments are wrong.
667
708
  | From the description | In the recipe |
668
709
  | --- | --- |
669
710
  | the address of the server | `protocol`, `host`, `port`, `base_url` |
711
+ | no server, or an address without a host | `host: '{host}'`, a variable that the application gives with `config.values` |
670
712
  | the variables of the server | `variables`, with their defaults |
671
713
  | the paths | the tree of endpoints |
672
714
  | the path parameters | `:name` placeholders |
@@ -728,30 +770,34 @@ A portable recipe is a recipe made to be shared: one API in one file, and
728
770
  nothing but data. You install it with a command that shows what it does before
729
771
  it writes anything, and you load it with `recipes_paths`.
730
772
 
731
- $ api_recipes install github
732
- github 1.0.0
733
- summary: GitHub REST API, users, repositories, issues and pull requests
773
+ $ api_recipes install github_essentials
774
+ reading github_essentials from https://github.com/madAle/api_recipes-cookbook
775
+ github_essentials 1.0.0
776
+ summary: GitHub REST API, the most used calls on users, repositories, issues and pull requests
734
777
  homepage: https://docs.github.com/en/rest
735
- from: https://github.com/madAle/api_recipes-cookbook, commit a4e8dd017d05
778
+ from: https://github.com/madAle/api_recipes-cookbook, commit cd19ca58aea1
736
779
  address: https://api.github.com
737
780
  credential: in the Authorization header
738
781
  headers: Accept: application/vnd.github+json
739
782
  calls: 14, of which 2 are not GET:
740
- POST github.repos.issues(owner, repo).create /repos/:owner/:repo/issues
741
- POST github.repos.issues(owner, repo).comments(issue_number).create /repos/:owner/:repo/issues/:issue_number/comments
742
- Install github 1.0.0 in config/api_recipes? [y/N] y
743
- github 1.0.0 is installed in config/api_recipes/github.recipe.yml
783
+ POST github_essentials.repos.issues(owner, repo).create /repos/:owner/:repo/issues
784
+ POST github_essentials.repos.issues(owner, repo).comments(issue_number).create /repos/:owner/:repo/issues/:issue_number/comments
785
+ Install github_essentials 1.0.0 in config/api_recipes? [y/N] y
786
+ github_essentials 1.0.0 is installed in config/api_recipes/github_essentials.recipe.yml
744
787
 
745
788
  ```ruby
746
789
  ApiRecipes.configure do |config|
747
790
  config.recipes_paths = Dir['config/api_recipes/*.recipe.yml']
748
791
  end
749
792
 
750
- ApiRecipes.github.users.show('octocat').run
793
+ ApiRecipes.github_essentials.users.show('octocat').run
751
794
  ```
752
795
 
796
+ `github_essentials` has the most used calls of the GitHub API; the recipe
797
+ called `github` has every operation, 1,281 calls with the same names.
798
+
753
799
  The command writes two files in `config/api_recipes`: the recipe,
754
- `github.recipe.yml`, and `recipes.lock`, which records the version, the
800
+ `github_essentials.recipe.yml`, and `recipes.lock`, which records the version, the
755
801
  repository, the commit and the checksum of each installed recipe. Commit both
756
802
  to your repository: the application downloads nothing when it starts.
757
803
 
@@ -763,7 +809,7 @@ layout.
763
809
  ### Installing, updating and checking
764
810
 
765
811
  $ api_recipes install github # the recipe at the head of the cookbook
766
- $ api_recipes install github --version 1.0.0 # the one at the tag github-1.0.0
812
+ $ api_recipes install github --version 2.0.0 # the one at the tag github-2.0.0
767
813
  $ api_recipes install billing --from https://github.com/acme/api-recipes
768
814
  $ api_recipes install ./billing.recipe.yml # a file of yours
769
815
  $ api_recipes update github
@@ -848,15 +894,21 @@ this when it runs: the installed recipes are files of your project.
848
894
 
849
895
  ### What `configure` checks
850
896
 
851
- Every file of `recipes_paths` must be called `NAME.recipe.yml` and must be in
852
- the `recipes.lock` of its folder with the checksum it has now. A file that was
853
- changed after it was installed, or that was never installed, raises
854
- `ApiRecipes::ConfigurationError` and the previous configuration stays:
897
+ Every file of `recipes_paths` must be called `NAME.recipe.yml` and follow the
898
+ rules of the format. A recipe that `recipes.lock` ties to a repository, because
899
+ `install` took it from one, must also have the checksum the lock records. When
900
+ it was changed afterwards, `configure` raises `ApiRecipes::ConfigurationError`
901
+ and the previous configuration stays:
855
902
 
856
- config/api_recipes/github.recipe.yml: was changed after it was installed: its checksum is not the one in recipes.lock. To accept the file as it is now, run `api_recipes install config/api_recipes/github.recipe.yml`
903
+ config/api_recipes/github.recipe.yml: was changed after it was installed from its repository: its checksum is not the one in recipes.lock. To keep the file as it is now, as a recipe of the project, run `api_recipes install config/api_recipes/github.recipe.yml`
857
904
 
858
- A recipe never replaces an API: a name that `apis_configs`, `apis_files_paths`
859
- or another recipe already defines is an error. Everything else works as for any
905
+ A recipe that the lock does not tie to a repository is a recipe of the project:
906
+ one you wrote, one that `convert` or `import` wrote, or one you accepted with
907
+ `install FILE` after changing it. It is loaded as it is written, with nothing
908
+ to compare it with, and `update` leaves it alone.
909
+
910
+ A recipe never replaces an API: a name that `apis_configs` or another recipe
911
+ already defines is an error. Everything else works as for any
860
912
  API: credentials, variables, `with`, and `api :github` in a class. To add a
861
913
  `verify_with`, which a recipe cannot carry, declare it in your code:
862
914
 
@@ -935,14 +987,19 @@ published version is the tag `NAME-VERSION`, for example `billing-1.2.0`.
935
987
  When the API is already described in a file of your project, `convert` moves
936
988
  it to a portable recipe. Run it in the root of the project: a Rails
937
989
  application or any other Ruby project, wherever `ApiRecipes.configure` is
938
- called.
990
+ called. With no file it moves every API that a file of the project describes,
991
+ one after the other, which is what a project that comes from 2.x needs:
992
+
993
+ $ bundle exec api_recipes convert
994
+
995
+ With a file it moves the API of that file:
939
996
 
940
997
  $ bundle exec api_recipes convert config/apis/billing.yml.erb
941
998
  billing 1.0.0 now comes from a portable recipe: 2 calls
942
999
 
943
1000
  Changed in the project
944
1001
  created config/api_recipes/billing.recipe.yml, with its line in config/api_recipes/recipes.lock
945
- edited config/initializers/api_recipes.rb: recipes_paths and config.values
1002
+ edited config/initializers/api_recipes.rb: recipes_paths and config.values; apis_files_paths, which loads nothing now, is gone
946
1003
  edited app/models/invoice.rb: verify_with on the declaration of the api
947
1004
  deleted config/apis/billing.yml.erb
948
1005
 
@@ -959,7 +1016,6 @@ the code of each tag is moved, as it is written, to `config.values`.
959
1016
 
960
1017
  ```ruby
961
1018
  ApiRecipes.configure do |config|
962
- config.apis_files_paths = Dir[File.expand_path('../apis/*.yml.erb', __dir__)]
963
1019
  config.values = {
964
1020
  billing: { variables: {
965
1021
  billing_host: (ENV['BILLING_HOST'] || 'billing.example.test'),
@@ -986,7 +1042,15 @@ What the command does:
986
1042
  after its place, and a default written in the tag as plain text or as a
987
1043
  number (`ENV.fetch('NAME', 'text')`, `ENV['NAME'] || 443`) becomes the
988
1044
  default of the variable. A default that a tag gave to a variable the file
989
- declares is given by the application from now on.
1045
+ declares is given by the application from now on. Only a variable with a
1046
+ default is declared in the recipe.
1047
+ - **A word in braces stays text**, as 2.x sent it, unless the file declares a
1048
+ variable with that name: it is written `\{word}` in a `path` and in the
1049
+ `base_url`, and a header or a parameter that holds one is given by a
1050
+ variable whose default is its text.
1051
+ - **`--calls` writes beside each endpoint how it is called in Ruby**, as
1052
+ `show: # .invoices.show(id)`, after the name of the API. The recipe is the
1053
+ same with or without them.
990
1054
  - **Nothing in the file is run**, and there is no option that runs it. The
991
1055
  code of a tag goes to `config.values` as text, and each tag has its own
992
1056
  variable, also two tags in one value. `.compact` leaves out a variable whose
@@ -1002,7 +1066,12 @@ What the command does:
1002
1066
  before you share it.
1003
1067
  - **The old description is removed**: the file is deleted, or only the lines
1004
1068
  of that API when it describes others, because a recipe never takes the place
1005
- of an API that another source defines.
1069
+ of an API that another source defines. With the last description of the
1070
+ project the lines of `config.apis_files_paths` are taken out, when git has
1071
+ the file as it is now or as this run of the command left it, unless they
1072
+ still name a file that describes an API, as one in `vendor` that the command
1073
+ does not look at; otherwise the command tells you to take them out, because
1074
+ 3.0 refuses the option.
1006
1075
  - **`verify_with`**, which a recipe cannot carry, is given to each `api :name`
1007
1076
  that a class or a module declares. One that a tag gave, or that an endpoint
1008
1077
  had, is left to you, as it is when one of the declarations gives its options
@@ -1014,7 +1083,11 @@ It changes your files only when that is safe, and all at once or not at all:
1014
1083
 
1015
1084
  - Lines are added only to a plain file of the project that is in the last
1016
1085
  commit of git. A file is deleted, or lines are taken out of it, only when
1017
- git has it committed as it is now. A symbolic link, and a file that git was told to skip, are never
1086
+ git has it committed as it is now: the command works out the id of the
1087
+ file and compares it with the one in the index and in the last commit, so
1088
+ that no filter of the repository runs. A file that differs only by CR LF
1089
+ at the end of its lines, as git writes it with `core.autocrlf`, counts as
1090
+ committed. A symbolic link, and a file that git was told to skip, are never
1018
1091
  changed. Outside a git repository the project is not changed.
1019
1092
  - Ruby is read as a tree, never matched as lines and never run, and the
1020
1093
  command edits only what it can read whole:
@@ -1024,14 +1097,18 @@ It changes your files only when that is safe, and all at once or not at all:
1024
1097
  - `config.values`, which is added, or which gets one more entry when it is
1025
1098
  given a Hash between braces whose keys are all written as names, none of
1026
1099
  them the API, and whose closing brace starts a line;
1027
- - `config.apis_files_paths`, when the old file is deleted: it must be given
1028
- patterns of `Dir`, or a list between brackets of names written as text,
1029
- from which the one element that names the file is taken out.
1100
+ - `config.apis_files_paths`, while other files still describe an API: it
1101
+ must be given patterns of `Dir`, or a list between brackets of names
1102
+ written as text, from which the one element that names the file is taken
1103
+ out. With the last description the whole assignment goes, unless it still
1104
+ names another file that describes an API.
1030
1105
 
1031
1106
  Anything else stops it: another mention of the old file in the code, another
1032
1107
  file that describes the API, a `recipes_paths` it cannot read.
1033
1108
  - Every Ruby file it changes must still be Ruby with the change, and when a
1034
- write fails every file is put back as it was.
1109
+ write fails every file is put back as it was. A file that changed after the
1110
+ command read it is not written over. The recipe is not written below a
1111
+ symbolic link.
1035
1112
  - When a step is not possible, nothing is written, the command says why, and
1036
1113
  it gives the steps to do by hand with the code to paste: the commands that
1037
1114
  write and install the recipe, the lines for the block of
@@ -1445,7 +1522,7 @@ body, a credential or a query string: the body is on `error.response`.
1445
1522
  | `ApiRecipes::CredentialOriginMismatch` | a request would send a credential to an origin other than the one it was set for |
1446
1523
  | `ApiRecipes::InvalidUrl` | the address that would be contacted is not the one that was validated |
1447
1524
  | `ApiRecipes::ConfigurationError` | the configuration or the options of `with` or `follow` are not valid; has `errors`, the list of problems |
1448
- | `ApiRecipes::RecipeFileError` | a configuration file cannot be read; a kind of `ConfigurationError` that names the file |
1525
+ | `ApiRecipes::RecipeFileError` | a recipe file cannot be read; a kind of `ConfigurationError` that names the file |
1449
1526
  | `ApiRecipes::ApiNameClashError` | an API is declared twice in a class hierarchy, or `api :name` names a method the class already has |
1450
1527
  | `ApiRecipes::ApiConfigIsNotAnHash` | the second argument of `api` is not a Hash |
1451
1528
  | `HTTP::TimeoutError`, `HTTP::ConnectionError` | http.rb network errors |
@@ -1602,7 +1679,7 @@ ApiRecipes does not check its origin, so prefer the levels above.
1602
1679
  ApiRecipes.configure do |config|
1603
1680
  config.logger = Rails.logger # any Logger
1604
1681
  config.print_urls = true # log the URL of every request
1605
- config.apis_files_paths = ['config/apis/github.yml']
1682
+ config.recipes_paths = Dir['config/api_recipes/*.recipe.yml']
1606
1683
  end
1607
1684
  ```
1608
1685
 
@@ -1689,8 +1766,22 @@ github.users.show(username) GET https://api.github
1689
1766
  github.repos.issues(owner, repo).create POST https://api.github.com/repos/:owner/:repo/issues
1690
1767
  ```
1691
1768
 
1692
- A file that contains ERB is read only with `--erb`, because that runs the code
1693
- in it.
1769
+ With no file, in the root of a project, it lists the calls of every API of the
1770
+ project: it finds the files that describe an API, and the installed recipes, as
1771
+ `api_recipes upgrade` does.
1772
+
1773
+ ```
1774
+ $ bundle exec api_recipes routes
1775
+ shop.orders POST https://shop.example.com/orders
1776
+ billing.invoices GET {erb}://{erb}/api/v1/invoices
1777
+ billing.invoices.show(id) GET {erb}://{erb}/api/v1/invoices/:id
1778
+ config/apis/billing.yml.erb: what an ERB tag gives is shown as {erb}; --erb evaluates the file, which runs the code in it
1779
+ ```
1780
+
1781
+ A file that contains ERB is not run: what a `<%= ... %>` tag gives is shown as
1782
+ the variable `{erb}`. `--erb` evaluates the file instead, which runs the code
1783
+ in it. A file where a tag gives a name, or where a `<% ... %>` tag decides
1784
+ which lines exist, is listed only with `--erb`.
1694
1785
 
1695
1786
  ## Recipes
1696
1787
 
@@ -1700,7 +1791,7 @@ in it.
1700
1791
  # config/initializers/api_recipes.rb
1701
1792
  ApiRecipes.configure do |config|
1702
1793
  config.logger = Rails.logger
1703
- config.apis_files_paths = Dir[Rails.root.join('config', 'apis', '*.yml').to_s]
1794
+ config.recipes_paths = Dir[Rails.root.join('config', 'api_recipes', '*.recipe.yml').to_s]
1704
1795
  config.values = { github: { authorization: "Bearer #{Rails.application.credentials.github_token}" } }
1705
1796
  end
1706
1797
  ```
@@ -1710,16 +1801,35 @@ A value that depends on the user who is signed in does not go there: see
1710
1801
 
1711
1802
  ### One host per environment
1712
1803
 
1713
- Keep one file and let ERB pick the values:
1804
+ Keep one recipe, with the address as variables, and let each environment give
1805
+ its values:
1714
1806
 
1715
1807
  ```yaml
1716
1808
  reports:
1717
- protocol: <%= ENV.fetch('REPORTS_PROTOCOL', 'https') %>
1718
- host: <%= ENV.fetch('REPORTS_HOST', 'reports.example.com') %>
1809
+ recipe:
1810
+ name: reports
1811
+ version: 1.0.0
1812
+ format: 1
1813
+ variables:
1814
+ protocol:
1815
+ default: https
1816
+ host:
1817
+ default: reports.example.com
1818
+ protocol: '{protocol}'
1819
+ host: '{host}'
1719
1820
  endpoints:
1720
1821
  monthly:
1721
1822
  ```
1722
1823
 
1824
+ ```ruby
1825
+ ApiRecipes.configure do |config|
1826
+ config.recipes_paths = Dir['config/api_recipes/*.recipe.yml']
1827
+ config.values = {
1828
+ reports: { variables: { protocol: ENV['REPORTS_PROTOCOL'], host: ENV['REPORTS_HOST'] }.compact }
1829
+ }
1830
+ end
1831
+ ```
1832
+
1723
1833
  ### Every page of a list
1724
1834
 
1725
1835
  ```ruby
@@ -1863,8 +1973,9 @@ What ApiRecipes does:
1863
1973
  evaluated with ERB and is read as plain YAML, without anchors, aliases or
1864
1974
  tags. It cannot carry `verify_with`, cannot take the name of an API you
1865
1975
  already have, and cannot let a variable decide where its host ends. Its
1866
- text, comments included, holds only visible characters. It is loaded only if
1867
- it matches the checksum in `recipes.lock`.
1976
+ text, comments included, holds only visible characters. One that `install`
1977
+ took from a repository is loaded only if it matches the checksum in
1978
+ `recipes.lock`.
1868
1979
  - **`api_recipes install` and `update`** show where the requests and the
1869
1980
  credential go, the headers and the parameters sent with every request, those
1870
1981
  that an endpoint adds, and which calls are not GET, the ones that `resource`
@@ -1890,8 +2001,8 @@ What ApiRecipes does:
1890
2001
  `Marshal.dump` and `YAML.dump`, and its JSON is the one of `to_h`.
1891
2002
  - **`fill`** calls only public writers and skips keys that are not plain
1892
2003
  attribute names.
1893
- - **Configuration files** are read with `YAML.safe_load`, and the options are
1894
- validated when they are loaded.
2004
+ - **The configuration** is validated when it is loaded, whether it comes
2005
+ from a recipe or from `apis_configs`.
1895
2006
 
1896
2007
  What stays with your application:
1897
2008
 
@@ -1905,7 +2016,12 @@ What stays with your application:
1905
2016
  the variables of one user on it. Use `with`, or an object made for the request.
1906
2017
  - `response.original_response` is the raw http.rb response, and it gives access
1907
2018
  to the request that was sent, headers included. Do not log or serialize it.
1908
- - ERB in a configuration file runs code. Load only files you trust.
2019
+ - The gem evaluates no ERB. `api_recipes upgrade --erb` and
2020
+ `api_recipes routes --erb` do, on the files of a 2.x project that you name:
2021
+ that runs the code in them.
2022
+ - A recipe of the project, which the lock ties to no repository, is loaded as
2023
+ it is written: review a recipe that someone adds to the folder as you review
2024
+ code, because it decides where the requests and the credential go.
1909
2025
  - Read what `api_recipes install` shows before you answer yes. ApiRecipes checks
1910
2026
  the form of a recipe, not whose host it names. Commit the installed recipes
1911
2027
  and `recipes.lock`, and review their changes as you review code: the lock
@@ -1922,9 +2038,8 @@ Every protection has an example in [`spec/security`](spec/security); its
1922
2038
 
1923
2039
  | Option | Meaning |
1924
2040
  | --- | --- |
1925
- | `apis_files_paths` | Array of YAML files, evaluated with ERB |
2041
+ | `recipes_paths` | Array of portable recipes (`NAME.recipe.yml`), read as data only; one that `recipes.lock` ties to a repository is compared with it |
1926
2042
  | `apis_configs` | Hash of API descriptions |
1927
- | `recipes_paths` | Array of installed portable recipes (`NAME.recipe.yml`), read as data only and checked against `recipes.lock` |
1928
2043
  | `values` | for each API, its credential and the values of its variables for the whole application, as `{ api_name: { authorization: '...', variables: { name: value } } }`; `basic_auth` in place of `authorization` |
1929
2044
  | `logger` | a Logger to use |
1930
2045
  | `log_to` | path or IO for the default logger (default: STDERR) |
@@ -1962,8 +2077,8 @@ Every protection has an example in [`spec/security`](spec/security); its
1962
2077
  | `on_bad_code` | looked for up the tree | `raise` or `ignore` |
1963
2078
  | `mime_type` | looked for up the tree | content type used by `response.data` |
1964
2079
  | `verify_with` | looked for up the tree | method that decides whether a response is a success |
1965
- | `default_headers` | none | headers added to those of the API, for this endpoint and the ones below it |
1966
- | `default_params` | none | query parameters added to those of the API, for this endpoint and the ones below it |
2080
+ | `default_headers` | none | headers of this endpoint; a request finds them here when it looks up the tree, before those of the API |
2081
+ | `default_params` | none | query parameters of this endpoint; a request finds them here when it looks up the tree, before those of the API |
1967
2082
  | `resource` | `no` | `yes` adds the endpoints `show`, `create`, `update`, `replace` and `delete`; a list adds only the ones it names |
1968
2083
  | `endpoints` | none | nested endpoints |
1969
2084
 
@@ -2038,8 +2153,8 @@ Run one from the root of the repository:
2038
2153
 
2039
2154
  $ bundle exec ruby examples/simple_usage.rb
2040
2155
 
2041
- [`examples/config/github.yml.erb`](examples/config/github.yml.erb) is a
2042
- configuration file with every option commented.
2156
+ [`examples/config/github.recipe.yml`](examples/config/github.recipe.yml) is a
2157
+ recipe with every option commented.
2043
2158
 
2044
2159
  ## Compatibility
2045
2160