Skip to content

Commit

Permalink
core: Interface and implementation properties should be separate from…
Browse files Browse the repository at this point in the history
… their source, so we can remove properties from specific schemas
  • Loading branch information
karlvr committed Apr 19, 2024
1 parent dede8c1 commit 916cd75
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/kind-geckos-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@openapi-generator-plus/core": minor
---

Interface and implementation properties should be separate from their source, so we can remove properties from specific schemas
5 changes: 3 additions & 2 deletions packages/core/src/process/schema/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CodegenHierarchySchema, CodegenInterfaceSchema, CodegenObjectSchema, CodegenSchemaPurpose, CodegenSchemaType, CodegenScope, isCodegenObjectSchema } from '@openapi-generator-plus/types'
import * as idx from '@openapi-generator-plus/indexed-type'
import { InternalCodegenState } from '../../types'
import { extractCodegenSchemaInfo } from '../utils'
import { extractNaming, fullyQualifiedName, toUniqueScopedName, usedSchemaName } from './naming'
Expand Down Expand Up @@ -63,7 +64,7 @@ export function toCodegenInterfaceSchema(schema: CodegenObjectSchema | CodegenHi
deprecated: schema.deprecated,

additionalProperties: schema.additionalProperties,
properties: schema.properties,
properties: schema.properties ? idx.create(schema.properties) : null,
examples: null,
children: null,
implementation: isCodegenObjectSchema(schema) ? schema : null,
Expand Down Expand Up @@ -117,7 +118,7 @@ export function toCodegenInterfaceImplementationSchema(interfaceSchema: CodegenI
const result = createObjectSchema(suggestedName, scope, allowAbstract ? CodegenSchemaPurpose.ABSTRACT_IMPLEMENTATION : CodegenSchemaPurpose.IMPLEMENTATION, state)

result.abstract = allowAbstract
result.properties = interfaceSchema.properties
result.properties = interfaceSchema.properties ? idx.create(interfaceSchema.properties) : null
result.additionalProperties = interfaceSchema.additionalProperties

addImplementor(interfaceSchema, result)
Expand Down
7 changes: 0 additions & 7 deletions packages/core/src/process/schema/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,6 @@ export function removeProperty(schema: CodegenObjectLikeSchemas, serializedName:

idx.remove(schema.properties, serializedName)
if (idx.isEmpty(schema.properties)) {
/* Check for schemas that share these properties */
if (isCodegenObjectSchema(schema) && schema.interface && schema.interface.properties === schema.properties) {
schema.interface.properties = null
}
if (isCodegenInterfaceSchema(schema) && schema.implementation && schema.implementation.properties === schema.properties) {
schema.implementation.properties = null
}
schema.properties = null
}

Expand Down

0 comments on commit 916cd75

Please sign in to comment.