aws-amplify / aws-amplify/amplify-codegen
Swift non model type properties are internal by default
- Dominant language
- TypeScript
- Stars
- 59
- Forks
- 64
- PR merge metrics
- No merged PRs in 30d
Description
### Before opening, please confirm:
- [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-codegen/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-codegen/blob/master/CONTRIBUTING.md#bugs).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
### How did you install the Amplify CLI?
npm
### If applicable, what version of Node.js are you using?
v14.19.0
### Amplify CLI Version
8.0.1
### What operating system are you using?
Mac
### Amplify Codegen Command
codegen models
### Describe the bug
When generating app sync `.swift` files for `non model` types, properties on the generated struct are `internal` by default. I don't think this should be the case as Amplify docs state creating a `non model` type for `S3Object`'s is the way to properly upload / fetch from S3 using DataStore or the GQL API. Data is accessible by adding a `public` attribute to the property but it's a pain to constantly add back `public` after codegen. Instead if it's an `S3Object` or `non model` object let's make these properties `public` by default the `struct` already is `public` why shouldn't the properties?
### Expected behavior
`non model` types should have properties that are set to `public` so developers can access the data the struct holds. If all `non model` types shouldn't have publicly accessible properties maybe only add `public` to the properties for `S3Object` type's only.
### Reproduction steps
1. Add a `S3Object` type to graphql schema mentioned here: https://docs.amplify.aws/sdk/storage/graphql-api/q/platform/ios/#client-code
2. run `amplify codegen models`
3. Notice the `S3Object` struct properties do not have a `public` access control modifier
### GraphQL schema(s)
```graphql
# Put schemas below this line
type Picture @model {
id: ID!
name: String
owner: String
visibility: Visibility
file: S3Object
createdAt: String
}
type S3Object {
bucket: String!
region: String!
key: String!
localUri: String!
mimeType: String!
}
enum Visibility {
public
private
}
```
### Log output
```
# Put your logs below this line
```
### Additional information
Function that generates ```non model``` types:
```
generateNonModelType() {
let result = [...this.imports, ''];
Object.entries(this.getSelectedNonModels()).forEach(([name, obj]) => {
const structBlock = new swift_declaration_block_1.SwiftDeclarationBlock()
.withName(this.getModelName(obj))
.access('public')
.withProtocols(['Embeddable']);
Object.values(obj.fields).forEach(field => {
const fieldType = this.getNativeType(field);
structBlock.addProperty(this.getFieldName(field), fieldType, undefined, 'DEFAULT', {
optional: !this.isFieldRequired(field),
isList: field.isList,
variable: true,
isEnum: this.isEnumType(field),
listType: field.isList ? swift_declaration_block_1.ListType.ARRAY : undefined,
});
});
result.push(structBlock.string);
});
return result.join('\n');
}
```
`structBlock.addProperty(this.getFieldName(field), fieldType, undefined, 'DEFAULT', {`
Should be:
`structBlock.addProperty(this.getFieldName(field), fieldType, undefined, 'public', {`
Thank you!
Contributor guide
Assessment
This issue has not been assessed yet.