Skip to content

Commit

Permalink
Add schema scope to generator template's naming callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
karlvr committed Aug 16, 2024
1 parent 7ff4cb7 commit 207ebd5
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/olive-swans-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@openapi-generator-plus/types": minor
"@openapi-generator-plus/core": minor
---

Add schema scope to generator template's naming callbacks
1 change: 1 addition & 0 deletions packages/core/src/process/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function toCodegenSchema(apiSchema: OpenAPIX.SchemaObject, $ref: string | undefi
suggestedName = state.generator.toSuggestedSchemaName(suggestedName, {
purpose,
schemaType,
scope: suggestedScope,
})

const naming = supportedNamedSchema(schemaType, !!$ref, purpose, state) ? toUniqueScopedName($ref, suggestedName, suggestedScope, apiSchema, schemaType, purpose, state) : null
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/process/schema/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function createIfNotExistsCodegenInterfaceSchema(schema: CodegenObjectSch
const suggestedName = state.generator.toSuggestedSchemaName(baseSuggestedNameForRelatedSchemas(schema), {
purpose,
schemaType: CodegenSchemaType.INTERFACE,
scope,
})
const naming = toUniqueScopedName(undefined, suggestedName, scope, undefined, CodegenSchemaType.INTERFACE, purpose, state)
usedSchemaName(naming.scopedName, state)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/process/schema/naming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function toScopedName($ref: string | undefined, suggestedName: string, scope: Co

const nameOptions: CodegenSchemaNameOptions = {
schemaType,
scope,
}
let name = state.generator.toSchemaName(suggestedName, nameOptions)

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/process/schema/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export function createObjectSchema(suggestedName: string, scope: CodegenScope |
suggestedName = state.generator.toSuggestedSchemaName(suggestedName, {
purpose,
schemaType: CodegenSchemaType.OBJECT,
scope,
})

const naming = toUniqueScopedName(undefined, suggestedName, scope, undefined, CodegenSchemaType.OBJECT, purpose, state)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/process/schema/one-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export function createOneOfSchema(suggestedName: string, scope: CodegenScope | n
suggestedName = state.generator.toSuggestedSchemaName(suggestedName, {
purpose,
schemaType: CodegenSchemaType.OBJECT,
scope,
})

const naming = toUniqueScopedName(undefined, suggestedName, scope, undefined, CodegenSchemaType.OBJECT, purpose, state)
Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,11 +866,15 @@ export interface CodegenDiscriminatorMappings {

export interface CodegenSchemaNameOptions {
schemaType: CodegenSchemaType
/** The scope that the schema to name is scoped inside */
scope: CodegenScope | null
}

export interface CodegenSchemaNameSuggestionOptions {
purpose: CodegenSchemaPurpose
schemaType: CodegenSchemaType
/** The scope that the schema to suggest a name for will probably be scoped inside */
scope: CodegenScope | null
}

export interface CodegenTypeOptions {
Expand Down

0 comments on commit 207ebd5

Please sign in to comment.