Creating Internal and External SDKs
To create two different versions of an SDK, one for internal use and one for external use, use JSONPath expressions in OpenAPI Overlays (a standard extension for modifying existing OpenAPI documents without changing the original). This approach dynamically targets and hides internal operations and parameters from the public SDK. The workflow.yaml
file can be configured to include Overlays as part of the source definition.
Using the x-internal
Extension
First, add an x-internal: true
extension to all the operations, parameters, and other elements in the OpenAPI spec that should only be available in the internal SDK.
info:title: Sample APIversion: 1.0.0description: A sample API with internal paths and parameters.paths:/public-resource:get:summary: Retrieve public dataresponses:'200':description: Public data responsecontent:application/json:schema:type: objectproperties:id:type: stringname:type: string/internal-resource:x-internal: true # This path is internal and should not be exposed externallyget:summary: Retrieve internal dataresponses:'200':description: Internal data responsecontent:application/json:schema:type: objectproperties:id:type: stringinternalInfo:type: stringdescription: Internal informationx-internal: true # This field is internaldescription: "This endpoint is restricted for internal staff management and not visible in public SDKs."
Using JSONPath Expressions in an Overlay
Next, use a JSONPath expression to remove all the internal paths and parameters from the SDK. This removal occurs specifically when generating the internal SDK.
info:title: Sample API Overlayversion: 1.0.0actions:- target: $.paths.*.*[?(@["x-internal"] == true)]remove: true- target: $.paths.*.*[?(@.properties[?(@["x-internal"] == true)])]remove: true
Define a workflow that generates both the internal and external SDKs.
workflowVersion: 1.0.0speakeasyVersion: latestsources:external-api:inputs:- location: ./api.yamloverlays:- location: ./external-overlay.yamlinternal-api:inputs:- location: ./api.yamloverlays:- location: ./internal-overlay.yamltargets:internal-sdk:target: pythonsource: internal-apiexternal-sdk:target: pythonsource: external-api