Skip to content

Commit

Permalink
fix: resolve issue with service inheritance within namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-greene-ck committed Apr 11, 2019
1 parent aee5187 commit 798a708
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 31 deletions.
10 changes: 9 additions & 1 deletion src/main/render/apache/service/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
typeNodeForFieldType,
} from '../types'

import { resolveIdentifierName } from '../../../resolver/utils'
import { IRenderState } from '../../../types'

export function renderClient(
Expand Down Expand Up @@ -153,7 +154,14 @@ export function renderClient(
ts.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
ts.createExpressionWithTypeArguments(
[],
ts.createIdentifier(`${node.extends.value}.Client`),
ts.createIdentifier(
`${
resolveIdentifierName(
node.extends.value,
state,
).fullName
}.Client`,
),
),
]),
]
Expand Down
14 changes: 12 additions & 2 deletions src/main/render/apache/service/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ export function renderHandlerInterface(
),
ts.createTypeReferenceNode(
ts.createIdentifier(
`${service.extends.value}.IHandler`,
`${
resolveIdentifierName(
service.extends.value,
state,
).fullName
}.IHandler`,
),
undefined,
),
Expand Down Expand Up @@ -243,7 +248,12 @@ export function renderProcessor(
ts.createExpressionWithTypeArguments(
[],
ts.createIdentifier(
`${node.extends.value}.Processor`,
`${
resolveIdentifierName(
node.extends.value,
state,
).fullName
}.Processor`,
),
),
]),
Expand Down
8 changes: 7 additions & 1 deletion src/main/render/shared/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { COMMON_IDENTIFIERS } from '../identifiers'

import { createAnyType, TypeMapping } from '../types'

import { resolveIdentifierName } from '../../../resolver/utils'
import { IRenderState } from '../../../types'
import { createFunctionParameter } from '../utils'

Expand Down Expand Up @@ -108,7 +109,12 @@ export function renderHandlerInterface(
),
ts.createTypeReferenceNode(
ts.createIdentifier(
`${service.extends.value}.IHandler`,
`${
resolveIdentifierName(
service.extends.value,
state,
).fullName
}.IHandler`,
),
[ts.createTypeReferenceNode('Context', undefined)],
),
Expand Down
14 changes: 11 additions & 3 deletions src/main/render/thrift-server/service/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
renderServiceAnnotationsStaticProperty,
} from '../annotations'

import { resolveIdentifierName } from '../../../resolver/utils'
import { createClassConstructor } from '../../shared/utils'
import { looseName, strictName, toolkitName } from '../struct/utils'

Expand All @@ -59,11 +60,18 @@ function extendsAbstract(): ts.HeritageClause {
])
}

function extendsService(service: Identifier): ts.HeritageClause {
function extendsService(
service: Identifier,
state: IRenderState,
): ts.HeritageClause {
return ts.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
ts.createExpressionWithTypeArguments(
[ts.createTypeReferenceNode(COMMON_IDENTIFIERS.Context, undefined)],
ts.createIdentifier(`${service.value}.Client`),
ts.createIdentifier(
`${
resolveIdentifierName(service.value, state).fullName
}.Client`,
),
),
])
}
Expand All @@ -90,7 +98,7 @@ export function renderClient(

const heritage: Array<ts.HeritageClause> =
service.extends !== null
? [extendsService(service.extends)]
? [extendsService(service.extends, state)]
: [extendsAbstract()]

// export class <node.name> { ... }
Expand Down
18 changes: 14 additions & 4 deletions src/main/render/thrift-server/service/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ import {
renderServiceAnnotationsStaticProperty,
} from '../annotations'

import { resolveIdentifierDefinition } from '../../../resolver/utils'
import {
resolveIdentifierDefinition,
resolveIdentifierName,
} from '../../../resolver/utils'
import { className, looseName, strictName, toolkitName } from '../struct/utils'

function objectLiteralForServiceFunctions(
Expand Down Expand Up @@ -95,11 +98,18 @@ function createHandlerType(node: ServiceDefinition): ts.TypeNode {
])
}

