-
Notifications
You must be signed in to change notification settings - Fork 857
Add UUID parameter type #483
Comments
@vanDonselaar why not use a string with a regex and define your own type? |
How can I 'define my own type' exactly? Sounds interesting! When using the |
Thats simple using the data type language introduced in RAML 1.0. For example: types:
UUID:
type: string
pattern: ^[0-9]* |
Yes, you can change integer for whatever you want, but that's not this case. You are trying to validate a string. you can define your type as follows types:
UUID:
type: string
pattern: ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$ and please don't cast, try using something as tryParse, your code will look much nicer. |
With 'cast' I actually meant doing public PostUuidExampleResponse postUuidExampleBySomeUuid(
@PathParam("some_uuid")
@Pattern(regexp = "^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-(8|9|a|b)[a-f0-9]{3}-[a-f0-9]{12}$")
@Valid
String someUuid) throws Exception {
UUID realUuid = UUID.fromString(someUuid);
... The introduction of a UUID type would allow the generator to produce code like this: public PostUuidExampleResponse postUuidExampleBySomeUuid(
@PathParam("some_uuid")
java.util.UUID someUuid) throws Exception {
someUuid; // Correct type |
with the new typesystem code generators will need to know about types and you could also enrich that with raml annotations. I don't think UUID will be a great built in type to add to the typesystem. |
Okay, sounds reasonable but that would imply that there is some kind of type registry where these types are all documented, right? So if I rephrase my question: how would a code generator know when to generate UUID's then? What are these annotations you're referring to? I don't see them in the 1.0 spec. Slightly unrelated: I'm really curious why RAML, as an API definition language, also tries to be a definition language for models. There are already tons of formats and projects fully dedicated to model definition. We have JSON Schema, Apache Avro, XML Schema, Apache Thrift, Google Protobuf, etc. all having high quality model generators to nearly all programming languages. I'm wondering why RAML wants to re-invent this wheel rather than becoming the de facto API definition language and leave the models pluggable. |
Here you can check about annotation types. As per API Definition RAML is only giving you more tools to define your types you are free to use it or not but you are not tied to it, you can also use xsd and json schema. |
Thanks for the link. |
No problem, we like users to be as free as they want while designing their APIs. |
We're using UUID's rather than Integers in our API to identify entities. It would be nice to have a
uuid
parameter type rather than usingstring
for UUID's.The text was updated successfully, but these errors were encountered: