Skip to content

Commit 06ce31d

Browse files
committed
feat(OpenAPI): Migrate from api-typings to openapi spec
BREAKING CHANGE: Core-Interface typings now uses @ideal-postcodes/openapi
1 parent e8d1ce1 commit 06ce31d

20 files changed

+85
-42
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ If you are looking for the browser or Node.js client which implements this inter
2424
- [API Documentation](https://core-interface.ideal-postcodes.dev/)
2525
- [npm Module](https://www.npmjs.com/package/@ideal-postcodes/core-interface)
2626
- [GitHub Repository](https://github.com/ideal-postcodes/core-interface)
27-
- [Typings Repository](https://github.com/ideal-postcodes/api-typings)
27+
- [Typings Repository](https://github.com/ideal-postcodes/openapi)
2828
- [Fixtures Repository](https://github.com/ideal-postcodes/api-fixtures)
2929

3030
## Downstream Clients

lib/error.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66

77
import { HttpResponse } from "./agent";
8-
import { ApiErrorResponse } from "@ideal-postcodes/api-typings";
8+
import { components } from "@ideal-postcodes/openapi";
9+
10+
export type ApiErrorResponse = components["schemas"]["ErrorResponse"];
911

1012
/**
1113
* IdealPostcodesErrorOptions

lib/helpers.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ import {
2121
IdpcUmprnNotFoundError,
2222
IdpcUdprnNotFoundError,
2323
} from "./error";
24-
import { Address, KeyStatus } from "@ideal-postcodes/api-typings";
24+
import {
25+
UkAddress,
26+
PafAddress,
27+
NybAddress,
28+
MrAddress,
29+
KeyStatus,
30+
} from "./types";
2531
import {
2632
Authenticable,
2733
Filterable,
@@ -166,7 +172,7 @@ export const ping = (client: Client): Promise<HttpResponse> => {
166172
*/
167173
export const lookupPostcode = (
168174
options: LookupPostcodeOptions
169-
): Promise<Address[]> => {
175+
): Promise<PafAddress[]> => {
170176
const queryOptions = toAddressIdQuery(options);
171177

172178
const { page } = options;
@@ -190,7 +196,7 @@ export const lookupPostcode = (
190196
*/
191197
export const lookupAddress = (
192198
options: LookupAddressOptions
193-
): Promise<Address[]> => {
199+
): Promise<UkAddress[]> => {
194200
const header: StringMap = {};
195201
const query: StringMap = { query: options.query };
196202
const { client } = options;
@@ -243,7 +249,7 @@ const toAddressIdQuery = (options: LookupIdOptions): Request => {
243249
*/
244250
export const lookupUdprn = (
245251
options: LookupUdprnOptions
246-
): Promise<Address | null> => {
252+
): Promise<PafAddress | NybAddress | null> => {
247253
const queryOptions = toAddressIdQuery(options);
248254
return udprn
249255
.retrieve(options.client, options.udprn.toString(), queryOptions)
@@ -265,7 +271,7 @@ export const lookupUdprn = (
265271
*/
266272
export const lookupUmprn = (
267273
options: LookupUmprnOptions
268-
): Promise<Address | null> => {
274+
): Promise<MrAddress | null> => {
269275
const queryOptions = toAddressIdQuery(options);
270276
return umprn
271277
.retrieve(options.client, options.umprn.toString(), queryOptions)

lib/resources/addresses.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { listMethod } from "./resource";
2-
import { AddressQueryResponse } from "@ideal-postcodes/api-typings";
2+
import { AddressResponse } from "../types";
33
import { OptionalStringMap } from "../util";
44
import { Client } from "../client";
55
import { HttpResponse } from "../agent";
@@ -53,7 +53,7 @@ export interface Request {
5353
}
5454

5555
export interface Response extends HttpResponse {
56-
body: AddressQueryResponse;
56+
body: AddressResponse;
5757
}
5858

5959
const resource = "addresses";
@@ -63,4 +63,4 @@ export interface List {
6363
}
6464

6565
export const list: List = (client, request) =>
66-
listMethod<Request, AddressQueryResponse>({ resource, client })(request);
66+
listMethod<Request, AddressResponse>({ resource, client })(request);

lib/resources/keys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
PublicKeyResponse,
44
PrivateKeyResponse,
55
KeyUsageResponse,
6-
} from "@ideal-postcodes/api-typings";
6+
} from "../types";
77
import { OptionalStringMap } from "../util";
88
import { Client } from "../client";
99
import { HttpResponse } from "../agent";

lib/resources/postcodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { retrieveMethod } from "./resource";
2-
import { PostcodesResponse } from "@ideal-postcodes/api-typings";
2+
import { PostcodesResponse } from "../types";
33
import { OptionalStringMap } from "../util";
44
import { Client } from "../client";
55
import { HttpResponse } from "../agent";

lib/resources/udprn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { retrieveMethod } from "./resource";
2-
import { UdprnResponse } from "@ideal-postcodes/api-typings";
2+
import { UdprnResponse } from "../types";
33
import { OptionalStringMap } from "../util";
44
import { Client } from "../client";
55
import { HttpResponse } from "../agent";

lib/resources/umprn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { retrieveMethod } from "./resource";
2-
import { UmprnResponse } from "@ideal-postcodes/api-typings";
2+
import { UmprnResponse } from "../types";
33
import { OptionalStringMap } from "../util";
44
import { Client } from "../client";
55
import { HttpResponse } from "../agent";

lib/types.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,44 @@
22
* @module Misc Types
33
*/
44

5-
import { Address } from "@ideal-postcodes/api-typings";
5+
import { paths, components } from "@ideal-postcodes/openapi";
6+
7+
export type AddressResponse =
8+
paths["/addresses"]["get"]["responses"][200]["content"]["application/json"];
9+
10+
export type AddressSuggestionResponse =
11+
paths["/autocomplete/addresses"]["get"]["responses"][200]["content"]["application/json"];
12+
13+
export type GbrResolveResponse =
14+
paths["/autocomplete/addresses/{address}/gbr"]["get"]["responses"][200]["content"]["application/json"];
15+
16+
export type PublicKeyResponse =
17+
paths["/keys/{key}"]["get"]["responses"][200]["content"]["application/json"];
18+
19+
export type PrivateKeyResponse =
20+
paths["/keys/{key}/details"]["get"]["responses"][200]["content"]["application/json"];
21+
22+
export type KeyUsageResponse =
23+
paths["/keys/{key}/usage"]["get"]["responses"][200]["content"]["application/json"];
24+
25+
export type PostcodesResponse =
26+
paths["/postcodes/{postcode}"]["get"]["responses"][200]["content"]["application/json"];
27+
28+
export type UdprnResponse =
29+
paths["/udprn/{udprn}"]["get"]["responses"][200]["content"]["application/json"];
30+
31+
export type UmprnResponse =
32+
paths["/umprn/{umprn}"]["get"]["responses"][200]["content"]["application/json"];
33+
34+
export type KeyStatus = components["schemas"]["ApiKey"];
35+
36+
export type PafAddress = components["schemas"]["PafAddress"];
37+
38+
export type MrAddress = components["schemas"]["MrAddress"];
39+
40+
export type NybAddress = components["schemas"]["NybAddress"];
41+
42+
export type UkAddress = PafAddress | MrAddress | NybAddress;
643

744
/**
845
* Authenticable
@@ -35,7 +72,7 @@ export interface AdminAuthenticable {
3572
/**
3673
* Address object attributes
3774
*/
38-
export type AddressKeys = keyof Address;
75+
export type AddressKeys = keyof components["schemas"]["PafAddress"];
3976

4077
/**
4178
* Filterable

package-lock.json

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

0 commit comments

Comments
 (0)