Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally Excluding Properties from OpenAPI Specs #5659

Open
3 tasks done
balassit opened this issue Jan 17, 2025 · 0 comments
Open
3 tasks done

Conditionally Excluding Properties from OpenAPI Specs #5659

balassit opened this issue Jan 17, 2025 · 0 comments

Comments

@balassit
Copy link

balassit commented 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

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;
}

Checklist

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@balassit balassit changed the title Conditionally Excluding Internal Enum Values from OpenAPI Specs Conditionally Excluding Properties from OpenAPI Specs Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant