Skip to content

Commit d8d3eba

Browse files
authored
Merge pull request #10 from julienlebren/codex/resolve-api-drift-9
Align client with ISBNdb OpenAPI 2.7.1
2 parents 766d667 + e76b0b3 commit d8d3eba

10 files changed

Lines changed: 292 additions & 207 deletions

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,10 @@ int pageSize | How many items should be returned per page, maximum of 1,000
236236
* **Get key details**
237237

238238
```dart
239-
final keyDetails = isbnDb.getKeyDetails();
239+
final keyDetails = await isbnDb.getKeyDetails();
240240
```
241241

242-
Returns your API host and current plan usage (`total`, `spent`, `left`).
242+
Returns your API host, plan name, and current usage (`total`, `spent`, `left`).
243243

244244
* **Get global API stats**
245245

@@ -399,6 +399,7 @@ books | List<Book> | An array containing the books related to this subject
399399
Name | Type | Description
400400
------------ | ------------- | -------------
401401
apiHost | String | API host attached to your key
402+
planName | String | Name of the subscription plan attached to your key
402403
planLimit | PlanLimit | Usage details of the current API plan
403404

404405
**PlanLimit**

api/isbndb-api-documentation-v2.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# ISBNdb API v2 (OpenAPI 2.7.0)
1+
# ISBNdb API Documentation v2 (OpenAPI 2.7.1)
22

3-
Source: user-provided `doc.json` (OpenAPI 3.0.0)
3+
Source: `https://api2.isbndb.com/doc.json` (OpenAPI 3.0.0)
44

55
## API metadata
66

7-
- Title: `ISBNdb API v2`
8-
- Version: `2.7.0`
7+
- Title: `ISBNdb API Documentation v2`
8+
- Version: `2.7.1`
99
- Server: `https://api2.isbndb.com`
1010
- Security: `ApiKeyAuth` (`Authorization` header)
1111

@@ -299,7 +299,7 @@ Responses:
299299
| `SearchBookFilters2` | - | `isbn`, `isbn13`, `author`, `text`, `subject`, `publisher`, `publishedFrom`, `publishedTo` |
300300
| `Point` | `x`, `y` | `x`, `y` |
301301
| `Price` | `condition`, `merchant`, `merchant_logo`, `merchant_logo_offset`, `shipping`, `price`, `total`, `link` | price row fields |
302-
| `Book` | `title`, `title_long`, `isbn`, `isbn13`, `date_published` | `isbn10`, `dewey_decimal`, `binding`, `publisher`, `language`, `edition`, `pages`, `dimensions`, `dimensions_structured`, `overview`, `image`, `image_original`, `msrp`, `excerpt`, `synopsis`, `authors`, `subjects`, `reviews`, `prices`, `related`, `other_isbns` |
302+
| `Book` | `title`, `title_long`, `isbn`, `isbn13`, `date_published` | `isbn10`, `binding`, `publisher`, `language`, `edition`, `pages`, `dimensions`, `dimensions_structured`, `overview`, `image`, `image_original`, `msrp`, `excerpt`, `synopsis`, `authors`, `subjects`, `reviews`, `prices`, `related`, `other_isbns` |
303303
| `AuthorDetailsResponse` | `author`, `name`, `books`, `total`, `page`, `page_size` | author + books + pagination |
304304
| `SearchAuthorsResponse` | `name`, `authors`, `total`, `page`, `page_size` | authors list + pagination |
305305
| `GetBookResponse` | `book` | `book` |
@@ -308,7 +308,7 @@ Responses:
308308
| `UpdatedBook` | `isbn13`, `updated_at` | `isbn13`, `updated_at` |
309309
| `UpdatedBooksResponse` | `data`, `page`, `page_size` | `data`, `page`, `page_size` |
310310
| `PlanLimit` | `total`, `spent`, `left` | quota counters |
311-
| `KeyResponse` | `api_host`, `plan_limit` | host + limits |
311+
| `KeyResponse` | `api_host`, `plan_limit`, `plan_name` | host + plan name + limits |
312312
| `DetailsResponse` | `name`, `books`, `total`, `page`, `page_size` | publisher details |
313313
| `SearchPublishersResponse` | `name`, `publishers`, `total`, `page`, `page_size` | publishers list + pagination |
314314
| `SearchBaseResponse` | `name`, `data`, `total`, `page`, `page_size` | generic search payload |
@@ -418,7 +418,6 @@ Enum values: `title`, `author`, `date_published`, `subjects`
418418
| `isbn` | string | yes | no | yes | - | Legacy ISBN-13 field |
419419
| `isbn13` | string | yes | no | no | - | ISBN-13 |
420420
| `isbn10` | string | no | yes | no | - | ISBN-10 if available |
421-
| `dewey_decimal` | `array<string>` | no | yes | no | - | Dewey decimals |
422421
| `binding` | string | no | yes | no | - | Binding |
423422
| `publisher` | string | no | yes | no | - | Publisher |
424423
| `language` | string | no | yes | no | - | Language |
@@ -496,6 +495,7 @@ Enum values: `title`, `author`, `date_published`, `subjects`
496495
| --- | --- | --- | --- | --- | --- | --- |
497496
| `api_host` | string | yes | no | no | - | API host |
498497
| `plan_limit` | `PlanLimit` | yes | no | no | - | Plan quota details |
498+
| `plan_name` | string | yes | no | no | - | Subscription plan name |
499499

500500
### `DetailsResponse`
501501

api/upstream/isbndb-openapi.json

Lines changed: 162 additions & 159 deletions
Large diffs are not rendered by default.

lib/isbndb.freezed.dart

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

lib/isbndb.g.dart

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

lib/src/key_details.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ sealed class KeyDetails with _$KeyDetails {
77
/// API host tied to this key.
88
@JsonKey(name: 'api_host') required String apiHost,
99

10+
/// Name of the subscription plan attached to this key.
11+
///
12+
/// Empty only for legacy payloads captured before API 2.7.1.
13+
@JsonKey(name: 'plan_name') @Default('') String planName,
14+
1015
/// Plan usage details.
1116
@JsonKey(name: 'plan_limit') required PlanLimit planLimit,
1217
}) = _KeyDetails;

scripts/check_api_spec_changes.sh

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,52 @@ normalize_spec() {
7575
local output="$2"
7676

7777
jq -S '
78+
def normalize_schema:
79+
if type != "object" then .
80+
else
81+
del(.description, .title, .example, .examples, .externalDocs)
82+
| if (.required? | type) == "array" then .required |= sort else . end
83+
| if (.enum? | type) == "array" then .enum |= sort_by(tostring) else . end
84+
| if (.properties? | type) == "object" then
85+
.properties |= (
86+
to_entries
87+
| sort_by(.key)
88+
| map(.value |= normalize_schema)
89+
| from_entries
90+
)
91+
else . end
92+
| if (.items? | type) == "object" then .items |= normalize_schema else . end
93+
| if (.additionalProperties? | type) == "object" then
94+
.additionalProperties |= normalize_schema
95+
else . end
96+
| if (.oneOf? | type) == "array" then
97+
.oneOf |= map(normalize_schema)
98+
else . end
99+
| if (.anyOf? | type) == "array" then
100+
.anyOf |= map(normalize_schema)
101+
else . end
102+
| if (.allOf? | type) == "array" then
103+
.allOf |= map(normalize_schema)
104+
else . end
105+
| if (.not? | type) == "object" then .not |= normalize_schema else . end
106+
end;
107+
78108
{
79109
openapi,
80110
info: {
81111
title: .info.title,
82112
version: .info.version
83113
},
84114
servers: ((.servers // []) | map({url, description})),
115+
components: {
116+
schemas: (
117+
(.components.schemas // {})
118+
| to_entries
119+
| sort_by(.key)
120+
| map(.value |= normalize_schema)
121+
| from_entries
122+
)
123+
},
85124
paths: (
86125
(.paths // {})
87126
| to_entries
@@ -103,22 +142,7 @@ normalize_spec() {
103142
name,
104143
in,
105144
required: (.required // false),
106-
schema: (
107-
.schema // {}
108-
| {
109-
type,
110-
format,
111-
enum,
112-
default,
113-
nullable,
114-
oneOf: ((.oneOf // []) | map({
115-
"$ref": .["$ref"],
116-
type,
117-
enum,
118-
nullable
119-
}))
120-
}
121-
)
145+
schema: ((.schema // {}) | normalize_schema)
122146
})
123147
| sort_by(.in, .name)
124148
),
@@ -127,12 +151,12 @@ normalize_spec() {
127151
else {
128152
required: (.value.requestBody.required // false),
129153
contentTypes: ((.value.requestBody.content // {}) | keys | sort),
130-
schemaRefs: (
154+
schemas: (
131155
(.value.requestBody.content // {})
132156
| to_entries
133157
| map({
134158
contentType: .key,
135-
schemaRef: (.value.schema["$ref"] // null)
159+
schema: ((.value.schema // {}) | normalize_schema)
136160
})
137161
| sort_by(.contentType)
138162
)
@@ -145,7 +169,15 @@ normalize_spec() {
145169
| sort_by(.key)
146170
| map({
147171
code: .key,
148-
schemaRef: (.value.content["application/json"].schema["$ref"] // null)
172+
schemas: (
173+
(.value.content // {})
174+
| to_entries
175+
| map({
176+
contentType: .key,
177+
schema: ((.value.schema // {}) | normalize_schema)
178+
})
179+
| sort_by(.contentType)
180+
)
149181
})
150182
)
151183
}
@@ -247,6 +279,18 @@ comm -3 "${tmp_dir}/reference.ops" "${tmp_dir}/candidate.ops" \
247279
| sed 's/^/ - /' \
248280
| head -n 60
249281

282+
echo "Changed component schemas:"
283+
jq -r -n \
284+
--slurpfile reference "${normalized_reference}" \
285+
--slurpfile candidate "${normalized_candidate}" '
286+
($reference[0].components.schemas // {}) as $reference_schemas
287+
| ($candidate[0].components.schemas // {}) as $candidate_schemas
288+
| (($reference_schemas | keys) + ($candidate_schemas | keys) | unique[])
289+
as $schema_name
290+
| select($reference_schemas[$schema_name] != $candidate_schemas[$schema_name])
291+
| $schema_name
292+
' | sed 's/^/ - /'
293+
250294
echo "Diff excerpt (first 120 lines):"
251295
head -n 120 "${tmp_dir}/spec.diff"
252296

0 commit comments

Comments
 (0)