-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(services): Switches MeshService/MeshExternalService to use Open…
…API specs (#2748) First PR converting our Typescript types to use auto generated types using an OpenAPI spec as the source of truth. This means far less handwriting Typescript 🎉 We also use the `openapi-fetch` package as our HTTP client. --- Rough roadmap in relation to this: - We currently just expect `kuma-hq/kuma` to be a sibling on your file system in our to auto generate the types. We could do something more automated at some point in the, probably distant, future. - Slowly but surely move all that we can over to use our autogenerated types and new HTTP client. - Any missing types should be temporarily handwritten as OpenAPI YAML and an issue created over in `kumahq/kuma` so folks are aware we need these types. - Once we are completely on OpenApi we can switch the `sources.ts` dependencies to be `fetch` instead of the full `api`/`kumaApi` client. - Lastly remove `kumaApi` entirely and all the old handwritten types. Signed-off-by: John Cowen <john.cowen@konghq.com>
- Loading branch information
Showing
14 changed files
with
7,552 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { components } from '@/types/auto-generated.d' | ||
type GeneratedMeshExternalService = components['schemas']['MeshExternalServiceItem'] | ||
type GeneratedMeshExternalServiceList = components['responses']['MeshExternalServiceList']['content']['application/json'] | ||
|
||
export const MeshExternalService = { | ||
fromObject(item: GeneratedMeshExternalService) { | ||
const labels = item.labels ?? {} | ||
const name = labels['kuma.io/display-name'] ?? item.name | ||
const namespace = labels['k8s.kuma.io/namespace'] ?? '' | ||
return { | ||
...item, | ||
config: item, | ||
id: item.name, | ||
name, | ||
namespace, | ||
labels, | ||
status: ((item = {}) => { | ||
return { | ||
...item, | ||
addresses: Array.isArray(item.addresses) ? item.addresses : [], | ||
} | ||
})(item.status), | ||
|
||
} | ||
}, | ||
|
||
fromCollection(collection: GeneratedMeshExternalServiceList) { | ||
const items = Array.isArray(collection.items) ? collection.items.map(MeshExternalService.fromObject) : [] | ||
return { | ||
...collection, | ||
items, | ||
total: collection.total ?? items.length, | ||
} | ||
}, | ||
} | ||
export type MeshExternalService = ReturnType<typeof MeshExternalService['fromObject']> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { components } from '@/types/auto-generated.d' | ||
type GeneratedMeshService = components['schemas']['MeshServiceItem'] | ||
type GeneratedMeshServiceList = components['responses']['MeshServiceList']['content']['application/json'] | ||
|
||
export const MeshService = { | ||
fromObject(item: GeneratedMeshService) { | ||
const labels = item.labels ?? {} | ||
const name = labels['kuma.io/display-name'] ?? item.name | ||
const namespace = labels['k8s.kuma.io/namespace'] ?? '' | ||
return { | ||
...item, | ||
id: item.name, | ||
name, | ||
namespace, | ||
labels, | ||
spec: ((item = {}) => { | ||
return { | ||
ports: Array.isArray(item.ports) ? item.ports : [], | ||
selector: ((item = {}) => { | ||
return { | ||
dataplaneTags: Object.keys(item.dataplaneTags ?? {}).length > 0 ? item.dataplaneTags! : {}, | ||
} | ||
})(item.selector), | ||
} | ||
})(item.spec), | ||
status: ((item = {}) => { | ||
return { | ||
tls: typeof item.tls !== 'undefined' ? item.tls : { status: 'NotReady' }, | ||
vips: Array.isArray(item.vips) ? item.vips : [], | ||
addresses: Array.isArray(item.addresses) ? item.addresses : [], | ||
} | ||
})(item.status), | ||
config: item, | ||
} | ||
}, | ||
|
||
fromCollection(collection: GeneratedMeshServiceList) { | ||
const items = Array.isArray(collection.items) ? collection.items.map(MeshService.fromObject) : [] | ||
return { | ||
...collection, | ||
items, | ||
total: collection.total ?? items.length, | ||
} | ||
}, | ||
} | ||
export type MeshService = ReturnType<typeof MeshService['fromObject']> |
Oops, something went wrong.