You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In our API definitions, we have enums and model properties where some values or attributes are intended for internal use only or are restricted to partner teams. These values and properties should be excluded from the OpenAPI specification generated for external users, while still being available in internal or partner-facing code generation.
Solution:
Introduce a compilation check to optionally skip rendering specified enum values or model properties based on visibility annotations. This approach will allow us to define visibility rules directly in the API schema, enabling conditional exclusion during OpenAPI spec generation or code emission.
Implementation:
Enhance the existing @visibility annotation (or introduce a similar annotation) to support compile time visibility rules.
tspconfig.yaml
compilerOptions:
emit:
- "@typespec/openapi3"
options:
"@typespec/openapi3":
visibility: "external" # Define the audience: "external", "partner", or "internal"
main.tsp
enum DeploymentEnvironment {
Production: "Production"; // Always included in all contexts
Staging: "Staging"; // Always included in all contexts
@visibility(["internal"]) // Visible only to internal teams
Development: "Development";
@visibility(["partner", "internal"]) // Visible to internal teams and specific partners, but not external customers
QA: "QA";
}
model DataSource {
sourceType: SourceType; // Always included in all contexts
@visibility(["internal"]) // Marks this property as internal-only
internalConfiguration: string;
}
balassit
changed the title
Conditionally Excluding Internal Enum Values from OpenAPI Specs
Conditionally Excluding Properties from OpenAPI Specs
Jan 17, 2025
Problem Statement:
In our API definitions, we have enums and model properties where some values or attributes are intended for internal use only or are restricted to partner teams. These values and properties should be excluded from the OpenAPI specification generated for external users, while still being available in internal or partner-facing code generation.
Solution:
Introduce a compilation check to optionally skip rendering specified enum values or model properties based on visibility annotations. This approach will allow us to define visibility rules directly in the API schema, enabling conditional exclusion during OpenAPI spec generation or code emission.
Implementation:
Enhance the existing @visibility annotation (or introduce a similar annotation) to support compile time visibility rules.
tspconfig.yaml
main.tsp
Checklist
The text was updated successfully, but these errors were encountered: