-
Notifications
You must be signed in to change notification settings - Fork 435
[CodeGenLib] Add validation step for input #1753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CodeGenLib] Add validation step for input #1753
Conversation
…nslator Motivation: The IDLToStructuredSwiftTranslator should discover errors in the CodeGenerationRequest object, before the specialized translators start their work. This way, if the input is not correct no translator will be started. Modifications: Moved the validation functions into a IDLToStructuredSwiftTranslator extension and the associated tests in a separate test file. Result: The input validation is not done by each individual specialzed translator, but by the main translator, before transformations take place.
gjcairo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just left a very small comment
| let noNamespaceServices = servicesByNamespace["", default: []] | ||
| let namespaces = servicesByNamespace.keys | ||
| for service in noNamespaceServices { | ||
| if namespaces.contains(service.name) { | ||
| throw CodeGenError( | ||
| code: .nonUniqueServiceName, | ||
| message: """ | ||
| Services with no namespace must not have the same names as the namespaces. \ | ||
| \(service.name) is used as a name for a service with no namespace and a namespace. | ||
| """ | ||
| ) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor nit, but you can skip the , default: []] subscript and instead make this whole block conditional to it being an empty key:
| let noNamespaceServices = servicesByNamespace["", default: []] | |
| let namespaces = servicesByNamespace.keys | |
| for service in noNamespaceServices { | |
| if namespaces.contains(service.name) { | |
| throw CodeGenError( | |
| code: .nonUniqueServiceName, | |
| message: """ | |
| Services with no namespace must not have the same names as the namespaces. \ | |
| \(service.name) is used as a name for a service with no namespace and a namespace. | |
| """ | |
| ) | |
| } | |
| } | |
| if let noNamespaceServices = servicesByNamespace[""] { | |
| let namespaces = servicesByNamespace.keys | |
| for service in noNamespaceServices { | |
| if namespaces.contains(service.name) { | |
| throw CodeGenError( | |
| code: .nonUniqueServiceName, | |
| message: """ | |
| Services with no namespace must not have the same names as the namespaces. \ | |
| \(service.name) is used as a name for a service with no namespace and a namespace. | |
| """ | |
| ) | |
| } | |
| } | |
| } |
| grouping: codeGenerationRequest.services, | ||
| by: { $0.namespace } | ||
| ) | ||
| try checkServiceNamesAreUnique(for: servicesByNamespace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| try checkServiceNamesAreUnique(for: servicesByNamespace) | |
| try self.checkServiceNamesAreUnique(for: servicesByNamespace) |
| ) | ||
| try checkServiceNamesAreUnique(for: servicesByNamespace) | ||
| for service in codeGenerationRequest.services { | ||
| try checkMethodNamesAreUnique(in: service) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| try checkMethodNamesAreUnique(in: service) | |
| try self.checkMethodNamesAreUnique(in: service) |
Add validation step for input in IDLToStructuredSwiftTranslator Motivation: The IDLToStructuredSwiftTranslator should discover errors in the CodeGenerationRequest object, before the specialized translators start their work. This way, if the input is not correct no translator will be started. Modifications: Moved the validation functions into a IDLToStructuredSwiftTranslator extension and the associated tests in a separate test file. Result: The input validation is not done by each individual specialzed translator, but by the main translator, before transformations take place.
Add validation step for input in IDLToStructuredSwiftTranslator
Motivation:
The IDLToStructuredSwiftTranslator should discover errors in the CodeGenerationRequest object, before the specialized translators start their work. This way, if the input is not correct no translator will be started.
Modifications:
Moved the validation functions into a IDLToStructuredSwiftTranslator extension and the associated tests in a separate test file.
Result:
The input validation is not done by each individual specialzed translator, but by the main translator, before transformations take place.