Skip to content

Commit

Permalink
Update naming logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Nov 16, 2023
1 parent ff40416 commit 3ac7a5c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
44 changes: 43 additions & 1 deletion packages/openapi3/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,48 @@ function createOAPIEmitter(
for (const declaration of declarations) {
schemas[declaration.name] = declaration.value as any;
}
}

// TODO: The old logic
// Emit the processed schemas. Only now can we compute the names as it
// depends on whether we have produced multiple schemas for a single
// TYPESPEC type.
// for (const group of processedSchemas.values()) {
// for (const [visibility, processed] of group) {
// let name = getOpenAPITypeName(program, processed.type, typeNameOptions);
// if (group.size > 1) {
// const suffix = getVisibilitySuffix(visibility, Visibility.All);
// // ignore plain "Read" suffix since it is the canonical visibility
// // for referenced schemas
// if (suffix !== "Read") {
// name += suffix;
// }
// }
// checkDuplicateTypeName(program, processed.type, name, root.components!.schemas);
// processed.ref.value = "#/components/schemas/" + encodeURIComponent(name);
// if (processed.schema) {
// root.components!.schemas![name] = processed.schema;
// }
// }
// }
}

// TODO: Old logic
// function processSchemas() {
// // Process pending schemas. Note that getSchemaForType may pull in new
// // pending schemas so we iterate until there are no pending schemas
// // remaining.
// while (pendingSchemas.size > 0) {
// for (const [type, group] of pendingSchemas) {
// for (const [visibility, pending] of group) {
// processedSchemas.getOrAdd(type, visibility, () => ({
// ...pending,
// schema: getSchemaForType(type, visibility),
// }));
// }
// pendingSchemas.delete(type);
// }
// }
// }

function processUnreferencedSchemas() {
const addSchema = (type: Type) => {
Expand All @@ -1321,6 +1362,7 @@ function createOAPIEmitter(
!shouldInline(program, type)
) {
getSchemaOrRef(type, Visibility.Read);
}
// TODO: This was the old fix...
// if (!processedSchemas.has(type) && !paramModels.has(type) && !shouldInline(program, type)) {
// getSchemaOrRef(type, Visibility.All);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ components:
relatives:
type: array
items:
$ref: '#/components/schemas/PersonRelativeReadOrCreateOrUpdateOrDeleteOrQueryItem'
$ref: '#/components/schemas/PersonRelativeItem'
Person:
type: object
required:
Expand Down Expand Up @@ -176,7 +176,7 @@ components:
type: array
items:
$ref: '#/components/schemas/PersonRelativeCreateOrUpdateItem'
PersonReadOrCreateOrUpdateOrDeleteOrQueryItem:
PersonItem:
type: object
required:
- id
Expand All @@ -200,7 +200,7 @@ components:
relatives:
type: array
items:
$ref: '#/components/schemas/PersonRelativeReadOrCreateOrUpdateOrDeleteOrQueryItem'
$ref: '#/components/schemas/PersonRelativeItem'
PersonRelative:
type: object
required:
Expand Down Expand Up @@ -231,14 +231,14 @@ components:
$ref: '#/components/schemas/PersonCreateOrUpdateItem'
relationship:
type: string
PersonRelativeReadOrCreateOrUpdateOrDeleteOrQueryItem:
PersonRelativeItem:
type: object
required:
- person
- relationship
properties:
person:
$ref: '#/components/schemas/PersonReadOrCreateOrUpdateOrDeleteOrQueryItem'
$ref: '#/components/schemas/PersonItem'
relationship:
type: string
PersonRelativeUpdateItem:
Expand Down

0 comments on commit 3ac7a5c

Please sign in to comment.