export function extendsService(service: Identifier): ts.HeritageClause {
export function extendsService(
service: Identifier,
state: IRenderState,
): ts.HeritageClause {
return ts.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
ts.createExpressionWithTypeArguments(
[ts.createTypeReferenceNode(COMMON_IDENTIFIERS.Context, undefined)],
ts.createIdentifier(`${service.value}.Processor`),
ts.createIdentifier(
`${
resolveIdentifierName(service.value, state).fullName
}.Processor`,
),
),
])
}
Expand Down Expand Up @@ -164,7 +174,7 @@ export function renderProcessor(

const heritage: Array<ts.HeritageClause> =
service.extends !== null
? [extendsService(service.extends)]
? [extendsService(service.extends, state)]
: [extendsAbstract()]

// export class <node.name> { ... }
Expand Down
2 changes: 1 addition & 1 deletion src/tests/integration/apache/add-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
TBufferedTransport,
} from 'thrift'

import { AddService } from './codegen/add-service'
import { AddService } from './codegen/com/test/add-service'

import { Server } from 'net'

Expand Down
6 changes: 3 additions & 3 deletions src/tests/integration/apache/calculator-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import {
ExceptionTwo,
Operation,
Work,
} from './codegen/calculator'
} from './codegen/com/test/calculator'

import { AddService } from './codegen/add-service'
import { AddService } from './codegen/com/test/add-service'

import { SharedStruct, SharedUnion } from './codegen/shared'
import { SharedStruct, SharedUnion } from './codegen/com/test/shared'

import { Server } from 'net'

Expand Down
4 changes: 2 additions & 2 deletions src/tests/integration/apache/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
LastName,
Operation,
Work,
} from './codegen/calculator'
} from './codegen/com/test/calculator'

import { SharedStruct, SharedUnion } from './codegen/shared'
import { SharedStruct, SharedUnion } from './codegen/com/test/shared'

import { createAddServer } from './add-service'
import { createCalculatorServer } from './calculator-service'
Expand Down
4 changes: 2 additions & 2 deletions src/tests/integration/thrift/add-service.thrift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace java add-service
namespace js add-service
namespace java com.test.add-service
namespace js com.test.add-service

service AddService {

Expand Down
4 changes: 2 additions & 2 deletions src/tests/integration/thrift/calculator.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ include "shared.thrift"
include "common/common.thrift"
include "operation.thrift"

namespace java calculator
namespace js calculator
namespace java com.test.calculator
namespace js com.test.calculator

typedef i32 MyInteger
typedef operation.Operation Operation
Expand Down
4 changes: 2 additions & 2 deletions src/tests/integration/thrift/common/common.thrift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace java common
namespace js common
namespace java com.core.common
namespace js com.core.common

include "shared.thrift"

Expand Down
4 changes: 2 additions & 2 deletions src/tests/integration/thrift/exceptions.thrift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace java exceptions
namespace js exceptions
namespace java com.test.exceptions
namespace js com.test.exceptions

include "shared.thrift"

Expand Down
4 changes: 2 additions & 2 deletions src/tests/integration/thrift/operation.thrift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace java operation
namespace js operation
namespace java com.test.operation
namespace js com.test.operation

include "exceptions.thrift"

Expand Down
4 changes: 2 additions & 2 deletions src/tests/integration/thrift/shared.thrift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace java shared
namespace js shared
namespace java com.test.shared
namespace js com.test.shared

const i32 SHARED_INT = 45

Expand Down
4 changes: 2 additions & 2 deletions src/tests/integration/thrift/user.thrift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace java user
namespace js user
namespace java com.test.user
namespace js com.test.user

struct User {
1: string name
Expand Down

0 comments on commit 798a708

Please sign in to comment.