-
Hiya, I'm still new to Smithy and smithy4s. I'm trying to learn it by writing small services, one of these is a contacts list, just like a todo list...but with contacts heh. My current model has a Am I modeling wrong, or is there a better/more standard way to do these type of things? I have the following smithy file: $version: "2"
namespace smithy4s.contacts
use smithy4s.api#simpleRestJson
use smithy4s.api#UUID
@simpleRestJson
service ContactsService {
version: "0.0.1"
operations: [AddContact, DeleteContact, ShowContact, ShowContacts]
}
@http(method: "POST", uri: "/contacts/{contactId}", code: 200)
operation AddContact {
input: AddContactInput
errors: [InvalidInput]
}
@idempotent
@http(method: "DELETE", uri: "/contacts/{contactId}", code: 200)
operation DeleteContact {
errors: [InvalidInput]
}
@input
structure AddContactInput for Contact {
@required
$contactId
}
@readonly
@http(method: "GET", uri: "/contacts/{contactId}", code: 200)
operation ShowContact {
output: ShowContactOutput
errors: [InvalidInput]
}
@readonly
@http(method: "GET", uri: "/contacts", code: 200)
operation ShowContacts {
output: ShowContactsOutput
}
@output
structure ShowContactsOutput {
@required
contacts: Contacts
}
@output
structure ShowContactOutput for Contact {
@required
$contactId
name: String
}
resource Contact {
identifiers: { contactId: ContactId }
}
list Contacts {
member: ContactId
}
@error("server")
structure InvalidInput {
@required
message: String
}
@uuidFormat
string ContactId
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
@zetashift, thanks for the interest :) For starters, let me say that in the current version, Smithy4s doesn't have any bespoke support for Now, that being said, let's try to minimise your example to make the problem clearer and identify a solution. This below seems to work. As you can see, I've added the
If you're worried about the repetition between various operations, you could use mixins to clear the boilerplate :
PS please don't start your namespaces with |
Beta Was this translation helpful? Give feedback.
-
So I don't know if Currently I have this, after trying to clean up the code a bit(lil bit minified): @simpleRestJson
service ContactsService {
version: "0.0.1"
operations: [AddContact, DeleteContact, ShowContact, ShowContacts]
}
@idempotent
@http(method: "DELETE", uri: "/contacts/{contactId}", code: 200)
operation DeleteContact {
input: Contact,
errors: [InvalidInput]
}
@http(method: "POST", uri: "/contacts/{contactId}", code: 200)
operation AddContact {
input: AddContactInput
errors: [InvalidInput]
}
@input
structure AddContactInput with [ContactContext] {
@required
$contactId
}
@mixin
structure ContactContext {
@httpLabel
@required
contactId: ContactId
}
structure Contact {
@httpLabel
@required
contactId: ContactId
}
@uuidFormat
string ContactId
Is this adequate? The |
Beta Was this translation helpful? Give feedback.
@zetashift, thanks for the interest :)
For starters, let me say that in the current version, Smithy4s doesn't have any bespoke support for
Resource
whatsoever, so I obviously cannot give you a very informed piece of advice on resources. I've not ever used resources myself, and though we are planning on support it eventually, we haven't even started thinking about the "how" of a possible support.Now, that being said, let's try to minimise your example to make the problem clearer and identify a solution. This below seems to work. As you can see, I've added the
@httpLabel
annotation in the definition of AddContactInput