-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tsp-openapi3 - update to group items by namespace when separated by d…
…ot, and escaped otherwise invalid identifiers (#3844) Fixes #3810 and replaces #3808 This PR does 2 things: 1. Groups operations/models into namespaces based on the dots in their schema names/operationIds. 2. Escapes invalid identifiers by surrounding them with backticks. --------- Co-authored-by: Christopher Radek <Christopher.Radek@microsoft.com>
- Loading branch information
1 parent
fef3f01
commit ae229b2
Showing
17 changed files
with
502 additions
and
141 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.chronus/changes/tsp-openapi3-namespacing-2024-6-15-22-37-45.md
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,7 @@ | ||
--- | ||
changeKind: feature | ||
packages: | ||
- "@typespec/openapi3" | ||
--- | ||
|
||
Updates tsp-openapi3 to escape identifiers that would otherwise be invalid, and automatically resolve namespaces for schemas with dots in their names. |
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
18 changes: 18 additions & 0 deletions
18
packages/openapi3/src/cli/actions/convert/generators/generate-namespace.ts
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,18 @@ | ||
import { TypeSpecNamespace } from "../interfaces.js"; | ||
import { generateModel } from "./generate-model.js"; | ||
import { generateOperation } from "./generate-operation.js"; | ||
|
||
export function generateNamespace(name: string, namespace: TypeSpecNamespace): string { | ||
const definitions: string[] = []; | ||
definitions.push(`namespace ${name} {`); | ||
|
||
definitions.push(...namespace.models.map(generateModel)); | ||
definitions.push(...namespace.operations.map(generateOperation)); | ||
|
||
for (const [namespaceName, nestedNamespace] of Object.entries(namespace.namespaces)) { | ||
definitions.push(generateNamespace(namespaceName, nestedNamespace)); | ||
} | ||
|
||
definitions.push("}"); | ||
return definitions.join("\n"); | ||
} |
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
Oops, something went wrong.