Skip to content

Commit

Permalink
Remove implements
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd committed Jul 10, 2024
1 parent d4ff7ff commit 704d448
Show file tree
Hide file tree
Showing 6 changed files with 523 additions and 1,577 deletions.
7 changes: 1 addition & 6 deletions compiler/src/model/build-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
modelBehaviors,
modelEnumDeclaration,
modelGenerics,
modelImplements,
modelInherits,
modelProperty,
modelType,
Expand Down Expand Up @@ -77,8 +76,6 @@ export function compileEndpoints (): Record<string, model.Endpoint> {
visibility: spec.visibility
}
},
stability: spec.stability,
visibility: spec.visibility,
request: null,
requestBodyRequired: Boolean(spec.body?.required),
response: null,
Expand All @@ -91,7 +88,7 @@ export function compileEndpoints (): Record<string, model.Endpoint> {
})
}
if (typeof spec.feature_flag === 'string') {
map[api].featureFlag = spec.feature_flag
map[api].availability.stack.featureFlag = spec.feature_flag
}
}
return map
Expand Down Expand Up @@ -534,8 +531,6 @@ function compileClassOrInterfaceDeclaration (declaration: ClassDeclaration | Int
for (const implement of declaration.getImplements()) {
if (isKnownBehavior(implement)) {
type.behaviors = (type.behaviors ?? []).concat(modelBehaviors(implement, jsDocs))
} else {
type.implements = (type.implements ?? []).concat(modelImplements(implement))
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/model/metamodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ export class Interface extends BaseType {
*/
generics?: TypeName[]
inherits?: Inherits
implements?: Inherits[] // Unused!

/**
* Behaviors directly implemented by this interface
Expand Down Expand Up @@ -266,7 +265,6 @@ export class Request extends BaseType {
generics?: TypeName[]
/** The parent defines additional body properties that are added to the body, that has to be a PropertyBody */
inherits?: Inherits
implements?: Inherits[]
/** URL path properties */
path: Property[]
/** Query string properties */
Expand Down
24 changes: 5 additions & 19 deletions compiler/src/steps/validate-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
const parentTypes = new Set<string>()
for (const type of apiModel.types) {
if (type.kind === 'request' || type.kind === 'interface') {
for (const parent of (type.implements ?? []).concat(type.inherits ?? [])) {
parentTypes.add(fqn(parent.type))
if (type.inherits != null) {
parentTypes.add(fqn(type.inherits.type))
}
}
}
Expand Down Expand Up @@ -380,7 +380,6 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
const openGenerics = openGenericSet(typeDef)

validateInherits(typeDef.inherits, openGenerics)
validateImplements(typeDef.implements, openGenerics)
validateBehaviors(typeDef, openGenerics)

// Note: we validate codegen_name/name uniqueness independently in the path, query and body as there are some
Expand Down Expand Up @@ -495,7 +494,6 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
if (typeDef.inherits != null) {
addInherits(typeDef.inherits)
}
typeDef.implements?.forEach(addInherits)
typeDef.behaviors?.forEach(addInherits)
}

Expand All @@ -505,7 +503,6 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
function validateInterface (typeDef: model.Interface): void {
const openGenerics = openGenericSet(typeDef)

validateImplements(typeDef.implements, openGenerics)
validateInherits(typeDef.inherits, openGenerics)
validateBehaviors(typeDef, openGenerics)
validateProperties(typeDef.properties, openGenerics, inheritedProperties(typeDef))
Expand Down Expand Up @@ -694,16 +691,6 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
context.pop()
}

function validateImplements (parents: (model.Inherits[] | undefined), openGenerics: Set<string>): void {
if (parents == null || parents.length === 0) return

context.push('Implements')
for (const parent of parents) {
validateTypeRef(parent.type, parent.generics, openGenerics)
}
context.pop()
}

function validateBehaviors (typeDef: model.Request | model.Response | model.Interface, openGenerics: Set<string>): void {
if (typeDef.kind !== 'response' && typeDef.behaviors != null && typeDef.behaviors.length > 0) {
context.push('Behaviors')
Expand Down Expand Up @@ -746,11 +733,10 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
}

// Does a parent have this behavior?
const parents = (type.implements ?? []).concat(type.inherits ?? [])
for (const parent of parents) {
const parentDef = getTypeDef(parent.type)
if (type.inherits != null) {
const parentDef = getTypeDef(type.inherits.type)
if (parentDef == null) {
modelError(`No type definition for parent '${fqn(parent.type)}'`)
modelError(`No type definition for parent '${fqn(type.inherits.type)}'`)
return false
}
if (parentDef.kind === 'request' || parentDef.kind === 'interface') {
Expand Down
Loading

0 comments on commit 704d448

Please sign in to comment.