Skip to content

Instantly share code, notes, and snippets.

@rajibkuet07
Created September 22, 2023 06:01
Show Gist options
  • Save rajibkuet07/06601f909ee941af9accc5ea51189a2d to your computer and use it in GitHub Desktop.
Save rajibkuet07/06601f909ee941af9accc5ea51189a2d to your computer and use it in GitHub Desktop.
Consume OpenAPI Specifications in any application

Consume OpenAPI Specifications in any application

Suppose the api that we will use for openapi specs is ucs and the app that will consume the openapi spec is core

Approaches for handling all routes of ucs from core with proper type safety

First Approach

  1. Generate and store openapi specs from the ucs in core - use openapi-typescript - need to run npx openapi-typescript <ucs-swagger-json-url> -o ./src/common/openapi-specs/cloud-schema.d.ts

    This may have a issue. We have to update each time using this cmd after any change in the spec of ucs.

    @see - https://github.com/drwpow/openapi-typescript/tree/main/packages/openapi-typescript

  2. Use this specs in the endpoints of core and use http module or any other fetch module to fetch data from ucs - use axios | feTs | openapi-fetch

    @see - https://openapi-ts.pages.dev/openapi-fetch/

Second Approach

  1. Use cron once daily to store the specs of ucs in the core. Should follow feTS way if you want to use feTS.
  2. Use feTS package to handle http requests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment