Skip to content

Conversation

@stefanadranca
Copy link
Collaborator

Typealias translator configuration for client and server type aliases

Motivation:

The typealias translator should generate typealiases for the client and server protocols only if the associated code (client/server code) will be generated. Also, at the moment the typealias translator doesn't generate the ClientProtocol typealias.

Modifications:

  • added a new initialiser for the TypealiasTranslator that sets the client and server property.
  • Based on the client and server properties' values, the typealias translator generates or not the protocol typealiases.
  • created method for client protocol typalias generation.
  • modified tests, so they include the client code.
  • added new tests for generating only client or server code.

Result:

The typealias translator will generate typealiases for client and server protocols only when the associated code is also generated, getting rid of the possibility of an error (when the protocol doesn't exist).

… typealiases

Motivation:

The typealias translator should generate typealias for the client and server protocols only if the associated code (client/server code) will be generated as well. Also, at the moment the Typealias translator doesn't generate the ClientProtocol typealias.

Modifications:

- added a new initialiser for the TypealiasTranslator that sets the client and server property.
- Based on the client and server properties' values the typealias translator generates or not the protocol typealiases.
- created method gor client protocol typalias generation.
- modified tests, so they include the client code.
- added new tests for generating only client or server code.

Result:

The typealias translator will generate typealiases for client and server protocols only when the associated code is also generated, getting rid of the possibility of an error (when the protocol doesn't exist).
Comment on lines 330 to 334
let namespacedPrefix: String
if service.namespace.isEmpty {
namespacedPrefix = service.name
} else {
namespacedPrefix = "\(service.namespace)_\(service.name)"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After merging the server code translator PR, I will use the service property from the extension to get the namespacedPrefix

static let methods: [MethodDescriptor] = []
typealias StreamingServiceProtocol = namespaceA_ServiceAServiceStreamingProtocol
typealias ServiceProtocol = namespaceA_ServiceAServiceProtocol
typealias ClientProtocol = namespaceA_ServiceAClientProtocol
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add a typealias for the Client as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the struct?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@glbrntt glbrntt merged commit 6145631 into grpc:main Dec 21, 2023
glbrntt pushed a commit to glbrntt/grpc-swift that referenced this pull request Feb 5, 2024
…grpc#1750)

Motivation:

The typealias translator should generate typealias for the client and server protocols only if the associated code (client/server code) will be generated as well. Also, at the moment the Typealias translator doesn't generate the ClientProtocol typealias.

Modifications:

- added a new initialiser for the TypealiasTranslator that sets the client and server property.
- Based on the client and server properties' values the typealias translator generates or not the protocol typealiases.
- created method gor client protocol typalias generation.
- modified tests, so they include the client code.
- added new tests for generating only client or server code.

Result:

The typealias translator will generate typealiases for client and server protocols only when the associated code is also generated, getting rid of the possibility of an error (when the protocol doesn't exist).
@glbrntt glbrntt added the version/v2 Relates to v2 label Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

version/v2 Relates to v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants